My first Windows App

#include <Windows.h>
#include <stdio.h>
LRESULT CALLBACK MyWindowProc(
							HWND hwnd,
							UINT uMsg,
							WPARAM wParam,
							LPARAM lParam
							);

int WINAPI WinMain(  HINSTANCE hInstance,  HINSTANCE hPrevInstance, LPSTR lpCmdLine,  int nShowCmd )
{
	HWND hwnd;
	WNDCLASS wndclass;
	MSG msg;
	 static TCHAR MyAppName[]=TEXT("My first windows app");
	wndclass.style=CS_HREDRAW|CS_VREDRAW;
	wndclass.lpfnWndProc=MyWindowProc;
	wndclass.cbClsExtra=0;//预留的额外空间
	wndclass.cbWndExtra=0;
	wndclass.hInstance=hInstance;
	wndclass.hIcon=::LoadIcon(NULL,IDI_INFORMATION);
	wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);
	wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName=NULL;
	wndclass.lpszClassName=MyAppName;
	if (!RegisterClass(&wndclass))
	{
		int i=GetLastError();
		//char str[25]={0};
		wchar_t chResult[128]={0};
		_itow(i,chResult,10);
		//sprintf(str,TEXT("%d"),i);
		MessageBox(NULL,chResult,TEXT("Error"),MB_OK);
	}
	hwnd=CreateWindow( MyAppName,
		               TEXT("My first windows"),
					   WS_OVERLAPPEDWINDOW,
					   CW_USEDEFAULT ,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   NULL,NULL,
					   hInstance,
					   NULL
		                 );
	ShowWindow(hwnd,nShowCmd); 
	//ShowWindow(hwnd,iCmdShow);
	UpdateWindow(hwnd);
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}
LRESULT CALLBACK MyWindowProc(
							  HWND hwnd,
							  UINT uMsg,
							  WPARAM wParam,
							  LPARAM lParam
							  )
{
	HDC hdc;
	PAINTSTRUCT ps;
	switch(uMsg)
	{
	case WM_CREATE:
		MessageBox(NULL,TEXT("Create"),TEXT("Create"),MB_OK);
		return 0;
	case WM_PAINT:
		hdc=BeginPaint(hwnd,&ps);
		TextOut(hdc,0,0,TEXT("hello world"),11);
		EndPaint(hwnd,&ps);
		return 0;

	}


	return DefWindowProc(hwnd,uMsg,wParam,lParam);

}

  

posted on 2013-05-29 01:21  奔跑吧,蜗牛!  阅读(174)  评论(0)    收藏  举报

导航