' note for hellowin!
来源:互联网 发布:类似美工的职业 编辑:程序博客网 时间:2024/04/28 07:53
// note for hellowin/*------------------------------------------------------------HELLOWIN.C -- Displays "Hello, Windows 98!" in client area(c) Charles Petzold, 1998------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口过程int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)//szCmdLine sz string-zero//hinstance h for handle//iCmdShow i for int//PSTR ---> char *{static TCHAR szAppName[] = TEXT("HelloWin");HWND hwnd;MSG msg;WNDCLASS wndclass; // 定义一个窗口类对象wndclass.style = CS_HREDRAW | CS_VREDRAW;// 定义类的风格wndclass.lpfnWndProc = WndProc;//设定窗口过程wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance; //WinMain的第一个参数//基于该窗口类设定图标wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);/// 1 loadicon 加载程序图标//当鼠标指针出现在这类窗口的客户区内时 将 变成一个箭头wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);/// 2 loadcursor 加载鼠标光标//指定背景色 hbr--> handle to a brush//for 填充像素的着色模式wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);/// 3 getstockobject 获取图形对象 本例中用来对窗口背景进行重绘// WHITE_BURSH返回一个 白色画刷//menuwndclass.lpszMenuName = NULL;//窗口类 的 名称wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass))/// 4 为应用程序的敞口 注册一个窗口类{MessageBox(NULL, TEXT("This program requires Windows NT!"),/// 5 显示消息框szAppName, MB_ICONERROR);return 0;}//createwindow 的 返回值 为一个指向所创建窗口的句柄hwnd = CreateWindow(szAppName, // window class name/// 6 createwindow 创建新窗口TEXT("The Hello Program"), // window captionWS_OVERLAPPEDWINDOW, // window styleCW_USEDEFAULT, // initial x positionCW_USEDEFAULT, // initial y positionCW_USEDEFAULT, // initial x sizeCW_USEDEFAULT, // initial y sizeNULL, // parent window handleNULL, // window menu handlehInstance, // program instance handleNULL); // creation parameters//下面这两行勇于窗口的显示ShowWindow(hwnd, iCmdShow);/// 7 在屏幕中 显示窗口UpdateWindow(hwnd);/// 8指示窗口对其自身进行重绘//updatawindow向wndproc 发送 vm_paint 完成//Windows为每一个运行着的Windows程序都维护着一个消息队列//当输入事件发生后 Windows会自动将这些事件 转化为消息 放在 消息队列中while (GetMessage(&msg, NULL, 0, 0))/// 9从消息队列获取消息{TranslateMessage(&msg);/// 10 翻译 一些键盘消息DispatchMessage(&msg);/// 11将消息发送给窗口过程}return msg.wParam;}//一个Windows程序可以包含多个窗口过程// 但是一个窗口过程总是与一个通过调用registerclass注册的 窗口类 想关联// createwindow是基于特定的窗口类来创建窗口 基于一个窗口类可以创建多个窗口/*typedef struct tagMSG{HWND hwnd;UNIT message;WPARAM wParam;LPARAM lParam;DWORD time;POINT pt;)MSG;*/// hwnd for handle 接受消息的窗口句柄 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)/// return long{//uint--> unsigned int //WPARAM //LPARAM ----> long //32// HDC hdc;PAINTSTRUCT ps;RECT rect;switch (message){case WM_CREATE:/// PlaySound(TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC);/// 12 播放声音文件return 0;case WM_PAINT:hdc = BeginPaint(hwnd, &ps);/// 13标明窗口绘制开始GetClientRect(hwnd, &rect);/// 14获取窗口客户区的尺寸DrawText(hdc, TEXT("Hello, Windows 98!"), -1, &rect,/// 15显示一个文本字符串DT_SINGLELINE | DT_CENTER | DT_VCENTER);EndPaint(hwnd, &ps);/// 16结束窗口绘制return 0;case WM_DESTROY:PostQuitMessage(0);/// 17将退出消息 插入 消息队列return 0;}// 对所有窗口过程没有处理的消息进行默认处理return DefWindowProc(hwnd, message, wParam, lParam);/// 18执行默认的消息处理}//another datastructure : MSG WNDCLASS PAINTSTRUCT RECT///FOR :句柄/*HINCSTANCE : 实例句柄--程序本身HWND : 窗口句柄HDC : 设备环境句柄//for another: HICON HCURSOR HBRUSH*///句柄的是指是引用某个对象的数值
0 0
- ' note for hellowin!
- HELLOWIN程式---HELLOWIN.C
- First note for testing
- note for tty
- note for rails guide
- note for pci spec
- Note for Oracle
- Note for Shell
- Note for Linux
- Note for Sybase
- Note for iSON
- Note for Eclipse
- Note for Dos
- Note for AIX
- Note for Hadoop
- NOTE 7 for Mirroring
- study note for dojo
- Note for 20140725
- STL中map、set的数据结构及底层实现
- Android中的系统广播集合
- Java反射机制总结之二
- Topic model:materials and tools
- qt5 cannot find -lGL
- ' note for hellowin!
- Configure Eclipse IDE in catkin of Ros Groovy
- 根据文件,算工资
- SOLR管理平台的使用小技巧
- Opencv1.0视频处理与解码器
- C#基础知识梳理系列五:委托与事件
- 增强for循环用法
- 认识Weblogic中各个机构
- How Tomcat works之第六章:Lifecycle生命周期