// 2Window_Timer.cpp : 定义应用程序的入口点。
//
#include <windows.h>
#include <iostream>
#include "resource1.h"
//宏定义输出函数
#define PrintLog(x) WriteConsole(g_hStdout, x, strlen(x), NULL, NULL);
HINSTANCE g_hInst;
HANDLE g_hStdout = NULL;
CHAR szText[256] = { 0 };
void OnCommand(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
int hMenuID = LOWORD(wParam);
switch (hMenuID)
{
case ID_EXIT:
PostQuitMessage(0);
break;
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
switch (nMsg)
{
case WM_COMMAND:
OnCommand(hWnd, nMsg, wParam, lParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, nMsg, wParam, lParam);
}
BOOL RegisterWnd(LPSTR pszClassName)
{
WNDCLASSEX wce = { 0 };
wce.cbSize = sizeof(wce);
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hbrBackground = HBRUSH(COLOR_BTNFACE + 1);
wce.hCursor = NULL;
wce.hIcon = NULL;
wce.hIconSm = NULL;
wce.hInstance = g_hInst;
wce.lpfnWndProc = WndProc;
wce.lpszClassName = pszClassName;
wce.lpszMenuName = NULL;
wce.style = CS_VREDRAW | CS_HREDRAW;
ATOM aTom = RegisterClassEx(&wce);
if (aTom == 0)
{
return FALSE;
}
else
{
return TRUE;
}
}
HWND CreateWnd(LPSTR pszClassName)
{
//加入菜单
HMENU hMainMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MAIN));
HWND hWnd = CreateWindowEx(0, pszClassName, "风火中原", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMainMenu, g_hInst, NULL);
return hWnd;
}
void showWnd(HWND hWnd)
{
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
}
void msg()
{
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
//控制台
void ConsoleWnd()
{
AllocConsole();
g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
CHAR szText[] = "Debug start:\n";
PrintLog(szText);
}
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
g_hInst = hInstance;
ConsoleWnd();
RegisterWnd("OOOO");
HWND hWnd = CreateWnd("OOOO");
showWnd(hWnd);
msg();
return 0;
}
时间: 2024-10-28 11:29:44