I am trying to figure out how to change the font of a popup menu. I have created my tray icon, added a menu, and added items to that menu. The problem is that I can't change the font using SendMessage. What other API command updates the menu's font. THanks for the help. Here is what my statements look like for the font.
fntSegoeUI LOGFONT <-12,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Segoe UI">
invoke CreateFontIndirect,OFFSET fntSegoeUI
mov hwndSegoeUI, eax
invoke SendMessage, menuHWND, WM_SETFONT, hwndSegoeUI, TRUE
Jason
We've had this one before :bdg
I think the general solution was to go with owner-drawn menus, which is a fair amount of trouble. Which basically means you draw the menu, and its items, and the selection, etc.. And so you can use whichever fonts or colours you like.
WM_SETFONT just doesn't work - I've tried it also. The only other 'easy' solution I can think of is to change the default menu font - but this would apply for all menus everywhere, so it's not a very nice idea.
Thanks. Yeah I was thinking that it was not going to be that easy. I guess I will just stick with the default font. Thanks again.
Jason
My problem is :
I can change the FONT of a RichEdit via CHARFORMAT,
but if I try control the DC of the RichEdit,
I find I must use the struct of LOGFONT to create Font of this DC.
They are different two struststructs.
HOW can I fill LOGFONT struct from a CHARFORMAT ?
Thank you
Hi jbullard,
I wrote an example of an ownerdrawn menu once, it enumerated the fonts and used them in the menu. Ownerdrawn controls are really a whole lot simpler than you'd think and allows you to stylize your program a little to separate it from the pack. I have the example on my website but I've also included it at the bottom of this post. The usual caveats apply... "I do not write in MASM, using only GoAsm so you will be obliged to translate it to MASM syntax or better still use GoAsm, it's free!!, also no animals were harmed in the making of this example (with the possible exception of my cats who see time spent on the computer as a waste of good petting time and thereby harmful)"
Hi Kongbo,
You can fill the LOGFONT structure with the GetObject API, using a pointer to the structure.
[attachment deleted by admin]
Thanks for the example. I have started another program and this will definitely come handy. :U
I CANNOT get the LOGFONT of the RichEdit.
I use these functions below ,want to get the current LOGFONT of RichEdit.
But ,they are only 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
-----------------------------------------------
What's the problem I make ?
Thank you.
Hi Kongbo,
I don't see what the problem is with sending EM_GETCHARFORMAT to fill the CHARFORMAT structure then translating that into a LOGFONT structure. The only real adaptation to make is twips to points but that can be accomplished by multiplying by 20 (a twip is a twentieth of a point). Beyond that simple translation all of the pertinent data is in the CHARFORMAT structure ready to use...
CHARFORMAT.dwEffects = LOGFONT.lfWeight, LOGFONT.lfItalic, LOGFONT.lfUnderline, LOGFONT.lfStrikeOut
CHARFORMAT.yHeight * 20 = LOGFONT.lfHeight (use lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72) to calculate device units)
CHARFORMAT.bCharSet = LOGFONT.lfCharSet
CHARFORMAT.bPitchAndFamily = LOGFONT.lfPitchAndFamily
CHARFORMAT.szFaceName = LOGFONT.lfFaceName
Just set the other members of LOGFONT to zero, they are usually that anyway so it makes no difference.
Donkey
By the way Kongbo,
You should at least read the docs for GetObject, the right way to use it is...
LOCAL hDC :D
LOCAL hFont :D
LOCAL lfont :LOGFONT
invoke GetDC, [hWin]
mov [hDC], eax
invoke GetCurrentObject, [hDC], OBJ_FONT
mov [hFont], eax
invoke GetObject, [hFont], SIZEOF LOGFONT, ADDR lfont
invoke ReleaseDC, [hDC]
Just poking in values and hoping to get the right result is not the way to program, read the documentation and write a test, adjust and correct your assumptions as necessary based on what you learn.
My code is below:
But it's dont work either.
What wrong with me?
-----------------------------------------------------------------------------------------------------------
LOCAL @hDC,@Font:LOGFONT,@hFont:HFONT
invoke HideCaret,stWin.hREdit
invoke GetDC,stWin.hREdit
mov @hDC,eax
invoke GetCurrentObject, @hDC, OBJ_FONT
mov @hFont,eax
invoke GetObject, @hFont,sizeof LOGFONT,addr @Font
invoke SelectObject,@hDC, @hFont
push eax
invoke TextOut,@hDC,0,@top,addr stWin.pBufferA,@dwLen
pop eax
invoke SelectObject,@hDC, eax
invoke ReleaseDC,stWin.hREdit,@hDC
invoke ShowCaret,stWin.hREdit
Why do you need to fill a logfont structure in that code ? it does nothing at all, you just need the handle to the font. And also, the font that is returned from GetCurrentObject is the font currently selected into the DC, there is no need to select it into it again before the TextOut. If you could just explain what you are trying to do I might be able to help but all of this "how do I do this" and "how do I do that" followed by a peice of code that has no need for it is a bit pointless.
Donkey
I'm making a editor inherite from RichEdit.
The special function of it is :
When I move the cursor or the direction key in the editor,
The line which cursor right in will be displayed in another color.
The other lines will keep their color.
And the editor can change font face and size by user at any time.
So ,I must use the TextOut function and reload the PAINT method.
Have another way?
All works well then ,except the FONT !
The strings output by TextOut function JUST have the DEFAULT font of RichEdit!
If I make a LOGFONT ,I must fill LOGFONT struct from CHARFORMAT struct .
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?
Thank you!
I Have already showed you the parallels between the 2 structures, the transfers are simple. I haven't in any way tested this or even tried to compile it, I typed it directly here but it should be very close...
mov edi, offset CharFormat
mov esi, offset lfont
invoke ZeroMem, esi, SIZEOF LOGFONT
mov D[esi+LOGFONT.lfWeight],FW_NORMAL
// ********** flags
mov eax,[edi+CHARFORMAT.dwEffects]
test eax, CFE_BOLD
jz >
mov D[esi+LOGFONT.lfWeight], FW_BOLD
:
test eax,CFE_ITALIC
jz >
mov B[esi+LOGFONT.lfItalic], TRUE
:
test eax,CFE_STRIKEOUT
jz >
mov B[esi+LOGFONT.lfStrikeOut], TRUE
:
test eax,CFE_UNDERLINE
jz >
mov B[esi+LOGFONT.lfUnderline], TRUE
:
// ********** Size
mov eax,[edi+CHARFORMAT.yHeight]
mov ecx,20
xor edx,edx
div ecx
push eax
invoke GetDeviceCaps,[hDC],LOGPIXELSY
pop ecx
mul ecx
mov ecx,72
xor edx,edx
div ecx
neg eax
mov [esi+LOGFONT.lfHeight], eax
// ********** face name
lea eax,[esi+LOGFONT.lfFaceName]
lea ecx,[edi+CHARFORMAT.szFaceName]
invoke lstrcopy, eax, ecx
// ********** Other
mov al,[edi+CHARFORMAT.bCharSet]
mov [esi+LOGFONT.lfCharSet],al
mov al,[edi+CHARFORMAT.bPitchAndFamily]
mov [esi+LOGFONT.lfPitchAndFamily],al
Edgar,
> (with the possible exception of my cats who see time spent on the computer as a waste of good petting time and thereby harmful)
You must have trained them wrong, the last cat in this house thought he was a programmer and used to make his contribution to source code by walking on the keyboard. It did not compile but it was not through lack of effort on his part. :bg
Hi Steve,
I've been putting in little comments like that ever since the thread on "who uses QE anyway", I had my little joke in my post there (except the "spell chack") and no-one saw it or at least no-one commented on it. I thought cool, I can type anything I want, no-one reads it anyway. Now you've gone and burst my bubble :)
My cats did try programming for a short while but they now are content to lie on the bed and demand attention, it takes too much effort to climb up onto the desk and the articulating keyboard tray tends to shift under their weight. Bear weighs in at a hefty 20 lbs now and the others are not far behind.
Edgar
Partly soluted.Not soluted completely,
The define of LOGFONT struct is very strict,
Even a very little different in the struct, the display string is WRONG.
eg:
1:If the character's wide is just a little wider or thinner , the position of cursor
is in the middle of a letter:<
2:If the user change the RichEdit's font face or size ,even a very little different
in the LOGFONT struct will make Windows select another font.
SO,Windows drive us MUST really fill in every field of the LOGFONT corectly.
------------------------------------------
typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth; ----?
LONG lfEscapement; ----?
LONG lfOrientation;
LONG lfWeight; ----?
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;----?
BYTE lfClipPrecision; ----?
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT;
typedef struct _charformat {
UINT cbSize;
_WPAD _wPad1;
DWORD dwMask;
DWORD dwEffects;
LONG yHeight;
LONG yOffset;
COLORREF crTextColor;
BYTE bCharSet;
BYTE bPitchAndFamily;
TCHAR szFaceName[LF_FACESIZE];
_WPAD _wPad2;
} CHARFORMAT;