Welcome to Hackers Alliance!

Win32 Printing Text Example

  • Archived

    The forum is archived and used for testing. It is currently read-only to visitors.
    It has been upgraded from vBulletin 3.8.x to XenForo for security purposes and future-proofing. Proprietary code and modifications (such as code database and HA bot) are broken with XenForo and will stay only with vBulletin.

-LeetGamer-

Coder
Coder
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;
}
If you have any questions let me know.
 
Last edited:
This site has been archived and is no longer accepting new content.

About us

  • Hackers Alliance is a small community forum about gaming and console hacking. Join our humble community to share ideas, game cheats, mods, and be part of an amazing growing community!

Quick Navigation

User Menu