记一次程序bug引发的电脑异常

    技术2025-05-01  36

    记一次程序bug引发的电脑异常

    正确程序
    #include <iostream> #include <windows.h> using namespace std; int main() { LPCSTR lpszDesktop = "H"; HDESK hOld = GetThreadDesktop(GetCurrentThreadId()); HDESK hdesk=CreateDesktopA(lpszDesktop,NULL,NULL,0,GENERIC_ALL, NULL); if ((NULL == hdesk)) { MessageBox(NULL, "失敗!", "測試", MB_OK | MB_ICONERROR); return 1; } SetThreadDesktop(hdesk); SwitchDesktop(hdesk); MessageBox(NULL, "成功!", "測試", MB_OK); SwitchDesktop(hOld); CloseDesktop(hdesk); return 0; }
    错误程序
    #include <iostream> #include <windows.h> using namespace std; int main() { LPCSTR lpszDesktop = "H"; //HDESK hOld = GetThreadDesktop(GetCurrentThreadId()); HDESK hdesk=CreateDesktopA(lpszDesktop,NULL,NULL,0,GENERIC_ALL, NULL); if ((NULL == hdesk)) { MessageBox(NULL, "失敗!", "測試", MB_OK | MB_ICONERROR); return 1; } SetThreadDesktop(hdesk); SwitchDesktop(hdesk); MessageBox(NULL, "成功!", "測試", MB_OK); //SwitchDesktop(hOld); CloseDesktop(hdesk); return 0; }
    错误原因

    没有保存原窗口句柄导致程序结束后无法调回原窗口。由于本程序未添加窗口功能,其结果为除鼠标图标外其他图标全部消失且无法使用,执行explorer.exe无效,尚未找到除按电源键强制关机外的其他解决办法。

    又get到一种整疯舍友的新方法。

    Processed: 0.010, SQL: 9