关闭

win32程序

421人阅读 评论(0) 收藏 举报
#include <windows.h>
#include <stdio.h>
#include <tchar.h>

LRESULT CALLBACK WinYisProc(HWND hwnd,
							UINT uMsg,
							WPARAM wParam,
							LPARAM lParam);
int WINAPI WinMain
	(
	HINSTANCE hInstance,
	 HINSTANCE hPrevInstance,
	 LPSTR lpCmdLine,
	 int nCmdShow
	 )
{
	WNDCLASS wndcls;
	wndcls.cbClsExtra=0;
	wndcls.cbWndExtra=0;
	wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
	wndcls.hIcon=LoadIcon(NULL,(LPCWSTR)IDI_ERROR);
wndcls.hInstance = hInstance;
	wndcls.lpfnWndProc=WinYisProc;
	wndcls.lpszClassName=_T("h");
	wndcls.lpszMenuName=NULL;
	wndcls.style=CS_HREDRAW | CS_VREDRAW;
	RegisterClass(&wndcls);
	 
	HWND hwnd;
	hwnd=CreateWindow(_T("h"),_T("tjjjj"),WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);

	ShowWindow(hwnd,SW_SHOWNORMAL);
	UpdateWindow(hwnd);

	MSG msg;
	while( GetMessage(&msg,hwnd,0,0) )
	{
	
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return 0;
}
LRESULT CALLBACK WinYisProc(
						   HWND hwnd,
						   UINT uMsg,
						   WPARAM wParam,
						   LPARAM lParam
						   )
{
	switch( uMsg )
	{
	case WM_CHAR:
		char szChar[20];
		sprintf(szChar,"char is %d",wParam);
		MessageBox(hwnd,(LPCWSTR)szChar,_T("yis"),0);
		break;
	case WM_LBUTTONDOWN:
		MessageBox(hwnd, _T("mouse clicked"), _T("message"), 0);
		HDC hdc;
		hdc = GetDC(hwnd);
		TextOut(hdc, 0, 50, _T("我是个快乐的青年"), strlen("我是个快乐的青年"));
		break;
	case WM_PAINT:
		HDC hDC;
		PAINTSTRUCT ps;
		hDC=BeginPaint(hwnd,&ps);
		TextOut(hDC,0,0,_T("yisyisyis"),strlen("yisyisyis"));
		EndPaint(hwnd,&ps);
		break;
	case WM_CLOSE:
		if(IDYES==MessageBox(hwnd,(LPCWSTR)"是否真的结束?",(LPCWSTR)"yis",MB_YESNO))
		{
			DestroyWindow(hwnd);
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd,uMsg,wParam,lParam);
	}
	return 0;


}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8812次
    • 积分:205
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:11篇
    • 译文:0篇
    • 评论:0条