What I am trying to do is set the text font in an edit control (in a dialog box, if it matters) to italic. I have gotten it to work by doing the following:



.ELSEIF uMsg==WM_CTLCOLORSTATIC
invoke GetDlgCtrlID,lParam
.
.
.
.ELSEIF eax == IDC_CARDFLAVOR ; the edit control ID
invoke GetCurrentObject,wParam,OBJ_FONT
mov hFontObj,eax
invoke GetObject,hFontObj,sizeof lFont,ADDR lFont
mov lFont.lfItalic,TRUE
invoke CreateFontIndirect,ADDR lFont
mov hFontObj,eax
invoke SelectObject,wParam,hFontObj
invoke SetTextColor,wParam,CurrentLightColor
mov eax,hBrLightCurrent
.
.
.


Works just fine...only thing I don't understand is why I have to set the font to italic every time I process WM_CTLCOLORSTATIC. I've tried setting it only on the first WM_CTLCOLORSTATIC...doesn't work. I have to do it every time. I've also tried setting it on the INITDIALOG message:



.
.
.
.IF uMsg==WM_INITDIALOG
invoke GetDlgItem,hWnd,IDC_CARDFLAVOR
mov hFlavor,eax
invoke GetDC,hFlavor
mov hDC,eax
invoke GetCurrentObject,hDC,OBJ_FONT
mov hFontObj,eax
invoke GetObject,hFontObj,sizeof lFont,ADDR lFont
mov lFont.lfItalic,TRUE
invoke CreateFontIndirect,ADDR lFont
mov hFontObj,eax
invoke SelectObject,hDC,hFontObj
invoke ReleaseDC,hFlavor,hDC
.
.
.


but the code doesn't work at all. So my question is, I guess, why can't I seem to get the correct edit control DC? Or why is the text getting reset to normal every time the control is painted?
Posted on 2003-11-11 12:34:53 by sirchess
I'm not sure about your problem, but you should be deleting the old font or you are using alot of resources...

.ELSEIF uMsg==WM_CTLCOLORSTATIC

invoke GetDlgCtrlID,lParam
.
.
.
.ELSEIF eax == IDC_CARDFLAVOR ; the edit control ID
invoke GetCurrentObject,wParam,OBJ_FONT
mov hFontObj,eax
invoke GetObject,hFontObj,sizeof lFont,ADDR lFont
mov lFont.lfItalic,TRUE
invoke CreateFontIndirect,ADDR lFont
mov hFontObj,eax
invoke SelectObject,wParam,hFontObj
[b]invoke DeleteObject,eax[/b]
invoke SetTextColor,wParam,CurrentLightColor
mov eax,hBrLightCurrent


For your problem have you tried sending a WM_SETFONT message instead ?
Posted on 2003-11-11 12:46:44 by donkey
Donkey,

No, I forgot about WM_SETFONT
:stupid:

Anyways, I got it to set italics with WM_SETFONT, but it's not the right font.

In my resource file I have the dialog defined as follows:


CardInfo DIALOG DISCARDABLE 150,15,147,182
STYLE WS_CHILD | DS_CONTROL | WS_VISIBLE
FONT 8, "MS Sans Serif"
BEGIN
.
.
.
EDITTEXT IDC_CARDFLAVOR,5,80,112,43,ES_READONLY | ES_MULTILINE | WS_VSCROLL
.
.
.
END


And in the code now:


.IF uMsg==WM_INITDIALOG
invoke GetDlgItem,hWnd,IDC_CARDFLAVOR
mov hFlavor,eax
invoke GetDC,hFlavor
mov hDC,eax
invoke GetCurrentObject,hDC,OBJ_FONT
mov hFontObj,eax
invoke GetObject,hFontObj,sizeof lFont,ADDR lFont
mov lFont.lfItalic,TRUE
invoke CreateFontIndirect,ADDR lFont
invoke SendDlgItemMessage,hWnd,IDC_CARDFLAVOR,WM_SETFONT,eax,TRUE


The result was italic text, but instead of 8-pt MS Sans Serif it wass more like the system default font and point.

The next thing I tried was copying the font info from the dialog DC instead of the editbox DC but still put it into the editbox DC...didn't change anything.

I want only the one edit box to be italic...there are other controls that need to stay normal. What am I missing here?
Posted on 2003-11-11 13:09:35 by sirchess
I think the WM_SETFONT is sent after the WM_INITDIALOG message so the font at the time you are processing the message is the system font. To set the font at that time you must create the font in-program. You could also process the WM_SETFONT message...

.IF uMsg == WM_SETFONT

; do your font extraction and creation here
invoke SendMessge,hControl,WM_SETFONT,hFont,TRUE
mov eax,FALSE ; continue to process the message
ret


This way any changes to the dialog font are reflected in the controls as well.
Posted on 2003-11-11 13:24:29 by donkey
Processing WM_SETFONT doesn't work at all. I checked and apparently that message gets sent before the WM_INITDIALOG, at least the dialog box's WM_SETFONT is.

I haven't tried processing the edit control WM_SETFONT because, AFAIK, that would require subclassing, which I am trying to avoid.

I'm also trying to avoid creating my own font because I looked at the number of members in the LOGFONT struct and it looks like trying to figure out that mess would be a project of its own :grin:

Which is why I'm trying what I'm trying...but it's not working.

/Edit: I think I found the problem.

First, I didn't notice, Donkey, that the handle to the dialog font is passed as wParam in the WM_SETFONT message (duh). So I changed it to extract that instead of getting the DC,etc.

Then I had the correct font object, but it still wasn't updating properly.

In the Win32 reference, it says that "The dialog box procedure is responsible for saving the font handle passed with the WM_SETFONT message and selecting the handle into the display device context whenever it writes text to the window. Predefined controls do this by default."

So what I guess was happening wass that the dialog box was changing the font each time before it repainted the control. I found that I could send a WM_SETFONT message to the editbox every time WM_CTLCOLOREDIT is called, using the now correct font object. So now it works. Thanks donkey!

/Edit2:
Does anyone know if there is a way to set the font of a single control in a resource script? It would be much easier...
Posted on 2003-11-11 15:20:13 by sirchess
Hi, everyone.


Does anyone know if there is a way to set the font of a single control in a resource script? It would be much easier...

There should be... did you guys check at MSDN?

EDIT:
Here you go... :)
DIALOGEX Resource statement
Posted on 2003-11-11 16:19:06 by QvasiModo
Thanks for the link Qvasi, unfortunately the DIALOGEX resource would only let me set all the controls to italics...I want only one control to be italics (the others should be normal font). I suppose I could put the control into a separate dialog box, but...that seems unnatural.
Posted on 2003-11-11 16:40:07 by sirchess
Right, I didn't realize that... :o
Anyway, you could do the following:
- Send WM_GETFONT
- Fill a LOGFONT structure from this handle, and change only what you need
- Create a new font and set it with WM_SETFONT
- Destroy the old handle
This should be done when processing WM_INITDIALOG.
Hope this one helps! ;)

BTW, most of the members of LOGFONT are not needed, just set them to NULL. :)
Posted on 2003-11-11 16:56:02 by QvasiModo
Wow...thanks, Qvasi! That solved everything...now I don't even have to call WM_SETFONT within the WM_CTLCOLORDIALOG anymore :alright:

I should've realized, if there's a WM_SETFONT, there must be a WM_GETFONT :rolleyes: ...silly me

I had tried setting the font during the dialog box's WM_SETFONT, but I guess that was too early...but it works now with the WM_INITDIALOG.

---

Thanks to both Qvasimodo and Donkey for their help and knowledge :)
Posted on 2003-11-11 17:15:47 by sirchess