博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++屏蔽Win10系统快捷键
阅读量:6078 次
发布时间:2019-06-20

本文共 5042 字,大约阅读时间需要 16 分钟。

很久之前实现的功能,也是参考其他人的实现,时间太久,具体参考哪里已经记不得了。

这里不仅能屏蔽一般的快捷键,还可以屏蔽ctrl+atl+del。

int globlePid = 0;HHOOK keyHook = NULL;HHOOK mouseHook = NULL;//键盘钩子过程LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam){    //在WH_KEYBOARD_LL模式下lParam 是指向KBDLLHOOKSTRUCT类型地址    KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;    //如果nCode等于HC_ACTION则处理该消息,如果小于0,则钩子子程就必须将该消息传递给 CallNextHookEx    //if (nCode == HC_ACTION){
if (pkbhs->vkCode == VK_ESCAPE && GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(VK_SHIFT) & 0x8000){ qDebug() << "Ctrl+Shift+Esc"; return 1; } else if (pkbhs->vkCode == VK_ESCAPE && GetAsyncKeyState(VK_CONTROL) & 0x8000){ qDebug() << "Ctrl+Esc"; return 1; } else if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN){ qDebug() << "Alt+Tab"; return 1; } else if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags &LLKHF_ALTDOWN){ qDebug() << "Alt+Esc"; return 1; } else if (pkbhs->vkCode == VK_LWIN || pkbhs->vkCode == VK_RWIN){ qDebug() << "LWIN/RWIN"; return 1; } else if (pkbhs->vkCode == VK_F4 && pkbhs->flags & LLKHF_ALTDOWN){ qDebug() << "Alt+F4"; return 1; } //return 1;//返回1表示截取消息不再传递,返回0表示不作处理,消息继续传递 //} return CallNextHookEx(keyHook, nCode, wParam, lParam);}//鼠标钩子过程LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam){ return 1;}//卸载钩子void unHook(){ UnhookWindowsHookEx(keyHook); // UnhookWindowsHookEx(mouseHook);}//安装钩子,调用该函数即安装钩子void setHook(){ //这两个底层钩子,不要DLL就可以全局 //底层键盘钩子 keyHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyProc, GetModuleHandle(NULL), 0); //底层鼠标钩子 // mouseHook =SetWindowsHookEx( WH_MOUSE_LL,mouseProc,GetModuleHandle(NULL),0);}//提升权限void EnableDebugPriv(){ HANDLE hToken; LUID sedebugnameValue; TOKEN_PRIVILEGES tkp; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { return; } if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue)) { CloseHandle(hToken); return; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Luid = sedebugnameValue; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL)) { CloseHandle(hToken); return; }}char* ConvertLPWSTRToLPSTR(LPWSTR lpwszStrIn){ LPSTR pszOut = NULL; if (lpwszStrIn != NULL) { int nInputStrLen = wcslen(lpwszStrIn); // Double NULL Termination int nOutputStrLen = WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, NULL, 0, 0, 0) + 2; pszOut = new char[nOutputStrLen]; if (pszOut) { memset(pszOut, 0x00, nOutputStrLen); WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, pszOut, nOutputStrLen, 0, 0); } } return pszOut;}//冻结void Freeze(){ //枚举进程信息 PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); int processPid; //CString strTmp; BOOL b = ::Process32First(hProcessSnap, &pe32); while (b) { processPid = pe32.th32ProcessID; char *exeFile = ConvertLPWSTRToLPSTR(pe32.szExeFile); if (strcmp(exeFile, "winlogon.exe") == 0) { break; } delete[] exeFile; b = ::Process32Next(hProcessSnap, &pe32); } ::CloseHandle(hProcessSnap); THREADENTRY32 th32; th32.dwSize = sizeof(th32); HANDLE hThreadSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); globlePid = processPid; unsigned long Pid; Pid = processPid; b = ::Thread32First(hThreadSnap, &th32); while (b) { if (th32.th32OwnerProcessID == Pid) { HANDLE oth = OpenThread(THREAD_ALL_ACCESS, FALSE, th32.th32ThreadID); if (!(::SuspendThread(oth))) { qDebug() << "freeze successed"; } else { qDebug() << "freeze failed"; } CloseHandle(oth); break; } ::Thread32Next(hThreadSnap, &th32); } ::CloseHandle(hThreadSnap);}void unFreeze(){ unsigned long Pid; Pid = globlePid; THREADENTRY32 th32; th32.dwSize = sizeof(th32); HANDLE hThreadSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); BOOL b = ::Thread32First(hThreadSnap, &th32); while (b) { if (th32.th32OwnerProcessID == Pid) { HANDLE oth = OpenThread(THREAD_ALL_ACCESS, FALSE, th32.th32ThreadID); if (::ResumeThread(oth)) { qDebug() << "unfreeze successed"; } else { qDebug() << "unfreeze failed"; } CloseHandle(oth); break; } ::Thread32Next(hThreadSnap, &th32); } ::CloseHandle(hThreadSnap);}

调用:

//屏蔽ctrl+alt+del  EnableDebugPriv();  Freeze();    //屏蔽其他快捷键   setHook();

转载于:https://www.cnblogs.com/tiandsp/p/10275683.html

你可能感兴趣的文章
搞IT的同学们,你们在哪个等级__那些年发过的帖子
查看>>
且谈语音搜索
查看>>
MySQL数据库导入导出常用命令
查看>>
低版本Samba无法挂载
查看>>
Telegraf+Influxdb+Grafana构建监控平台
查看>>
使用excel 展现数据库内容
查看>>
C#方法拓展
查看>>
MySql.Data.dll的版本
查看>>
Linux系统磁盘管理
查看>>
hdu 2191 (多重背包+二进制优化)
查看>>
home.php
查看>>
neo4j---删除关系和节点
查看>>
redis分布式锁redisson
查看>>
什么样的企业可以称之为初创企业?
查看>>
Python爬虫之BeautifulSoup
查看>>
《HTML 5与CSS 3权威指南(第3版·下册)》——第20章 使用选择器在页面中插入内容...
查看>>
如何判断自己适不适合做程序员?这几个特点了解一下
查看>>
newinstance()和new有什么区别
查看>>
android下载封装类
查看>>
[node] 用 node-webkit 开发桌面应用
查看>>