主题:dll注册热键,求救...............
我是做java的,但现在想要通过动态库注册热键,找了好久没找到相关的代码,特到些处求救,希望能帮帮我这个菜鸟!。。。。。。。。。。。。。
以下是我写的注册的代码,但是热键响应的方法我不知道怎么注册,WndProc方法,是用来响应按键消息的方法,不知道怎么样才能让它被回调。
#include <stdlib.h>
#include "stdafx.h"
#include "org_csj_hotkey_Hotkey.h"
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){
return TRUE;
}
JNIEXPORT void JNICALL Java_org_csj_hotkey_Hotkey_registerHotKey(JNIEnv *, jobject){
printf("进入\n");
RegisterHotKey(NULL,GlobalAddAtom("Ctrl+Alt+w"),MOD_CONTROL|MOD_ALT,'w');
}
JNIEXPORT void JNICALL Java_org_csj_hotkey_Hotkey_unregisterHotKey(JNIEnv *, jobject){
printf("退出\n");
UnregisterHotKey(NULL,GlobalAddAtom("Ctrl+Alt+w"));
}
LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message
parameter
LPARAM lParam) // second message parameter
{
printf("调用\n");
switch (uMsg){
case WM_CREATE:
// Initialize the window.
printf("dll输出:WM_CREATE\n");
return 0;
case WM_PAINT:
printf("dll输出:WM_PAINT\n");
// Paint the window's client area.
return 0;
case WM_SIZE:
// Set the size and position of the window.
printf("dll输出:WM_SIZE\n");
return 0;
case WM_HOTKEY: //处理WM_HOTKEY消息
printf("dll输出:d按了?\n");
return 0;
case WM_DESTROY:
printf("dll输出:WM_DESTROY\n");
// Clean up window-specific data objects.
return 0;
default:
// Process other messages.
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
以下是我写的注册的代码,但是热键响应的方法我不知道怎么注册,WndProc方法,是用来响应按键消息的方法,不知道怎么样才能让它被回调。
#include <stdlib.h>
#include "stdafx.h"
#include "org_csj_hotkey_Hotkey.h"
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){
return TRUE;
}
JNIEXPORT void JNICALL Java_org_csj_hotkey_Hotkey_registerHotKey(JNIEnv *, jobject){
printf("进入\n");
RegisterHotKey(NULL,GlobalAddAtom("Ctrl+Alt+w"),MOD_CONTROL|MOD_ALT,'w');
}
JNIEXPORT void JNICALL Java_org_csj_hotkey_Hotkey_unregisterHotKey(JNIEnv *, jobject){
printf("退出\n");
UnregisterHotKey(NULL,GlobalAddAtom("Ctrl+Alt+w"));
}
LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message
parameter
LPARAM lParam) // second message parameter
{
printf("调用\n");
switch (uMsg){
case WM_CREATE:
// Initialize the window.
printf("dll输出:WM_CREATE\n");
return 0;
case WM_PAINT:
printf("dll输出:WM_PAINT\n");
// Paint the window's client area.
return 0;
case WM_SIZE:
// Set the size and position of the window.
printf("dll输出:WM_SIZE\n");
return 0;
case WM_HOTKEY: //处理WM_HOTKEY消息
printf("dll输出:d按了?\n");
return 0;
case WM_DESTROY:
printf("dll输出:WM_DESTROY\n");
// Clean up window-specific data objects.
return 0;
default:
// Process other messages.
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}