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\n"); 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;
}
SuspendThread and ResumeThread的更多相关文章
- 常用的WinAPI函数整理
常用的WinAPI函数整理 一.进程 创建进程: CreateProcess("C:\\windows\\notepad.exe",0,0,0,0,0,0,0,&s ...
- Worker Thread
http://www.codeproject.com/Articles/552/Using-Worker-Threads Introduction Worker threads are an eleg ...
- C++实现线程池 .
C++实现线程池. 欢迎转载,转载请注明原出处:http://blog.csdn.net/ithzhang/article/details/9020283 代码地址:https://github.co ...
- windows 线程
在windows中进程只是一个容器,用于装载系统资源,它并不执行代码,它是系统资源分配的最小单元,而在进程中执行代码的是线程,线程是轻量级的进程,是代码执行的最小单位. 从系统的内核角度看,进程是一个 ...
- 20160226.CCPP体系详解(0036天)
程序片段(01):01.多线程.c+02.多线程操作.c 内容概要:多线程 ///01.多线程.c #include <stdio.h> #include <stdlib.h> ...
- Atitit sleep原理 node.js sleep解决方案 timer
Atitit sleep原理 node.js sleep解决方案 timer sleep()的实现分为三步: 1.注册一个信号signal(SIGALRM,handler).接收内核给出的一个信 ...
- windows下进程与线程剖析
进程与线程的解析 进程:一个正在运行的程序的实例,由两部分组成: 1.一个内核对象,操作系统用它来管理进程.内核对象也是系统保存进程统计信息的地方. 2.一个地址空间,其中包含所有可执行文件或DLL模 ...
- pthread到Win32thread
一.什么是线程. 线程(thread)是为了提高系统内程序的并发(concurrency)执行程度而提出来的概念,它是比进程更小的能够独立运行的基本单位.在引入线程的系统中,线程是处理器调度(sche ...
- C语言多线程编程一
1. Windows下同时打开多个对话框: #include <Windows.h> #include <process.h> //创建线程 void runmsg(void ...
- MFC【17-1】线程和线程同步化
17.1线程 对于Windows来说所有的线程都是一样的,但MFC却把线程区分为两种类型:User Interface(UI) threads(用户界面(UI)线程)和Worker threads(工 ...
随机推荐
- [转帖]vSphere虚拟化平台(vCenter和ESXi)升级注意事项
https://www.dinghui.org/vmware-vsphere-upgrade.html 最近两年做了蛮多vSphere升级项目,几点思路,做一下汇总整理如下供参考: 一.升级必要性 1 ...
- 【转帖】【笔记】python连接神通数据库
https://www.cnblogs.com/wyongbo/p/17054924.html python连接国产神州通用数据库. 一.准备 下载whl及dll: 链接: https://pan.b ...
- [转帖]@nginx多server及使用优化(php)
文章目录 一.nginx多server优先级 二.禁止IP访问页面 三.nginx的包含include 四.nginx 路径的alias和root 1.配 ...
- lldb3.9.0 安装攻略
Study From https://github.com/dotnet/diagnostics/blob/master/documentation/lldb/centos7/build-instal ...
- css水平居中的5种几种方式
元素水平居中的第一种方式 子元素不需要宽度也可以 <div class="box"> <div class="son"> 我是内容 &l ...
- vue3中beforeRouteEnter 的使用和注意点
beforeRouteEnter 在vue3中的使用 有些时候,我们需要在知道是从哪一个页面过来的. 然后做一些逻辑处理 比如说:从A->B,B页面需要调用接口,回填B页面中的数据 B--> ...
- echarts设置标题样式
<!DOCTYPE html> <html> <!-- https://blog.csdn.net/weixin_42698255/article/details/892 ...
- git创建分支出现 fatal: Not a valid object name: 'master'.
今天使用git 创建新分支的时候 出现了一个错误 fatal: Not a valid object name: 'master'. 问题描述:一个非法的master,原因:本地还没有创建master ...
- Python获取内存、CPU利用率,CPU温度
最近一个项目的需求,在软件上加入硬件实时信息,大概搜索一下,没太好的结果,所以决定自己写一篇 我的代码不难发现,都使用了psutil包,为什么呢,别的包我没太关注,纯粹是这台机的环境上有这个包 如果大 ...
- Leetcode 42题 接雨水(Trapping Rain Water) Java语言求解
题目链接 https://leetcode-cn.com/problems/trapping-rain-water/ 题目内容 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱 ...