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://www.ibm.com/developerworks/cn/linux/l-cn-guimigrt/index4.html?ca=drs-cn#N1019A

转载于:https://www.cnblogs.com/oyjj/archive/2011/06/06/2132860.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值