The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: G`HOST on October 25, 2005, 12:02:15 PM

Title: Problem in "DrawText"
Post by: G`HOST on October 25, 2005, 12:02:15 PM
 
           
Quote.ELSEIF uMsg==WM_CREATE
                   invoke CreateWindowEx,NULL,ADDR ButtonClass,NULL,\
                                         WS_CHILD or WS_VISIBLE or BS_PUSHBUTTON or BS_CENTER or BS_VCENTER,\
                                         275,10,80,25,hWnd,NULL,hInstance,NULL
                                         mov hwndButton,eax           
                   invoke GetDC,hwndButton
                    mov hdc,eax
                   invoke GetClientRect,hwndButton1,ADDR rect
                   invoke SetTextColor,hdc,0FF0008h
                   invoke DrawText,hdc,ADDR Button1Text,-1,ADDR rect,DT_CENTER or DT_VCENTER or DT_SINGLELINE
      
                   invoke ReleaseDC,hWnd,hdc



Why am i not getting the desired result ? (The color of the text on button does not change)
if i leave the "LPCTSTR lpWindowName" to NULL in CreateWindowEx then there is no text on the button.
Title: Re: Problem in "DrawText"
Post by: hitchhikr on October 25, 2005, 12:37:51 PM
Use WM_CTLCOLORBTN together with an owner drawn button instead.
Title: Re: Problem in "DrawText"
Post by: Manos on October 25, 2005, 01:02:52 PM
The problem is not in DrawText but in WM_CREATE.
The WM_CREATE happen before the window appears on the screen.
Therefor the text does not appears in the above message.
You must use DrawText in WM_PAINT,that is,when the window
appears on the screen already.

Manos.
Title: Re: Problem in "DrawText"
Post by: G`HOST on October 28, 2005, 11:50:06 AM
Yup i got you .You are right about WM_CREATE .I tried WM_PAINT and WM_CTLCOLORBTN but none worked. i think i have to learn more :toothy anyway thanks for the help.
Title: Re: Problem in "DrawText"
Post by: Manos on October 28, 2005, 02:44:01 PM
You have to handle the WM_PAINT of Button,not of parent window.
Therefor a way is to subclass the Button window.

Manos.
Title: Re: Problem in "DrawText"
Post by: remus2k on January 06, 2011, 05:46:52 PM
Hello

I have a Problem with my DrawText function

Use LogFont:
LogFont    LOGFONT   <19,12,0,0,FW_NORMAL,0,0,0,OEM_CHARSET,0,0,0,0,"Courier New">

And here my DrawText Function:

invoke   SelectObject,hDC,pFont
invoke   SetTextColor,hDC,0A600h
invoke   SetBkColor,hDC,0
invoke   DrawText,hDC,offset szString,2,addr Rect,DT_BOTTOM

and a little Rect Calculation

Now the Problem is that not correct Draw my Text Char

(http://i53.tinypic.com/2v84jly.jpg)

Can you tell me what is wrong must i set the correct LogFont?
Title: Re: Problem in "DrawText"
Post by: donkey on January 06, 2011, 05:54:42 PM
Hi G`HOST,

I will make a list of the problems and misconceptions.

1) The WM_CREATE is fine, but you cannot draw the button from there, it is in the parent's wndproc, anything you draw will be overwritten.

2) Using the WM_PAINT in the parent's wndproc has the same problem as above.

3) Don't try to process the WM_PAINT of a button, it is a combination of multiple windows that are displayed dependent on the button state.

4) if you do try to paint the button, you will also need to use DrawFrameControl as well as a few other specialized drawing routines.

5) The owner drawn button is your best solution, it allows you to draw your button face without worrying about the 5 or 6 other drawing requirements.

6) If you do decide to process WM_PAINT you have to subclass the button, you can't do it from the parent wndproc.

Edgar
Title: Re: Problem in "DrawText"
Post by: donkey on January 06, 2011, 05:58:37 PM
Quote from: remus2k on January 06, 2011, 05:46:52 PM
Hello

I have a Problem with my DrawText function

Use LogFont:
LogFont    LOGFONT   <19,12,0,0,FW_NORMAL,0,0,0,OEM_CHARSET,0,0,0,0,"Courier New">

And here my DrawText Function:

invoke   SelectObject,hDC,pFont
invoke   SetTextColor,hDC,0A600h
invoke   SetBkColor,hDC,0
invoke   DrawText,hDC,offset szString,2,addr Rect,DT_BOTTOM

and a little Rect Calculation

Now the Problem is that not correct Draw my Text Char

(http://i53.tinypic.com/2v84jly.jpg)

Can you tell me what is wrong must i set the correct LogFont?

You have to create the font and use it's handle in SelectObject. Also you should make sure that you select it out when you're done.

invoke CreateFontIndirect, offset LogFont
mov hFont, eax
...
invoke   SelectObject,hDC,hFont
mov hOldFont, eax

...

invoke   SelectObject,hDC,hOldFont
Title: Re: Problem in "DrawText"
Post by: dedndave on January 06, 2011, 06:13:14 PM
also - make sure that the font you are selecting supports the charset you are requesting
i don't think "Courier New" supports OEM_CHARSET
find out which fonts support the charset you want to use, then pick from that list
i use the "Termnal" font - but there may be others
Title: Re: Problem in "DrawText"
Post by: remus2k on January 06, 2011, 06:58:56 PM
I think it is a rect calculations probelm from my scroller
Use i without a scroller Draw this text correct with this font Settings
Title: Re: Problem in "DrawText"
Post by: dedndave on January 06, 2011, 08:32:28 PM
yes - scrolling is a bit tricky to learn for n00bs like me because there are so many different ways to do it
without knowing about it, you have to pick a method - lol
i am looking at examples that use ScrollWindow
i think for text, it is the best way (a simpler way is to redraw the whole screen)
search the forum (and google) for "ScrollWindow"

there are more advanced techniques - but i think they might be a little complicated for text
Tedd, Manos, and others have posted some good example code
Title: Re: Problem in "DrawText"
Post by: remus2k on January 06, 2011, 08:59:15 PM
No my scroller works fine only not with this Font?
and scroll a window is a not good solution