.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.
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
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)
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
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]
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.
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.
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...
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.
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
Yes, GetWindowDC returns the DC for the entire window,but i didn't understand why you need that for TextOut
ok, i didn't saw your previous post
But the question still remains,Why the window behaving the way it is?
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]
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
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
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
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.
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.
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
shaka_zulu
Yup, your example worked just perfect. :thumbu
But my Original question was......... ""why"" responding to WM_PAINT message doesnt work properly?
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.
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.
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
yes got you man :U
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?