News:

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

Change PopupMenu Font

Started by jbullard, August 22, 2006, 12:57:33 AM

Previous topic - Next topic

jbullard

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

Tedd

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.
No snowflake in an avalanche feels responsible.

jbullard

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

Kongbo

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

donkey

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]
"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

jbullard

Thanks for the example.  I have started another program and this will definitely come handy.   :U

Kongbo

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.

donkey

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
"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

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.
"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

Kongbo

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      

donkey

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
"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

Kongbo

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!

donkey

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

"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

hutch--

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
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

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
"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