zoukankan      html  css  js  c++  java
  • SuspendThread and ResumeThread

    记录下,用于复现

    #include <windows.h>
    #include <iostream>
    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
    ");
    
                getchar(); //To Do here. 
    
                ResumeThread(hThread);
            }
        }
        WaitForSingleObject(hThread, INFINITE);
        return 0;
    
    }
    #include <windows.h>
    #include <iostream>
    int main()
    {
        DWORD tid = 14328;
        PostThreadMessage(tid, WM_USER, 0, 0);
        return 0;
    }
  • 相关阅读:
    office(Word、Excel、PPT等图标异常和桌面无新建解决方案)
    CentOS7安装搭建.Net Core 2.0环境-详细步骤
    Win7系统system进程句柄数一直增加解决方案
    安装.Net Framework 4.6.2时出现“无法建立到信任根颁发机构的证书链”解决方法
    css关于定位那些事情
    1份2015计划书
    js关于弹也遮罩层
    每日一句(2014-10-23)
    每日一句(2014-10-17)
    每日一句(2014-10-16)
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12484705.html
Copyright © 2011-2022 走看看