1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE, PTSTR pszCmd, INT iSc)
{
MSG msg;
HWND hWnd;
WNDCLASSEX wnd;
wnd.cbSize = sizeof(wnd);
wnd.cbClsExtra = NULL;
wnd.cbWndExtra = NULL;
wnd.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wnd.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wnd.hInstance = hInst;
wnd.lpfnWndProc = WndProc;
wnd.lpszClassName = _T("My_class_name");
wnd.lpszMenuName = NULL;
wnd.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClassEx(&wnd))
{
// Error ...
// MessageBox(NULL, _T("ERROR #1"), _T("Error"), MB_ICONSTOP | MB_OK);
return FALSE;
}
hWnd = CreateWindowEx(NULL, _T("My_class_name"), _T("WinAPI Programme"), WS_OVERLAPPEDWINDOW, 200, 200, 500, 300, 0, 0, hInst, 0);
if(!hWnd)
{
// Error ...
// MessageBox(NULL, _T("ERROR #2"), _T("Error"), MB_ICONSTOP | MB_OK);
return FALSE;
}
ShowWindow(hWnd, iSc);
while(GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
static RECT rect;
switch(uMsg)
{
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
DrawText(hDC, _T("Hello Win32 world ! :)"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hWnd, &ps);
break;
case WM_SIZE:
GetClientRect(hWnd, &rect);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(NULL);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return FALSE;
}
|