News:

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

TextOut.

Started by G`HOST, December 08, 2005, 05:25:12 PM

Previous topic - Next topic

G`HOST

.ELSEIF uMsg==WM_PAINT
                   invoke BeginPaint,hWnd,ADDR ps
                   invoke GetWindowDC,hWnd
                   mov hdc,eax
                   invoke SetBkMode,hdc,TRANSPARENT
                   invoke SetTextColor,hdc,White
                   invokeCreateFont,18,10,0,0,700,TRUE,FALSE,FALSE,\     DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,ADDR FontName
                   invoke SelectObject,hdc,eax
                   mov hFont,eax
                   invoke TextOut,hdc,150,5,ADDR Text1,9
                   invoke TextOut,hdc,248,22,ADDR Text2,14
                   invoke SelectObject,hdc,hFont
                   invoke EndPaint,hWnd,ADDR ps

Can somebody help me out with this :
The Text disappear when the Window Loses focus,and appears back after it has gained the focus.

ramguru

The problem maybe is that you create font in WM_PAINT message (u sopposed to do it in WM_CREATE) or that you execute GetWindowDC - it's enough to use ps.hdc...btw for what reason u use this func

G`HOST

Well as far CreateFont thingi goes i never had a problem before,I may be wrong but i think thats not the problem here.Beside i am not trying to set the specified font for the whole app,just in the above code section,i did returned the actual font to dc,didnt i? :toothy
And about ps.hdc,i dont know if the dc here is for the client area or the whole window.Since i an trying to paint text in the nonclient area. :8)

ramguru

OK now I get it, but here goes onother quest(ion) why don't u use WM_NCPAINT which is dedicated to draw things in non-client area using exactly GetWindowDC

Mincho Georgiev

First, you don't need to use GetWindowDC, the HDC value for the window is returned by the BeginPaintFunction ,i.e.:

...
invoke BeginPaint,hwnd,addr ps
mov hdc,eax

...

Second, there's a several different reasons that can cause a Text Flickering. As a start ,you can check out the WINDOWCLASSEX wc.style member of your window, the style must be a 0, CS_HREDRAW and CS_VREDRAW are constants and causing repainting of the window in case of horizontal or vertical change(resize too). that repainting dont repaint the text if your PaintProc is not properly written.
I have made some chanhes in you code snippet and there's the result.
Bye for now!


[attachment deleted by admin]

G`HOST

Quote from: ramguru on December 08, 2005, 06:00:20 PM
OK now I get it, but here goes onother quest(ion) why don't u use WM_NCPAINT which is dedicated to draw things in non-client area using exactly GetWindowDC
WM_NCPAINT:An application sends the WM_NCPAINT message to a window when its frame must be painted. (Win32.hlp)

GetWindowDc:The GetWindowDC function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area.

See.[title bar, menus, and scroll bars].?Thats why.

G`HOST

Thanx shaka_zulu for your help,but i am still unsure that the dc returned by the BeginPaint call is for Client area or the whole Window.I tried it but didnt work.Well i think i will dl your modifications and see whats there.

ramguru

I'm sure dc return BeginPaint or ps.hdc is only for client area and you choose what to use BaginPaint/EndPaint or GetWindowDC or something else...

G`HOST

shaka_zulu
No man it doesnt solve the problem. the thing is,that i want to display the string on the Menu bar not in the client area and i am able to paint it there nice and clean, its that it just disappears whenever the window looses focus.

ramguru

OK this will work

.ELSEIF uMsg==WM_NCACTIVATE
invoke SetWindowPos,hWnd,0,0,0,0,0,SWP_FRAMECHANGED+SWP_NOSIZE+SWP_NOMOVE+SWP_NOZORDER+SWP_NOACTIVATE

.ELSEIF uMsg==WM_NCPAINT
                   ;invoke BeginPaint,hWnd,ADDR ps
                   invoke GetWindowDC,hWnd
                   mov hdc,eax
                   invoke SetBkMode,hdc,TRANSPARENT
                   invoke SetTextColor,hdc,White
                   invokeCreateFont,18,10,0,0,700,TRUE,FALSE,FALSE,\     DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,ADDR FontName
                   invoke SelectObject,hdc,eax
                   mov hFont,eax
                   invoke TextOut,hdc,150,5,ADDR Text1,9
                   invoke TextOut,hdc,248,22,ADDR Text2,14
                   invoke SelectObject,hdc,hFont
                   ;invoke EndPaint,hWnd,ADDR ps

Mincho Georgiev

Yes, GetWindowDC returns the DC for the entire window,but i didn't understand why you need that for TextOut

Mincho Georgiev

ok, i didn't saw your previous post

G`HOST

But the question still remains,Why the window behaving the way it is?

Mincho Georgiev

There it is, you dont need to paint the whole window to do that. you just need to paint the text every time when receiving
WM_SETFOCUS and WM_KILLFOCUS messages:


[attachment deleted by admin]

PBrennick

shaka_zulu,
That is an excellent example.  It works well on my XP machine except I had to fudge the x,y coordinates a bit, well the 'y' coordinate, actually.


invoke TextOut,hdc,50,33,addr String1,sizeof String1-1


No doubt it is because of my resolution settings.  Anyway, this method is very useful.  Thank you.

Paul
The GeneSys Project is available from:
The Repository or My crappy website