SuspendThread and ResumeThread

记录下,用于复现

#include 
#include 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{switch (message){case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;
}
DWORD WINAPI createyourwindow(LPVOID param)
{WNDCLASSEXW wcex = { 0 };wcex.cbSize = sizeof(WNDCLASSEX);HWND* hWnd = (HWND*)param;wcex.style = CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc = WndProc;wcex.cbClsExtra = 0;wcex.cbWndExtra = 0;wcex.hInstance = GetModuleHandle(NULL);wcex.hCursor = LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);wcex.lpszClassName = L"MyClass";RegisterClassExW(&wcex);*hWnd = CreateWindowW(L"MyClass", L"window", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, GetModuleHandle(NULL), NULL);if (!*hWnd){return FALSE;}ShowWindow(*hWnd, SW_NORMAL);UpdateWindow(*hWnd);MSG msg;// Main message loop:while (GetMessage(&msg, NULL, 0, 0)){if (!TranslateAccelerator(msg.hwnd, NULL, &msg)){TranslateMessage(&msg);DispatchMessage(&msg);}}return 0;
}int main()
{DWORD ThreadId;HWND hwnd = NULL;HANDLE hThread = CreateThread(NULL, 0, createyourwindow, (LPVOID)&hwnd, 0, &ThreadId);MSG msg;DWORD tid = GetCurrentThreadId(); // used in the PostThreadMessage().// Main message loop:while (GetMessage(&msg, NULL, 0, 0)){if (msg.message == WM_USER && hwnd != NULL){SuspendThread(hThread);printf("suspend\n");getchar(); //To Do here. ResumeThread(hThread);}}WaitForSingleObject(hThread, INFINITE);return 0;}
#include 
#include 
int main()
{DWORD tid = 14328;PostThreadMessage(tid, WM_USER, 0, 0);return 0;
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部