windows 的最简单的窗口程序的处理流程
2018-02-03 21:20
363 查看
For example, suppose the user presses the left mouse button. This causes a chain of events:
The operating system places a
WM_LBUTTONDOWN message on the message queue.
Your program calls the
GetMessage function.
GetMessage pulls the
WM_LBUTTONDOWN message from the queue and fills in the
MSG structure.
Your program calls the
TranslateMessage and
DispatchMessage functions.
Inside
DispatchMessage, the operating system calls your window procedure.
Your window procedure can either respond to the message or ignore it.
例如,假设用户按下鼠标左键,这个动作将引发连串反应:
1、操作系统将鼠标左键被按下的事件放入事件队列;
2、你的程序(指自己编写的窗口程序)调用GetMessage函数;
3、GetMessage函数从消息队列中取出鼠标左键被按下这条消息,并将它填入MSG结构的对象中;
4、你的程序调用TranslateMessage 和
DispatchMessage 函数;
5、在DispatchMessage函数中,系统又调用了你程序中的window procedure函数;
6、你的window procedure函数可以回应这条消息,或者忽略这条消息。
配合源码:https://msdn.microsoft.com/zh-cn/library/windows/desktop/ff381409.aspx
The operating system places a
WM_LBUTTONDOWN message on the message queue.
Your program calls the
GetMessage function.
GetMessage pulls the
WM_LBUTTONDOWN message from the queue and fills in the
MSG structure.
Your program calls the
TranslateMessage and
DispatchMessage functions.
Inside
DispatchMessage, the operating system calls your window procedure.
Your window procedure can either respond to the message or ignore it.
例如,假设用户按下鼠标左键,这个动作将引发连串反应:
1、操作系统将鼠标左键被按下的事件放入事件队列;
2、你的程序(指自己编写的窗口程序)调用GetMessage函数;
3、GetMessage函数从消息队列中取出鼠标左键被按下这条消息,并将它填入MSG结构的对象中;
4、你的程序调用TranslateMessage 和
DispatchMessage 函数;
5、在DispatchMessage函数中,系统又调用了你程序中的window procedure函数;
6、你的window procedure函数可以回应这条消息,或者忽略这条消息。
配合源码:https://msdn.microsoft.com/zh-cn/library/windows/desktop/ff381409.aspx
#ifndef UNICODE #define UNICODE #endif #include <windows.h> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) { // Register the window class. const wchar_t CLASS_NAME[] = L"Sample Window Class"; WNDCLASS wc = { }; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = CLASS_NAME; RegisterClass(&wc); // Create the window. HWND hwnd = CreateWindowEx( 0, // Optional window styles. CLASS_NAME, // Window class L"Learn to Program Windows", // Window text WS_OVERLAPPEDWINDOW, // Window style // Size and position CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, // Parent window NULL, // Menu hInstance, // Instance handle NULL // Additional application data ); if (hwnd == NULL) { return 0; } ShowWindow(hwnd, nCmdShow); // Run the message loop. MSG msg = { }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1)); EndPaint(hwnd, &ps); } return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
相关文章推荐
- Windows窗口程序中的printf处理
- 一个能够检查Windows传递给窗口消息处理程序的键盘内容和字符消息的程序
- Directx3D9学习之二:Windows编程之最简单窗口程序
- Windows编程之最简单窗口程序
- windows程序消息处理流程
- windows的窗口消息.处理流程本质.
- windows终止处理程序( __try __finally) 简单解析
- 最简单的Windows窗口程序,使用main函数,隐藏控制台等,适合window编程入门
- windows简单窗口程序
- windows终止处理程序( __try __finally) 简单解析
- 用C写最简单的Windows窗口程序——WINAPI HelloWorld
- Delphi使用Windows API 创建最基本的窗口程序Hello,Windows演示
- 用C#写一个简单的WINDOWS服务程序
- 【笔记】Qt程序在Windows、OS X、CentOS、Ubuntu下的打包处理
- windows程序窗体创建流程模型A--发送自定义消息逻辑上出现Bug
- 《网络渗透技术》学习笔记(1)--Windows平台上一个最简单溢出程序的调试 zz
- 发现Windows程序 最主要的还是要理解消息和窗口的相互调用,相互影响是如何实现的,才能更准确的去理解Windows程序,去编好自己想要的程序功能
- Asp.Net基础 - 1.Web应用程序和网站 + 2.最简单的ASP.Net程序处理过程 + 3.ASP.Net的IsPostBack揭秘
- ncurses简单的一个多窗口程序
- iOS程序之事件处理流程