• 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;
    }
  • 相关阅读:
    Ext.dataGroupingStore/JsonStore/SimpleStore
    转:LinQ操作汇总(From CSharpSamples)
    XSLT教程 比较全的
    使用ASP.Net Forms模式实现WebService身份验证
    关于DataRow的RowState和RowVersion
    C#日志工具汇总
    转 Using log4net,
    js//初始话日期
    两个数据库表的连接 查询
    ExtJS入门之三 查询
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12484705.html
Copyright © 2020-2023  润新知