windows 消息机制的学习
概述
链接1:http://www.cppblog.com/suiaiguo/archive/2009/07/18/90412.html
链接2:http://www.cnblogs.com/findumars/p/3948427.html
代码框架
#include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, , ))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ; switch (message)
{
case WM_CREATE:
PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return ; case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return ; case WM_DESTROY:
PostQuitMessage () ;
return ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Windows 函数
HWND WINAPI CreateWindow(
_In_opt_ LPCTSTR lpClassName,
_In_opt_ LPCTSTR lpWindowName,
_In_ DWORD dwStyle, // Window Style
_In_ int x,
_In_ int y,
_In_ int nWidth,
_In_ int nHeight,
_In_opt_ HWND hWndParent,
_In_opt_ HMENU hMenu,
_In_opt_ HINSTANCE hInstance,
_In_opt_ LPVOID lpParam
);
//使用CreateWindow之前要先依次 【定义】和 【注册】 【窗口类型】
// 【定义】 并初始化
WNDCLASS wndclass;
......
wndclass.lpszClassName = TEXT("WindowClassName");
...... // 【注册】
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ;
return ;
} //CreateWindow 与 窗口类型wndclass 的联系是通过 CreateWindow 第一个 参数建立起来的
// 如果要使用上面第3行定义的 wndclass 则使用时第一个参数如下: hwnd1 = CreateWindow( TEXT("WindowClassName"), // window class name
.
.
.
NULL) ; // creation parameters //CreateWindow 后必须使用以下两函数才能 显示和刷新
ShowWindow (hwnd1, iCmdShow) ; //设置特定的状态
UpdateWindow (hwnd1) ; // 向procedure 发送 MS_PAINT
Windows Notifications (Windows Procedure 所接收的“通知”)
KeyBord Input Notification
windows 消息机制的学习的更多相关文章
- <Win32_1>深入浅出windows消息机制[转自crocodile_]
上学期学习了Java ,感觉Java写一个窗口真心简单,很易上手,也就难怪很多开发人员选择Java作为自己的开发编程语言.但是由于自身对windows的热爱,让我觉得c.c++语言才是我亲睐的编程语言 ...
- 转:Windows消息机制要点
Windows消息机制要点 1. 窗口过程 每个窗口会有一个称为窗口过程的回调函数(WndProc),它带有四个参数,分别为:窗口句柄(Window Handle),消息ID(Message ...
- Windows消息机制
Windows的消息系统是由3个部分组成的: · 消息队列.Windows能够为所有的应用程序维护一个消息队列.应用程序必须从消息队列中获取消息,然后分派给某个窗口.· 消息循环.通过这个循环机制应用 ...
- 我对windows消息机制的理解(参考深入浅出MFC,欢迎批评指正!!)
以消息为基础,以事件驱动之 程序的进行依靠外部消息来驱动,即:程序不断等待任何可能的输入,然后做判断,然后再做适当的处理. 消息输入:操作系统捕获,以消息形式进入程序.(操作系统通过其USERS模块中 ...
- 深入Delphi -- Windows 消息机制
http://www.txsz.net/xs/delphi/3/Windows%20%E6%B6%88%E6%81%AF%E6%9C%BA%E5%88%B6.htm Windows 消息机制 by m ...
- 收藏:Windows消息机制
百度百科介绍的windows消息机制也不错:http://baike.baidu.com/view/672379.htm Windows的应用程序一般包含窗口(Window),它主要为用户提供一种可视 ...
- windows消息机制(转)
1. 引言Windows 在操作系统平台占有绝对统治地位,基于Windows 的编程和开发越来越广泛.Dos 是过程驱动的,而Windows 是事件驱动的[6],这种差别的存在使得很多Dos 程序员不 ...
- 深入理解windows 消息机制
深入理解Windows消息机制 今天我们来学一学Windows消息机制,我们知道在传统的C语音程序中,当我们需要打开一个文件时,我们可以调用fopen()函数,这个函数最后又会调用操作系统提供的函数以 ...
- windows消息机制框架原理【简单版本】
windows消息机制框架原理 结合两张图理解 窗口和窗口类 Windows UI 应用程序 (e) 具有一个主线程 (g).一个或多个窗口 (a) 和一个或多个子线程 (k) [工作线程或 UI 线 ...
随机推荐
- Canvas transform浅析
没有前奏,直接进入主题 transform调用方法: ctx.transform(a,b,c,d,e,f);如下 var ctx = document.getElementById("myC ...
- 移动Web开发技巧
META相关 1. 添加到主屏后的标题(IOS) <meta name="apple-mobile-web-app-title" content="标题" ...
- HTTPS双向认证
生成证书 openssl genrsa -des3 -out server.key 2048 openssl req -new -x509 -key server.key -out ca.crt -d ...
- 生成PDF并下载。
例子是生成一个pdf格式的证书: //创建Document Document document = null; //为该Document创建一个Writer实例 PdfWriter writer = ...
- 加速器eaccelerator不兼容高版本php
话说PHP官方发布PHP5.4已经有一阵了,根据使用的情况来看,似乎还是很不错的.从初始发布到现在升级到的PHP5.4.4,修正不少的Bug.PHP5.4新的版本,除了提供了更多新的特性,还有大幅的效 ...
- UIBarButtonItem-添加自定义Left或者Right按钮 <总结>
为UINavigationController添加UINavigationItem 1.添加返回导航按钮backBarButtonItem 1.用系统自带的返回按钮 UIBarButtonIt ...
- Swift - 04 - 浮点型
import UIKit var str = "Hello, playground" // 显式定义浮点型常量 let PI:Float = 3.141592612312312 l ...
- JavaScript_ECMA5数组新特性
var arr = [ 1, 2, 3, 4, 5, 4, 3, 2, 1 ]; 新加位置的方法: indexOf lastIndexOf1.1个参数的时候表示传值 返回索引位置(index从0开始) ...
- NOI 191钉子和小球.cpp
#include<iostream> #include<cstdio> #include<cstring> using namespace std; ][]; in ...
- Chrome扩展与用户隐私
转载自https://www.imququ.com/post/chrome-extensions-and-user-privacy.html Google Chrome浏览器应该早就是大家的默认了 ...