win32_First day

今天正式开始了win32 SDK非模态化的编程,不使用资源添加来写窗口,算是一次新的修炼吧,即使学的有些晚,但是想要更加详细的了解windows各种消息机制还得从最基本的API了解,这对以后无论是何种编程,对MFC的封装使用都会有更大的帮助,下面是一个非模态的窗口建立。

#include "windows.h"


HINSTANCE g_Instance;


LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wapram,LPARAM lparam)
{
	switch(uMsg)
	{
	case WM_DESTROY:{
						PostQuitMessage(0);
					}break;
	}

	return DefWindowProc(hwnd,uMsg,wapram,lparam);
}

BOOL CALLBACK Registe(LPCTSTR pszName)
{
	WNDCLASSEX wce;

	wce.cbSize				=	sizeof(wce);
	wce.style				=	CS_HREDRAW|CS_VREDRAW;
	wce.cbClsExtra			=	0;
	wce.cbWndExtra			=	0;
	wce.hCursor				=	NULL;
	wce.hIcon				=	NULL;
	wce.hbrBackground		=	HBRUSH (COLOR_BTNFACE	+	1);
	wce.hIconSm				=	NULL;
	wce.hInstance			=	g_Instance;
	wce.lpfnWndProc			=	WndProc;
	wce.lpszClassName		=	pszName;
	wce.lpszMenuName		=	NULL;

	ATOM nAtom	=	 RegisterClassEx(&wce);
	if (nAtom	==	0)
	{
		return FALSE;
	}

	return TRUE;

	
}

HWND CALLBACK CreateWnd(LPCTSTR pszName)
{
	HWND hwnd	=	 CreateWindow(pszName,L"MyWnd",WS_OVERLAPPEDWINDOW,0,0,400,500,NULL,NULL,g_Instance,NULL);

	if (hwnd	==	NULL)
	{
		return NULL;
	}

	ShowWindow(hwnd,SW_SHOW);
	UpdateWindow(hwnd);

	

	return hwnd;
}


void MessageInfo(HWND hwnd)
{
	MSG msg	=	{0};
	while(GetMessage(&msg,hwnd,NULL,NULL))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
	g_Instance	=	hInstance;

	Registe(L"EDIT");
	HWND hwnd	=	 CreateWnd(L"EDIT");
	MessageInfo(hwnd);


	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值