Drag and Drop – 使得程序窗口支持脱拽

Author: 徐艺波(xuyibo) Views: 507 UpdateTime:2007-3-8
      留言

    处理比较简单,在要支持Drag and Drop的窗口创建出来后,调用DragAcceptFiles(hwnd, TRUE),其中第一个参数是这个窗口的句柄.

    然后在这个窗口的回调函数中增加下面的代码:
    case WM_DROPFILES:
    {
    char szBuf[MAX_PATH+40];
    HDROP hDrop = (HDROP)wParam;

    if (IsIconic(hwnd))
    ShowWindow(hwnd,SW_RESTORE);

    //SetForegroundWindow(hwnd);

    DragQueryFile(hDrop,0,szBuf,sizeof(szBuf));
    // Add you code here
    SetDlgItemText(hwnd, IDC_FILENAME, szBuf);

    if (DragQueryFile(hDrop,(UINT)(-1),NULL,0) > 1)
    MessageBox(hwnd, “一次只能拖进一个文件”, “警告”, MB_OK);

    DragFinish(hDrop);
    }
    return 0;

    上面的代码提取在txt2chm,是将在对话框的IDC_FILENAME Edit子窗口中显示脱入文件的路径,将SetDlgItemText替换为你的处理函数就可以了。

留言: (留言使用了AJAX,提交的留言将自动显示在下面)Top
User:

Email:[email protected] QQ:85521028
Copyright ©2002-2007 XuYibo All rights reserved. License | Contributor
网站地图