2016-11-20 49 views
0

我一直在試圖編譯這個C++函數的dll 2天,不幸的是沒有成功。在YouTube上觀看了大約8個視頻,並且所有代碼在每個視頻中看起來都不一樣。與它混淆。使DLL的C + +在dev-C + +

我希望它有一個DLL,我可以在我的autohotkey腳本中調用鼠標或鍵盤事件(因爲ahks鼠標& kb不適用於所有類型的窗口)。

如果您知道如何使用Dev-C++或者有任何提示,我將不勝感激,謝謝。

POINT getCurrentPos(HWND hwnd) 
{ 
    POINT cpos; 
    GetCursorPos(&cpos); 
    ScreenToClient(hwnd, &cpos); 
    return(cpos); 
} 

void rightClick(HWND hWindow, POINT k) 
{ 
    POINT currentPos = getCurrentPos(hWindow); 
    DWORD coordinates = MAKELPARAM(k.x, k.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, 0, coordinates); 
    PostMessage(hWindow, WM_RBUTTONDOWN, MK_RBUTTON, coordinates); 
    PostMessage(hWindow, WM_MOUSEMOVE, MK_RBUTTON, coordinates); 
    PostMessage(hWindow, WM_RBUTTONUP, 0, coordinates); 
    coordinates = MAKELPARAM(currentPos.x, currentPos.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, 0, coordinates); 
} 

void leftClick(HWND hWindow, POINT k) 
{ 
    POINT currentPos = getCurrentPos(hWindow); 
    DWORD coordinates = MAKELPARAM(k.x, k.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, 0, coordinates); 
    PostMessage(hWindow, WM_LBUTTONDOWN, MK_LBUTTON, coordinates); 
    PostMessage(hWindow, WM_MOUSEMOVE, MK_LBUTTON, coordinates); 
    PostMessage(hWindow, WM_RBUTTONUP, 0, coordinates); 
    coordinates = MAKELPARAM(currentPos.x, currentPos.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, 0, coordinates); 
} 

void dragDrop(HWND hWindow, POINT from, POINT to) 
{ 
    POINT currentPos = getCurrentPos(hWindow); 
    DWORD coordinates = MAKELPARAM(from.x, from.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, 0, coordinates); 
    PostMessage(hWindow, WM_LBUTTONDOWN, MK_LBUTTON, coordinates); 
    coordinates = MAKELPARAM(to.x, to.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, MK_LBUTTON, coordinates); 
    PostMessage(hWindow, WM_LBUTTONUP, 0, coordinates); 
    coordinates = MAKELPARAM(currentPos.x, currentPos.y); 
    PostMessage(hWindow, WM_MOUSEMOVE, 0, coordinates); 
} 

void KeyUp(HWND hwnd, int vk_key) 
{ 
    PostMessage(hwnd, WM_KEYUP, vk_key, (MapVirtualKey(vk_key, MAPVK_VK_TO_VSC)) * 0x10000 + 0xC0000000 + 1); 
} 

void KeyDown(HWND hwnd, int vk_key) 
{ 
    PostMessage(hwnd, WM_KEYDOWN, vk_key, (MapVirtualKey(vk_key, MAPVK_VK_TO_VSC)) * 0x10000 + 1); 
} 

void KeyPress(HWND hwnd, int vk_key) 
{ 
    KeyDown(hwnd, vk_key); 
    KeyUp(hwnd, vk_key); 
} 
+0

***在YouTube上觀看約8個視頻和所有的代碼看起來每個視頻不同。與此混淆***請記住,關於如何在'C++'中編碼的視頻往往是錯誤的。請閱讀官方文檔。 – drescherjm

回答