⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testapp.cpp

📁 这是一本学习 window编程的很好的参考教材
💻 CPP
字号:
#include <windows.h>

HWND     g_hWnd;
HMODULE  hHookLib = NULL;


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(
	HINSTANCE hInstance, 
	HINSTANCE hPrevInstance,
    LPSTR     lpszCmdLine, 
	int       nCmdShow
	)
{
    HWND     hwnd;
    MSG      msg ;
    WNDCLASS wndclass ;

	if(!hPrevInstance) 
	{
		wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
		wndclass.lpfnWndProc   = WndProc ;
		wndclass.cbClsExtra    = 0 ;
		wndclass.cbWndExtra    = 0 ;
		wndclass.hInstance     = hInstance ;
		wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION) ;
		wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
		wndclass.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH) ;
		wndclass.lpszMenuName  = NULL;
		wndclass.lpszClassName = "DemoClass" ;
		RegisterClass(&wndclass) ;
	}

	hwnd = ::CreateWindow(
		"DemoClass",			// LPCTSTR lpClassName
		"Test Application",		// LPCTSTR lpWindowName
   		WS_OVERLAPPEDWINDOW,	// DWORD dwStyle
		CW_USEDEFAULT,			// int x
		0,						// int y 
		CW_USEDEFAULT,			// int nWidth
		0,						// int nHeight
		NULL,					// HWND hWndParent
		NULL,					// HMENU hMenu
		hInstance,				// HANDLE hInstance
		NULL                    // PVOID lpParam 
		);				
	g_hWnd = hwnd;
	
	::ShowWindow(hwnd, nCmdShow) ;
	::UpdateWindow(hwnd) ;

	while(::GetMessage(&msg, NULL, 0, 0))
	{
		::TranslateMessage(&msg) ;
		::DispatchMessage(&msg) ;
	}
	
	return msg.wParam ;
}

LRESULT CALLBACK WndProc(
	HWND   hwnd, 
	UINT   message, 
	WPARAM wParam, 
	LPARAM lParam
	)
{
	static char    pszLine0[80] = "Hello from TestApp!";
	static wchar_t pszLine1[80] = L"Hello from TestApp!";
    HDC hDC;                               
    PAINTSTRUCT ps;
	
	switch(message)
    {
    case WM_PAINT:
        hDC = ::BeginPaint(hwnd, &ps);
		::TextOutA(hDC, 0, 0, pszLine0, lstrlen(pszLine0));
		::TextOutW(hDC, 0, 20, pszLine1, wcslen(pszLine1));
        ::EndPaint(hwnd, &ps);
		return 0;
    case WM_DESTROY :
        ::PostQuitMessage(0) ;
		return 0;
    default:
        break;
    }
    return DefWindowProc(hwnd, message, wParam, lParam) ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -