分类: C/C++
2008-08-04 09:36:42
#include还有,我们应该学会使用msdn快速查找到我们所需要的信息。#include
LRESULT CALLBACK WinMYProc( HWND hWnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );接下来是WinMain
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state ) { WNDCLASS wndcls;//注册窗口类 wndcls.cbClsExtra=0; wndcls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//窗口画刷 wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);//鼠标 wndcls.hIcon=LoadIcon(NULL,IDI_WINLOGO);//图标 wndcls.hInstance=hInstance;//窗口实例 wndcls.lpfnWndProc=WinMYProc;//窗口函数 wndcls.lpszClassName="BEYOND";//窗口类名 wndcls.lpszMenuName=NULL;//菜单名(这里为空) wndcls.style=CS_HREDRAW | CS_VREDRAW;//窗口风格(水平重绘和垂直重绘) RegisterClass(&wndcls);//注册窗口 //注册完窗口,接着是创建和显示窗口了 HWND hWnd; hWnd=CreateWindow("BEYOND",lovebeyond",WS_OVERLAPPEDWINDOW, 0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);//显示 UpdateWindow(hWnd);//更新 //接下来是消息循环了 MSG msg; while(GetMessage(&msg,NULL,0,0))//当不为WM_QUIT时,继续消息循环 { TranslateMessage(&msg);//用于翻译消息 DispatchMessage(&msg);//发送消息 } return msg.wParam;//返回一个参数 } //消息响应函数 LRESULT CALLBACK WinMYProc( HWND hWnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { switch(uMsg) { case WM_CHAR://键盘消息 char szChar[20]; sprintf(szChar,"char is %d",wParam); MessageBox(hWnd,szChar,"char",0); break; case WM_LBUTTONDOWN://鼠标左键按下 MessageBox(hWnd,"mouse clicked","message",0); break; case WM_PAINT://窗口重绘消息 HDC hDC; PAINTSTRUCT ps; hDC=BeginPaint(hWnd,&ps); TextOut(hDC,0,0,"lovebeyond",strlen("lovebeyond")); EndPaint(hwnd,&ps); break; case WM_CLOSE://关闭消息 if(IDYES==MessageBox(hWnd,"想要结束吗?","message",MB_YESNO)) { DestroyWindow(hWnd); } break; case WM_DESTROY://销毁窗口消息 PostQuitMessage(0); break; default://默认窗口消息处理 return DefWindowProc(hWnd,uMsg,wParam,lParam); } return 0; }到此,所有程序结束,读者也可以试着自己写一个类似的程序,加入更多的响应功能。这里就到此结束。希望对大家了解windows程序有所帮助。谢谢阅读。