70,036
社区成员
发帖
与我相关
我的任务
分享#include <windows.h>
long FAR PASCAL MainWndProc(HWND , unsigned, WORD, LONG);
HWND hWnd;
HBRUSH hBrush;
int PASCAL WinMain(HANDLE hInstance, HANDLE hPreInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Message;
if(!hPreInstance)
if(!initApplication(hPreInstance))
return FALSE;
if(!initInstance(hInstance, nCmdShow))
return FALSE;
while(GetMessage(&Message, NULL, NULL, NULL))
{
TranslateMessage(&Message);
DispatchMessageA(&Message);
}
return (Message.wParam);
}
BOOL initApplication(HANDLE hInstance)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW; //| CS_VERDRAW;
WndClass.lpfnWndProc = MainWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = "Simple App";
return RegisterClass(&WndClass);
}
BOOL initInstance(HANDLE hInstance, int nCmdShow)
{
hWnd = CreateWindow(
"Simple App",
"Simple Application",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
HDC hDC;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
hBrush = CreateSolidBrush(RGB(255, 100, 0));
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
SelectObject(hDC, hBrush);
Rectangle(hDC, 10, 20, 160, 180);
TextOut(hDC, 30, 50, "Hello World", 13);
EndPaint(hWnd, &ps);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
DeleteObject(hBrush);
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}
BOOL initApplication(HANDLE hInstance);
BOOL initInstance(HANDLE hInstance, int nCmdShow);
long FAR PASCAL MainWndProc(HWND , unsigned, WORD, LONG);