#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
就可以
我试了 还是不行啊
麻烦各位高人帮个忙
我该怎么做??
3 个解决方案
#1
可能需要较新的Platform SDK.
#2
哦 好了 可以了
再问下吧
怎么样屏蔽XP的系统热键??像Ctrl+ESC Alt+ESC WIN键等?
貌似用底层钩子也做不到啊
以下是我的底层键盘钩子函数的部分代码 可是不起作用~~
case WM_SYSKEYUP:
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
fEatKeystroke =
p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) || // 屏蔽Win
// 屏蔽Alt+Tab
p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Alt+Esc
((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Ctrl+Esc
p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
break;
}
再问下吧
怎么样屏蔽XP的系统热键??像Ctrl+ESC Alt+ESC WIN键等?
貌似用底层钩子也做不到啊
以下是我的底层键盘钩子函数的部分代码 可是不起作用~~
case WM_SYSKEYUP:
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
fEatKeystroke =
p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) || // 屏蔽Win
// 屏蔽Alt+Tab
p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Alt+Esc
((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Ctrl+Esc
p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
break;
}
#3
写个键盘钩子,但无法屏蔽CTRL+DEL+ALT
/***********************************
全局键盘钩子处理函数
说明:禁用Win键,ALT+TAB,ALT+F4
************************************/
LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT result;
if(HC_ACTION != nCode)
return CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
PKBDLLHOOKSTRUCT pKBStruct;
pKBStruct = (PKBDLLHOOKSTRUCT)lParam;
if(wParam == WM_SYSKEYDOWN)
{
switch(pKBStruct->vkCode)
{
case VK_F4:
TRACE("Alt+F4 Pressed\n");
result = TRUE;
break;
case VK_TAB:
TRACE("Alt+Tab Pressed\n");
ReleaseMutex(theApp.m_hMutex);
result = TRUE;
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
else
{
switch(pKBStruct->vkCode)
{
case VK_LWIN:
TRACE("Left Win Pressed\n");
result = TRUE;
break;
case VK_RWIN:
TRACE("Right Win Pressed\n");
result = TRUE;
break;
case VK_ESCAPE:
if(GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1))
{
TRACE("CTRL+ESC Pressed\n");
result = TRUE;
}
else
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
return result;
}
BOOL CViewDocApp::InitInstance()
{
........................................
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// 设置全局键盘钩子
::SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,AfxGetInstanceHandle(),NULL);
return TRUE;
}
如果编译的时候说WH_KEYBOARD_LL没定义,你可以用13来代替它,或者在前面加上
#define _WIN32_WINNT 0x0500
/***********************************
全局键盘钩子处理函数
说明:禁用Win键,ALT+TAB,ALT+F4
************************************/
LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT result;
if(HC_ACTION != nCode)
return CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
PKBDLLHOOKSTRUCT pKBStruct;
pKBStruct = (PKBDLLHOOKSTRUCT)lParam;
if(wParam == WM_SYSKEYDOWN)
{
switch(pKBStruct->vkCode)
{
case VK_F4:
TRACE("Alt+F4 Pressed\n");
result = TRUE;
break;
case VK_TAB:
TRACE("Alt+Tab Pressed\n");
ReleaseMutex(theApp.m_hMutex);
result = TRUE;
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
else
{
switch(pKBStruct->vkCode)
{
case VK_LWIN:
TRACE("Left Win Pressed\n");
result = TRUE;
break;
case VK_RWIN:
TRACE("Right Win Pressed\n");
result = TRUE;
break;
case VK_ESCAPE:
if(GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1))
{
TRACE("CTRL+ESC Pressed\n");
result = TRUE;
}
else
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
return result;
}
BOOL CViewDocApp::InitInstance()
{
........................................
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// 设置全局键盘钩子
::SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,AfxGetInstanceHandle(),NULL);
return TRUE;
}
如果编译的时候说WH_KEYBOARD_LL没定义,你可以用13来代替它,或者在前面加上
#define _WIN32_WINNT 0x0500
#1
可能需要较新的Platform SDK.
#2
哦 好了 可以了
再问下吧
怎么样屏蔽XP的系统热键??像Ctrl+ESC Alt+ESC WIN键等?
貌似用底层钩子也做不到啊
以下是我的底层键盘钩子函数的部分代码 可是不起作用~~
case WM_SYSKEYUP:
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
fEatKeystroke =
p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) || // 屏蔽Win
// 屏蔽Alt+Tab
p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Alt+Esc
((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Ctrl+Esc
p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
break;
}
再问下吧
怎么样屏蔽XP的系统热键??像Ctrl+ESC Alt+ESC WIN键等?
貌似用底层钩子也做不到啊
以下是我的底层键盘钩子函数的部分代码 可是不起作用~~
case WM_SYSKEYUP:
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
fEatKeystroke =
p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) || // 屏蔽Win
// 屏蔽Alt+Tab
p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Alt+Esc
((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
// 屏蔽Ctrl+Esc
p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
break;
}
#3
写个键盘钩子,但无法屏蔽CTRL+DEL+ALT
/***********************************
全局键盘钩子处理函数
说明:禁用Win键,ALT+TAB,ALT+F4
************************************/
LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT result;
if(HC_ACTION != nCode)
return CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
PKBDLLHOOKSTRUCT pKBStruct;
pKBStruct = (PKBDLLHOOKSTRUCT)lParam;
if(wParam == WM_SYSKEYDOWN)
{
switch(pKBStruct->vkCode)
{
case VK_F4:
TRACE("Alt+F4 Pressed\n");
result = TRUE;
break;
case VK_TAB:
TRACE("Alt+Tab Pressed\n");
ReleaseMutex(theApp.m_hMutex);
result = TRUE;
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
else
{
switch(pKBStruct->vkCode)
{
case VK_LWIN:
TRACE("Left Win Pressed\n");
result = TRUE;
break;
case VK_RWIN:
TRACE("Right Win Pressed\n");
result = TRUE;
break;
case VK_ESCAPE:
if(GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1))
{
TRACE("CTRL+ESC Pressed\n");
result = TRUE;
}
else
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
return result;
}
BOOL CViewDocApp::InitInstance()
{
........................................
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// 设置全局键盘钩子
::SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,AfxGetInstanceHandle(),NULL);
return TRUE;
}
如果编译的时候说WH_KEYBOARD_LL没定义,你可以用13来代替它,或者在前面加上
#define _WIN32_WINNT 0x0500
/***********************************
全局键盘钩子处理函数
说明:禁用Win键,ALT+TAB,ALT+F4
************************************/
LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT result;
if(HC_ACTION != nCode)
return CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
PKBDLLHOOKSTRUCT pKBStruct;
pKBStruct = (PKBDLLHOOKSTRUCT)lParam;
if(wParam == WM_SYSKEYDOWN)
{
switch(pKBStruct->vkCode)
{
case VK_F4:
TRACE("Alt+F4 Pressed\n");
result = TRUE;
break;
case VK_TAB:
TRACE("Alt+Tab Pressed\n");
ReleaseMutex(theApp.m_hMutex);
result = TRUE;
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
else
{
switch(pKBStruct->vkCode)
{
case VK_LWIN:
TRACE("Left Win Pressed\n");
result = TRUE;
break;
case VK_RWIN:
TRACE("Right Win Pressed\n");
result = TRUE;
break;
case VK_ESCAPE:
if(GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1))
{
TRACE("CTRL+ESC Pressed\n");
result = TRUE;
}
else
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
break;
default:
result = CallNextHookEx(theApp.m_hHook,nCode,wParam,lParam);
}
}
return result;
}
BOOL CViewDocApp::InitInstance()
{
........................................
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// 设置全局键盘钩子
::SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,AfxGetInstanceHandle(),NULL);
return TRUE;
}
如果编译的时候说WH_KEYBOARD_LL没定义,你可以用13来代替它,或者在前面加上
#define _WIN32_WINNT 0x0500