40

利用SendMessage模拟鼠标左键双击打开文件,但是文件没打开,请熟悉Windows编程的大神指点

利用SendMessage模拟鼠标左键双击打开文件,但是文件没打开。打印4次结果0。请熟悉Windows编程的大神指点

// SendMessage.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "Winuser.h"

int main(int argc, char* argv[])
{
    HWND desktop = GetDesktopWindow();//屏幕窗口句柄
    desktop=GetWindow(desktop,GW_CHILD);
    /*8DWORD ProcessId;//要打开窗口的进程标识符
    ::GetWindowThreadProcessId(desktop, &ProcessId);
    HANDLE processH = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessId);*/
    int x = 30;
    int y = 24;
    ::SetCursorPos(x,y);
    //Sleep(1000);
    LRESULT result1 = ::SendMessage(desktop, WM_LBUTTONDOWN,VK_LBUTTON,MAKELPARAM(x,y));
    LRESULT result2 = ::SendMessage(desktop, WM_LBUTTONUP,0,MAKELPARAM(x,y));
    LRESULT result3 = ::SendMessage(desktop, WM_LBUTTONDOWN,VK_LBUTTON,MAKELPARAM(x,y));
    LRESULT result4 = ::SendMessage(desktop, WM_LBUTTONUP,0,MAKELPARAM(x,y));
    printf("%d %d %d %d\n",result1,result2,result3,result4);
    //::SendMessage(NULL, WM_LBUTTONDOWN, 0,(y<<16)|x);
    //::SendMessage(NULL, WM_LBUTTONUP, 0,(y<<16)|x);

    return 0;
}

查看全部
qq_30091945
追梦者_AIer
2019/01/21 18:20
  • microsoft
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复