窗口测试

#include "stdafx.h"
#include "Tools.h"
#include<Windows.h>

LRESULT CALLBACK WindowProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
	switch(uMsg){
	case WM_DESTROY:
		{
			DbgPrintf("WM_DESTROY %d %d \n",wParam,lParam);
			PostQuitMessage(0);
			return 0;
		}
	case WM_KEYUP:
		{
			DbgPrintf("WM_KEYUP: %d %d \n",wParam,lParam);
			return 0;
		}
	case WM_KEYDOWN:
		{
			DbgPrintf("WM_KEYUP: %d %d \n",wParam,lParam);
			return 0;
		}
	}


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


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	
	//窗口类名
	TCHAR className[] = "1111";
	
	//创建窗口类的对象
	WNDCLASS wndclass={0};
	wndclass.hbrBackground = (HBRUSH)COLOR_MENU;
	wndclass.lpfnWndProc = WindowProc;
	wndclass.lpszClassName = className;
	wndclass.hInstance = hInstance;
	
	//注册窗口类
	RegisterClass(&wndclass);
	
	
	//创建窗口
	HWND hwnd = CreateWindow(
		  className,  // registered class name
		  TEXT("www.gyarmy.com"), // window name
		  WS_OVERLAPPEDWINDOW,        // window style
		  10,                // horizontal position of window
		  10,                // vertical position of window
		  600,           // window width
		  400,          // window height
		  NULL,      // handle to parent or owner window
		  NULL,          // menu handle or child identifier
		  hInstance,  // handle to application instance
		  NULL       // window-creation data
	);

	if(hwnd ==  NULL)
		return 0;
	
	//显示窗口
	ShowWindow(hwnd,SW_SHOW);

	//消息循环
	MSG msg;
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	int a = GetLastError();
	
	return 0;
}

原文链接: 窗口测试 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( http://gyarmy.com/post-327.html )

发表评论

0则评论给“窗口测试”