Unable to draw text :: no mfc - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Unable to draw text :: no mfc

im having a problem using DrawText right after I create and show a window. What is going on here because when I post the drawtext stuff where the system calls WM_PAINT then everything goes fine what is going on is the text getting written over or what? Here is the code im using...

// ......... stuff before this

// show and update the window
ShowWindow(g_hWnd, nCmdShow);
UpdateWindow(g_hWnd);

RECT rect;
PAINTSTRUCT ps;
HDC hDC;

hDC = BeginPaint(g_hWnd, &ps);
GetClientRect(g_hWnd, &rect);

SetBkMode(hDC, TRANSPARENT);
SetTextColor(hDC, RGB(255, 0, 0));

DrawText(hDC, "Hello World!", -1, &rect, DT_LEFT);
EndPaint(g_hWnd, &ps);

// stuff after this....

Can anyone help me???
Thanks for anything ahead of time

Comments

  • Johnny13Johnny13 Posts: 128Member
    your code looks OK,so whats the problem?
    just make sure the ShowWindow/UpdateWindow is in WinMain(),not WinProc()
    you can also use TextOut() instead of DrawText(),check teh API;-)
  • veliusvelius Posts: 456Member
    Did you call InvalidateRect()? Also the code only seemed to work in the WndProc procedure for a WM_PAINT request. Even calling InvalidateRect() would not work without handling the WM_PAINT message.
    [hr]
    When it came down to it I dropped everything and ran.
    -Ramza Final Fantasy Tactics

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : im having a problem using DrawText right after I create and show a window. What is going on here because when I post the drawtext stuff where the system calls WM_PAINT then everything goes fine what is going on is the text getting written over or what? Here is the code im using...
    :
    : // ......... stuff before this
    : [code]
    : // show and update the window
    : ShowWindow(g_hWnd, nCmdShow);
    : UpdateWindow(g_hWnd);
    : [/code]
    [blue]This ^^^ supposed to be in WinMain()[/blue]

    [blue]And that (below) supposed to be inside [b]case WM_PAINT:[/b] in your WndProc for [b]g_hWnd[/b][/blue]
    [code]
    : RECT rect;
    : PAINTSTRUCT ps;
    : HDC hDC;
    :
    : hDC = BeginPaint(g_hWnd, &ps);
    : GetClientRect(g_hWnd, &rect);
    :
    : SetBkMode(hDC, TRANSPARENT);
    : SetTextColor(hDC, RGB(255, 0, 0));
    :
    : DrawText(hDC, "Hello World!", -1, &rect, DT_LEFT);
    : EndPaint(g_hWnd, &ps);
    [/code]
    :
    : // stuff after this....
    :
    : Can anyone help me???
    : Thanks for anything ahead of time
    :

  • ASCHUNKASCHUNK Posts: 19Member
    Hi,

    i guess the SetBKMode function causes your problem. If you choose TRANSPARENT, then white rectangle behind the text will be hidden. As i conclude from your code you want to have a black text with left alignment and a white background. Usually, all Windows applications have a white background and the text color is usually black. May be you can skip the SetBkMode call and use the standard settings instead. The other lines seem to be ok.
    Regards.
    Alex

    : im having a problem using DrawText right after I create and show a window. What is going on here because when I post the drawtext stuff where the system calls WM_PAINT then everything goes fine what is going on is the text getting written over or what? Here is the code im using...
    :
    : // ......... stuff before this
    :
    : // show and update the window
    : ShowWindow(g_hWnd, nCmdShow);
    : UpdateWindow(g_hWnd);
    :
    : RECT rect;
    : PAINTSTRUCT ps;
    : HDC hDC;
    :
    : hDC = BeginPaint(g_hWnd, &ps);
    : GetClientRect(g_hWnd, &rect);
    :
    : SetBkMode(hDC, TRANSPARENT);
    : SetTextColor(hDC, RGB(255, 0, 0));
    :
    : DrawText(hDC, "Hello World!", -1, &rect, DT_LEFT);
    : EndPaint(g_hWnd, &ps);
    :
    : // stuff after this....
    :
    : Can anyone help me???
    : Thanks for anything ahead of time
    :

Sign In or Register to comment.