VC win32 Application SDK创建窗口Demo

win32.h

#ifndef _X_WIN32_H_ #define _X_WIN32_H_ BOOL InitApplication(HINSTANCE); BOOL InitInstance(HINSTANCE,int); LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); #endif 

win32.cpp

#include <windows.h> #include "win32.h" HINSTANCE g_hInst; HWND g_hWnd; char g_szAppName[]="WIN32Sample"; char g_szTitle[]="Win32 Sample Application"; int CALLBACK WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd ) { MSG msg; UNREFERENCED_PARAMETER(lpCmdLine);//to avoid compile warnning if(!hPrevInstance) { if (!InitApplication(hInstance)) { return FALSE; } } if(!InitInstance(hInstance,nShowCmd)) { return FALSE; } while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;//PostQuitMessage's wParam } BOOL InitApplication( HINSTANCE hInstance ) { WNDCLASS wc; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);; wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=hInstance; wc.lpfnWndProc=(WNDPROC)WndProc; wc.lpszClassName=g_szAppName; wc.lpszMenuName=NULL; wc.style=0; return RegisterClass(&wc); } BOOL InitInstance( HINSTANCE hInstance,int nShowCmd) { g_hInst=hInstance; g_hWnd= CreateWindow(g_szAppName, g_szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if(!g_hWnd) { return FALSE; } ShowWindow(g_hWnd,nShowCmd);//show window UpdateWindow(g_hWnd);//send WM_PAINT to msgQue return TRUE; } LRESULT CALLBACK WndProc( HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { switch(message) { case WM_DESTROY: PostQuitMessage(0);//wnd destoryed,application will quit soon break; default: return DefWindowProc(hwnd,message,wParam,lParam);//pass to default wndproc } return 0; } 

 

自定义鼠标、图标、菜单

参考:http://blog.csdn.net/iamoyjj/archive/2011/06/06/6528218.aspx

 

 

附:CreateWindowEx函数的流程

VC win32 Application SDK创建窗口Demo_第1张图片

更多请参考:

http://www.ibm.com/developerworks/cn/linux/l-cn-guimigrt/index4.html?ca=drs-cn#N1019A

你可能感兴趣的:(null,application,callback)