- Oct 17, 2010
- 66
- 2
- 0
Code:
// How to print text in Win32 C/C++
// Auther: -LeetGamer-
#include <Windows.h>
HINSTANCE hInstance;
int GetTextSize (LPSTR a0)
{
for (int iLoopCounter = 0; ;iLoopCounter++)
{
if (a0 [iLoopCounter] == '\0')
return iLoopCounter;
}
}
LPSTR TextArray [] = {
"Hello World"
};
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow (hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint (hwnd, &ps);
TextOut (hdc,
10,
10,
TextArray [0],
GetTextSize (TextArray [0]));
EndPaint (hwnd, &ps);
}
break;
}
return DefWindowProc (hwnd, msg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstanace, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WindowClass;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.cbSize = sizeof (WNDCLASSEX);
WindowClass.lpszClassName = "1";
WindowClass.lpszMenuName = NULL;
WindowClass.lpfnWndProc = WndProc;
WindowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
WindowClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
WindowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WindowClass.style = 0;
WindowClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
RegisterClassEx (&WindowClass);
HWND hwnd = CreateWindowEx (WS_EX_CLIENTEDGE,
"1",
"Printing Text in Win32 C/C++",
WS_OVERLAPPEDWINDOW,
315, 115,
640, 480,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, SW_SHOWNORMAL);
MSG msg;
while (GetMessage (&msg, NULL, 0, 0) > 0)
{
TranslateMessage (&msg);
DispatchMessage (&msg);
if (VK_ESCAPE == msg.wParam)
break;
}
return 0;
}
Last edited: