OSDN Git Service

drop
authorab25cq <ab25cq@gmail.com>
Fri, 14 Dec 2012 12:07:11 +0000 (21:07 +0900)
committerab25cq <ab25cq@gmail.com>
Fri, 14 Dec 2012 12:07:11 +0000 (21:07 +0900)
Makefile
README
drop.c [new file with mode: 0644]

index e7a2a1a..e40013a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-all: enum_windows click wheel cursor_pos window_from_point mousehook mousehook_lib.dll
+all: enum_windows click wheel cursor_pos window_from_point mousehook mousehook_lib.dll drop
 
 install: all
        mkdir -p /usr/local/bin
@@ -11,7 +11,7 @@ install: all
        install -m 755 mousehook_lib.dll /usr/local/bin
 
 clean:
-       rm -rf enum_windows click wheel cursor_pos window_from_point mousehook mousehook_lib.dll mousehook_lib.o
+       rm -rf enum_windows click wheel cursor_pos window_from_point mousehook mousehook_lib.dll mousehook_lib.o drop
 
 enum_windows: enum_windows.c
 
@@ -29,3 +29,6 @@ mousehook: mousehook.c mousehook_lib.dll
 mousehook_lib.dll: mousehook_lib.c
        gcc -c mousehook_lib.c
        gcc -shared -o mousehook_lib.dll mousehook_lib.o -Wl,--kill-at
+
+drop: drop.c
+       gcc -o drop drop.c -lgdi32
diff --git a/README b/README
index eafec00..2f60975 100644 (file)
--- a/README
+++ b/README
@@ -18,4 +18,5 @@
     wheel: \88ø\90\94\82É\90\94\8e\9a\82ð\8ew\92è\82µ\82Ä\81A\82»\82Ì\97Ê\82¾\82¯\83E\83B\81[\83\8b\82ð\93®\82©\82µ\82Ü\82·\81B> 0\82Å\8fã\95û\8cü\81A < 0\82Å\89º\95û\8cü\82É\83X\83N\83\8d\81[\83\8b\81B
     cursor_pos: \83J\81[\83\\83\8b\82Ì\88Ê\92u\82ð\95Ô\82µ\82Ü\82·\81B\88ø\90\94\82ð\8ew\92è\82·\82é\82Æ\83J\81[\83\\83\8b\82ð\88Ú\93®\82µ\82Ü\82·\81B < 0\82Å\8c»\8dÝ\88Ê\92u\82Ì\82Ü\82Ü\81B-1 10\82¾\82Æy\95û\8cü\82Ì\82Ý10\82É\88Ú\93®\82µ\82Ü\82·\81B
     window_from_point: \83J\81[\83\\83\8b\82Ì\89º\82É\82 \82é\83E\83B\83\93\83h\83E\82Ì\83N\83\89\83X\96¼\82ð\95\\8e¦\82µ\82Ü\82·\81B
-    mousehook: START\83{\83^\83\93\82ð\89\9f\82·\82Æ\83t\83b\83N\8aJ\8en\81BEND\82Å\83t\83b\83N\8fI\97¹\81B\8c»\8dÝ\92n\82Ì\83}\83E\83X\82Ì\8dÀ\95W\82ð\95\\8e¦\82µ\82Ü\82·\81B\83N\83\8a\83b\83N\81A\89E\83N\83\8a\83b\83N\82ð\8ds\82Á\82½\8fê\8f\8a\82à\95\\8e¦\82µ\82Ü\82·\81B
+    mousehook: START\83{\83^\83\93\82ð\89\9f\82·\82Æ\83t\83b\83N\8aJ\8en\81BEND\82Å\83t\83b\83N\8fI\97¹\81B\8c»\8dÝ\88Ê\92u\82Ì\83}\83E\83X\82Ì\8dÀ\95W\82ð\95\\8e¦\82µ\82Ü\82·\81B\83N\83\8a\83b\83N\81A\89E\83N\83\8a\83b\83N\82ð\8ds\82Á\82½\8fê\8f\8a\82à\95\\8e¦\82µ\82Ü\82·\81B
+    get_dnd: \83t\83@\83C\83\8b\82Ì\83h\83\89\83b\83O\83A\83\93\83h\83h\83\8d\83b\83v\82ð\8eó\82¯\95t\82¯\82Ü\82·\81B\83E\83B\83\93\83h\83E\82ð\95Â\82\82é\82Æ\8eó\82¯\8eæ\82Á\82½\83t\83@\83C\83\8b\82Ì\88ê\97\97\82ð\8fo\97Í\82µ\82Ü\82·\81B
diff --git a/drop.c b/drop.c
new file mode 100644 (file)
index 0000000..7fa16c4
--- /dev/null
+++ b/drop.c
@@ -0,0 +1,219 @@
+#include <windows.h>
+#include <windowsx.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char** lpFileNames;
+static int iFileNameNumber = 0;
+static int iFileNameMallocSize = 128;
+
+void init_file_name()
+{
+    lpFileNames = malloc(sizeof(char*)*iFileNameMallocSize);
+    iFileNameNumber = 0;
+}
+
+void final_file_name()
+{
+    int i;
+    for(i=0; i<iFileNameNumber; i++) {
+        free(lpFileNames[i]);
+    }
+    free(lpFileNames);
+}
+
+void add_file_name(char* fname)
+{
+    if(iFileNameNumber >= iFileNameMallocSize) {
+        iFileNameMallocSize *= 2;
+        lpFileNames = realloc(lpFileNames, sizeof(char*)*iFileNameMallocSize);
+    }
+
+    lpFileNames[iFileNameNumber++] = strdup(fname);
+}
+
+void erase_file_name(int index)
+{
+    free(lpFileNames[index]);
+    iFileNameNumber--;
+
+    int i;
+    for(i=index; i<iFileNameNumber; i++) {
+        lpFileNames[i] = lpFileNames[i+1];
+    }
+
+puts("FILES");
+for(i=0; i<iFileNameNumber; i++) {
+puts(lpFileNames[i]);
+}
+
+    //memcpy(lpFileNames + index, lpFileNames + index + 1, iFileNameNumber - index -1);
+
+}
+
+void clear_file_names()
+{
+    int i;
+    for(i=0; i<iFileNameNumber; i++) {
+        free(lpFileNames[i]);
+    }
+
+    iFileNameNumber = 0;
+}
+
+void output_file_names()
+{
+    int i;
+    for(i=0; i<iFileNameNumber; i++) {
+        printf("%s\n", lpFileNames[i]);
+    }
+}
+
+#define ID_LISTBOX 1
+#define ID_BUTTON_OK 2
+#define ID_BUTTON_DEL 3
+#define ID_BUTTON_RESET 4
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HDC hdc;
+    PAINTSTRUCT ps;
+    static HWND hList;
+    UINT uFileNo;
+    char szFileName[256];
+    HDROP hDrop;
+
+    switch(msg) {
+    case WM_CREATE: {
+        RECT rect;
+        GetClientRect(hWnd, &rect);
+        hList = CreateWindow(
+                    TEXT("LISTBOX"), NULL, 
+                    WS_CHILD | WS_VISIBLE | WS_BORDER,
+                    40, 0, rect.right, rect.bottom-40, hWnd, (HMENU)ID_LISTBOX,
+                    ((LPCREATESTRUCT)(lParam))->hInstance, NULL);
+        CreateWindow(
+                    TEXT("BUTTON"), TEXT("OK"),
+                    WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
+                    0, 0, 100, 30, hWnd, (HMENU)ID_BUTTON_OK,
+                    ((LPCREATESTRUCT)(lParam))->hInstance, NULL);
+        CreateWindow(
+                    TEXT("BUTTON"), TEXT("\8dí\8f\9c"),
+                    WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
+                    120, 0, 100, 30, hWnd, (HMENU)ID_BUTTON_DEL,
+                    ((LPCREATESTRUCT)(lParam))->hInstance, NULL);
+        CreateWindow(
+                    TEXT("BUTTON"), TEXT("\83\8a\83Z\83b\83g"),
+                    WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
+                    240, 0, 100, 30, hWnd, (HMENU)ID_BUTTON_RESET,
+                    ((LPCREATESTRUCT)(lParam))->hInstance, NULL);
+        DragAcceptFiles(hWnd, TRUE);
+        }
+        break;
+
+    case WM_DESTROY:
+        PostQuitMessage(0);
+        return 1;
+
+    case WM_COMMAND: {
+        switch(LOWORD(wParam)) {
+            case ID_BUTTON_OK: {
+                SendMessage(hWnd, WM_CLOSE, 0, 0);
+                }
+                break;
+
+            case ID_BUTTON_DEL: {
+                int selectedItem = SendMessage((HWND)hList, LB_GETCURSEL, 0, 0);
+                SendMessage(hList, LB_DELETESTRING, selectedItem, 0);
+                erase_file_name(selectedItem);
+                }
+                break;
+
+            case ID_BUTTON_RESET:
+                SendMessage(hList, LB_RESETCONTENT, 0, 0);
+                clear_file_names();
+                break;
+        }
+        }
+        break;
+
+    case WM_PAINT: {
+        RECT rect;
+        GetClientRect(hWnd, &rect);
+        //AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, 0);
+        SetWindowPos(hList, NULL, 0, 40, rect.right-rect.left
+                    , rect.bottom-rect.top-40, 0);
+        }
+        break;
+
+    case WM_DROPFILES: {
+        hDrop = (HDROP)wParam;
+        uFileNo = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, NULL, 0);
+        int i;
+        for(i = 0; i<(int)uFileNo; i++) {
+            DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
+            SendMessage((HWND)hList, LB_ADDSTRING, 0, (long)szFileName);
+            add_file_name(szFileName);
+/*
+            if(ShellExecute(hWnd, NULL, szFileName, NULL, NULL, SW_SHOWNORMAL) <= (HINSTANCE)32)
+            {
+                MessageBox(hWnd, "\83t\83@\83C\83\8b\82ð\8aJ\82¯\82Ü\82¹\82ñ\82Å\82µ\82½", "\8e¸\94s", MB_OK);
+            }
+*/
+        }
+        DragFinish(hDrop);
+        }
+        break;
+
+    }
+    return DefWindowProc(hWnd, msg, wParam, lParam);
+}
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+            PSTR lpCmdLine, int nCmdShow)
+{
+    HWND hWnd;
+    MSG msg;
+    WNDCLASS winc;
+
+    init_file_name();
+
+    winc.style = CS_HREDRAW | CS_VREDRAW;
+    winc.lpfnWndProc = WndProc;
+    winc.cbClsExtra = winc.cbWndExtra = 0;
+    winc.hInstance = hInstance;
+    winc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+    winc.hCursor = LoadCursor(NULL, IDC_ARROW);
+    winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+    winc.lpszMenuName = NULL;
+    winc.lpszClassName = TEXT("mousehook");
+
+    if(!RegisterClass(&winc)) {
+        fprintf(stderr, "RegisterClass\n");
+        final_file_name();
+        return 1;
+    }
+
+    hWnd = CreateWindow(
+        TEXT("mousehook"), TEXT("Kitty on your lap"),
+        WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+        CW_USEDEFAULT, CW_USEDEFAULT,
+        300, 300,
+        NULL, NULL, hInstance, NULL);
+
+    if(hWnd == NULL) {
+        fprintf(stderr, "CreateWindow\n");
+        final_file_name();
+        return 1;
+    }
+
+    while(GetMessage(&msg, NULL, 0, 0)) {
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
+    }
+
+    output_file_names();
+
+    final_file_name();
+    return msg.wParam;
+}