The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: G`HOST on December 08, 2005, 05:25:12 PM

Title: TextOut.
Post by: G`HOST on December 08, 2005, 05:25:12 PM
.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.
Title: Re: TextOut.
Post by: ramguru on December 08, 2005, 05:42:43 PM
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
Title: Re: TextOut.
Post by: G`HOST on December 08, 2005, 05:54:43 PM
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)
Title: Re: TextOut.
Post by: 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
Title: Re: TextOut.
Post by: Mincho Georgiev on December 08, 2005, 06:02:34 PM
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]
Title: Re: TextOut.
Post by: G`HOST on December 08, 2005, 06:04:14 PM
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.
Title: Re: TextOut.
Post by: G`HOST on December 08, 2005, 06:12:00 PM
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.
Title: Re: TextOut.
Post by: ramguru on December 08, 2005, 06:15:49 PM
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...
Title: Re: TextOut.
Post by: G`HOST on December 08, 2005, 06:21:03 PM
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.
Title: Re: TextOut.
Post by: ramguru on December 08, 2005, 06:23:47 PM
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
Title: Re: TextOut.
Post by: Mincho Georgiev on December 08, 2005, 06:25:10 PM
Yes, GetWindowDC returns the DC for the entire window,but i didn't understand why you need that for TextOut
Title: Re: TextOut.
Post by: Mincho Georgiev on December 08, 2005, 06:27:44 PM
ok, i didn't saw your previous post
Title: Re: TextOut.
Post by: G`HOST on December 08, 2005, 06:47:13 PM
But the question still remains,Why the window behaving the way it is?
Title: Re: TextOut.
Post by: Mincho Georgiev on December 08, 2005, 07:20:54 PM
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]
Title: Re: TextOut.
Post by: PBrennick on December 08, 2005, 09:10:14 PM
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
Title: Re: TextOut.
Post by: Mincho Georgiev on December 08, 2005, 09:40:34 PM
You're wellcome Paul . I didn't thought about the resolution, i've made it on 1152x864, but universal resolution example can be easily implemented using GetSystemMetrics.
Bye for now  :U
Title: Re: TextOut.
Post by: shuttlebug on December 09, 2005, 03:32:13 AM
    invoke GetDC,hWnd
    mov    hDc,eax

    invoke CreateFont,blah,blah
    mov    hFont,eax
    invoke SelectObject,hDc,hFont
 
    invoke TextOut,hDc,blah,blah
    invoke ReleaseDC,hWnd,hDc 

Title: Re: TextOut.
Post by: Mincho Georgiev on December 09, 2005, 04:12:00 AM
shuttlebug, the function SelectObject selects an object into the specified device context,i.e. the handle hFont we needet only for SelectObject function to Set Up the specified font into the specified DC. It'does not matter that after the Selecting (HGDIOBJ)hFont, the eax or the hFont value is not anymore the same,because we dont need it. If we had a handle of window to setting font into it, SendMessage with WM_SETFONT would do the job ,BUT we setting font into device context,that's why is SelectObject function witch actually fill the second argument with the needed value (hObj). I hope you understanding my point. If somewone had a question why is used the SaveDC function,i'll tell you that way: YES,you can remove it, but on some older machines or OS it may cause a problem.I put it on just to be sure that it will bi ok on GHOST's comp ,who actually begin the current post.
Title: Re: TextOut.
Post by: shuttlebug on December 09, 2005, 04:24:42 AM
It does matter if your going to use that second selectobject function with an invalid hFont handle pointer. And anyhow, i was replying to the original post not to you shaka.
Title: Re: TextOut.
Post by: Mincho Georgiev on December 09, 2005, 04:32:25 AM
I'm, nut sure if understand what you mean. The SelectObject function is not used twice,just once. You cannot use it and you don't need to use it twice,because after the first use ,you have a HGDIOBJ returned by the using of that function.

invoke CreateFont,14,0,0,0,FW_BOLD,0,0,0,
               ANSI_CHARSET,OUT_DEFAULT_PRECIS,
               CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, 18,ADDR FaceName
            mov hFont,eax
            invoke SelectObject,hdc,hFont
            mov hObj,eax
is 5.30 in the mornig now here,so see you soon  :U
Title: Re: TextOut.
Post by: G`HOST on December 09, 2005, 08:12:10 AM
shaka_zulu
Yup, your example worked just perfect. :thumbu
But my Original question was......... ""why"" responding to  WM_PAINT message doesnt work properly?
Title: Re: TextOut.
Post by: tenkey on December 09, 2005, 10:52:04 AM
Probably because you aren't handling WM_NCPAINT.

If you don't change the client area contents or increase its size, WM_PAINT does not get sent. WM_NCPAINT is sent when the nonclient area needs to change. When you lose focus, the title bar normally gets redrawn to turn off highlighting. That happens via a WM_NCPAINT message.

When you regain focus, the client area may need to be redrawn to make it "rise" to the top of the "stack". That happens via both a WM_NCPAINT and a WM_PAINT message. The frame is drawn first via WM_NCPAINT, followed by drawing the client area via WM_PAINT.
Title: Re: TextOut.
Post by: Mincho Georgiev on December 09, 2005, 01:55:36 PM
The answer is simple: When the window looses focus ,windows by itself redraws the title bar area of your window (like changing it's color to gray), and the result of that WINDOWS repainting is disapearing of the posted text. Well ,we corected that - so every time that windows repaints the title bar, the PaintText Function will repaint the text too!
That's it.
Title: Re: TextOut.
Post by: Mincho Georgiev on December 10, 2005, 10:30:48 AM
i mean the title bar AND the status bar. If you pay attention to what's happening whe the main window loose focus,you will notice that WINDOWS repaints the title bar, the status bar and all other controls that needs to be set up as inactive (graying). I hope,you understand now  :U
Title: Re: TextOut.
Post by: G`HOST on December 10, 2005, 11:19:55 AM
yes got you man :U
Title: Re: TextOut.
Post by: Kongbo on November 14, 2006, 02:41:25 AM
How can I fill LOGFONT struct from CHARFORMAT struct when using RichEdit?

When I use RichEdit,I can use CHOOSEFONT and CHARFORMAT to change
the face or the size of FONT.
But when I control the DC, I find that what I can do with FONT is
ONLY LOGFONT struct.
LOGFONT and CHARFORMAT are different struct,I CANNOT transfer them form one to one.

How can I fill LOGFONT struct from CHARFORMAT struct?

Somebody told me , use the GetObject function.
But I try several formats,This function always return 0.

------------------------------------

LOCAL hDC:DWORD
LOCAL Font:LOGFONT

invoke GetObject,hDC, HFONT, addr Font
invoke GetObject,hDC,sizeof LOGFONT,addr Font

invoke GetObject,addr Font, HFONT, addr Font 
invoke GetObject,addr Font, sizeof LOGFONT, addr Font

invoke GetObject,HFONT,sizeof LOGFONT,addr Font

invoke GetObject,addr ,SIZEOF LOGFONT,OFFSET lf
invoke SelectObject,[edi+DRAWITEMSTRUCT.hdc],[edi+DRAWITEMSTRUCT.itemData]

-------------------------------------

Please, tell me,How can I fill LOGFONT struct from CHARFORMAT struct when using RichEdit?