News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problem in "DrawText"

Started by G`HOST, October 25, 2005, 12:02:15 PM

Previous topic - Next topic

G`HOST

 
           
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.

hitchhikr

Use WM_CTLCOLORBTN together with an owner drawn button instead.

Manos

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.

G`HOST

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.

Manos

You have to handle the WM_PAINT of Button,not of parent window.
Therefor a way is to subclass the Button window.

Manos.

remus2k

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



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

donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

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



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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dedndave

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

remus2k

I think it is a rect calculations probelm from my scroller
Use i without a scroller Draw this text correct with this font Settings

dedndave

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

remus2k

No my scroller works fine only not with this Font?
and scroll a window is a not good solution