windows 经典程序,回想起当初写这个程序时,心里多么的复杂呀
2013-08-18 09:42
435 查看
windows 经典程序,回想起当初写这个程序时,心里多么的复杂呀
#include <windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance, PSTR szCmdLine,int iCmdShow) { static TCHAR szAppName[]=TEXT("HelloWin32"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style =CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc =(WNDPROC)WndProc; //windows procedure wndclass.cbClsExtra =0; wndclass.cbWndExtra =0; wndclass.hInstance =hInstance; wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);//load an icon for use by program wndclass.hCursor =LoadCursor(NULL,IDC_ARROW); //load cursor for use by program wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); //Obtains a graphic object ,in this case // a brush used for painting the window's background wndclass.lpszMenuName =NULL; wndclass.lpszClassName =szAppName; if(!RegisterClass(&wndclass)) //Register a window class for the program's window { MessageBox(NULL,TEXT("This program requires Windows NT!"), szAppName,MB_ICONERROR); return 0; } 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, // inital x size CW_USEDEFAULT, //initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // window instance handle NULL // creationg parameters ); ShowWindow(hwnd,iCmdShow); //Shows the window on the screen. UpdateWindow(hwnd); //Directs the window to paint itself. while (GetMessage(&msg,NULL,0,0)) //Obtains a message from the message queue. { TranslateMessage(&msg); //Translates some keyboard messages DispatchMessage(&msg); //Sends a message to a window procedure } 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: return 0; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); //Initiates the beginning of window painting. GetClientRect(hwnd,&rect); //Obtains the dimensions of the window's client area DrawText(hdc,TEXT("hello win"),-1,&rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER); EndPaint(hwnd,&ps); //Ends window painting. return 0; case WM_DESTROY: PostQuitMessage(0); //Inserts q "quit" message into the message queue return 0; default: break; } return DefWindowProc(hwnd,message,wParam,lParam); //Performs default default processing of message }
相关文章推荐
- 关于C#WINDOWS开发-复杂控件程序
- Visual C++ 2008入门经典 第13章 使用MFC编写Windows程序
- 偶这个前端设计师有生以来写过的最复杂的程序业务逻辑(菜鸟贴)。
- windows 下写yacc程序的经典计算器例子
- 把java程序作成windows EXE程序或windows服务---经典总结
- 一个跟操作系统linux和windows差异有关的问题:通过soap的无wsdl实现php程序通信的程序(经典的吐血)
- 把java程序作成windows EXE程序或windows服务---经典总结
- VC 这个程序可能安装不正确,和***不兼容,既,和windows兼容性设置
- [C#]写个记事本作为 Windows 程序的练习,这个是雏形
- 右键TXT文件-打开方式-选择默认程序提示 windows无法访问指定设备,路经或文件.您可能没有合适的权限访问这个项目
- 在java程序中如何能获取到另一个程序的windows句柄,又如何使用这个句柄向这个窗口发送消息
- windows无法结束这个程序,要完成操作可能需要更多时间??
- C# Windows服务启动错误1083配置成在该可执行程序中运行的这个服务不能执行该服务
- (QT Windows)没有找到mingwm10.dll,因此这个程序未能启动。之解决方法...
- 在Linux中#!/usr/bin/python之后把后面的代码当成程序来执行。 但是在windows中用IDLE编程的话#后面的都是注释,之后的代码都被当成文本了。 该怎么样才能解决这个问题呢?
- MFC——1.浅谈Windows程序内部运行机制
- windows交叉编译程序在树莓派运行不了
- 被这个C程序折腾死了
- 各位高手帮我看看这个清屏程序
- windows控制台程序使用TIMER