开发者

c++ win32 output a text

im using visual studio c++ 2008 i created project that contents开发者_Go百科 the full window code. i don't know how to output text to window. i mean i have full functional window with menu bar and under the menu bar there is the body im trying to ouput the text in the body but how?


This page has a sample on how to do it in Win32:
http://www.rohitab.com/discuss/index.php?showtopic=11454

The code below is the Window Procedure for the window, if you note the WM_PAINT (That is the message that tells the window to paint itself) the code is simply drawing the text to the Device Context, which is the client area of the window.

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
        HDC hdc;
        PAINTSTRUCT ps;
        LPSTR szMessage = "darkblue 0wNz j00!";
        switch(Message) {
                case WM_PAINT:
                        hdc = BeginPaint(hwnd, &ps);
                        TextOut(hdc, 70, 50, szMessage, strlen(szMessage));
                        EndPaint(hwnd, &ps);
                        break;
                case WM_CLOSE:
                        DestroyWindow(hwnd);
                        break;
                case WM_DESTROY:
                        PostQuitMessage(0);
                        break;
                default:
                        return DefWindowProc(hwnd, Message, wParam, lParam);
        }
        return 0;
}


As an out of topic note, I suggest you to try some 3rd party library instead, as it can be much more convenient. Take a look at wxWidgets for instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜