Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Unable to draw text :: no mfc Posted by volume on 20 Sept 2003 at 10:14 PM
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
Report
Re: Unable to draw text :: no mfc Posted by Johnny13 on 21 Sept 2003 at 3:25 AM
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
Report
Re: Unable to draw text :: no mfc Posted by velius on 22 Sept 2003 at 7:02 AM
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.


When it came down to it I dropped everything and ran.
-Ramza Final Fantasy Tactics

Report
Re: Unable to draw text :: no mfc Posted by AsmGuru62 on 22 Sept 2003 at 7:19 AM
: 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);
: 

This ^^^ supposed to be in WinMain()

And that (below) supposed to be inside case WM_PAINT: in your WndProc for 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
:

Report
Re: Unable to draw text :: no mfc Posted by ASCHUNK on 22 Sept 2003 at 9:44 AM
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
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.