- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm having difficulty in changing the colour of text in dialog controls. I am utilising the dflogm module and calling the following subroutine from the modal dialog callback.
subroutine DlgSetTextColour(dlg,idc,RGBCol)
!*************************************************************
! Set Text Colour in Dialog Control
!*************************************************************
use dflogm
use dfwin
implicit none
! Arguements
type(DIALOG) :: dlg ! Dialog Data Structure
integer :: idc ! Dialog Control ID
integer :: RGBCol ! RGB(red,green,blue)
! Local variables
integer(HANDLE) :: hWndControl ! Control Window handle
integer(HANDLE) :: hDC ! Device Context
integer(DWORD) :: iret
if(dlg%hWnd.eq.0) return
hWndControl = GetDlgItem(dlg%hwnd,idc)
hDC = GetDC(hWndControl)
iret = MSFWIN$SetTextColor(hDC,RGBCol)
return
end subroutine
It has no effect. Eventually I wish to be able to modify the Font by making it bold or italic also. Is it possible to do this using the DFLOGM/IFLOGM modules modal dialog boxes or will I have to reconfigure to Modeless or rewrite in Windows API approach.
I tried changing the control (a push button) to Owner Draw but if crashed the program at the DlgInit(IDD_WW,dlg) statement.
subroutine DlgSetTextColour(dlg,idc,RGBCol)
!*************************************************************
! Set Text Colour in Dialog Control
!*************************************************************
use dflogm
use dfwin
implicit none
! Arguements
type(DIALOG) :: dlg ! Dialog Data Structure
integer :: idc ! Dialog Control ID
integer :: RGBCol ! RGB(red,green,blue)
! Local variables
integer(HANDLE) :: hWndControl ! Control Window handle
integer(HANDLE) :: hDC ! Device Context
integer(DWORD) :: iret
if(dlg%hWnd.eq.0) return
hWndControl = GetDlgItem(dlg%hwnd,idc)
hDC = GetDC(hWndControl)
iret = MSFWIN$SetTextColor(hDC,RGBCol)
return
end subroutine
It has no effect. Eventually I wish to be able to modify the Font by making it bold or italic also. Is it possible to do this using the DFLOGM/IFLOGM modules modal dialog boxes or will I have to reconfigure to Modeless or rewrite in Windows API approach.
I tried changing the control (a push button) to Owner Draw but if crashed the program at the DlgInit(IDD_WW,dlg) statement.
Link Copied
11 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - anthonyrichards
Thanks Anthony, your example is really useful.
This is almost what I was looking for and I have managed to incorporate the method into one of my dialogs. However it does not seem to work with pushbutton controls.My originalidea was to showthe currentlyselected colourfor the background of the button used to select the common colour dialog box.
Is it possible to change the font style of individual controlsusing this technique?
Thanks,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - dannycat
Thanks Anthony, your example is really useful.
This is almost what I was looking for and I have managed to incorporate the method into one of my dialogs. However it does not seem to work with pushbutton controls.My originalidea was to showthe currentlyselected colourfor the background of the button used to select the common colour dialog box.
Is it possible to change the font style of individual controlsusing this technique?
Unfortunately, you cannot change background of foreground colors of pushbuttons. That's by [stupid] Windows design.
What you can do is to make a bitmap whose single color you change dynamically, and set it to button using BM_SETIMAGE (make sure to specify BS_BITMAP style for the button.) A simpler method is to use a static control+push button, as in the attached image.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem with push buttons is that they consist of more than one component (the shadowed edge plus the main part), so apparently a single 'background' color is not allowed by the Windows system.
Regarding fonts, once you have a handle to a font object,hFontObj, and a handle to the device context for the control, hDC, you can selectthe fontinto the device context forthe control using SelectObject(hDC, hFontObj).As to choosing and selcting fonts, I can be of no help. Try looking up 'ChooseFont' and 'Font and Text Functions' in the Help.
Regarding fonts, once you have a handle to a font object,hFontObj, and a handle to the device context for the control, hDC, you can selectthe fontinto the device context forthe control using SelectObject(hDC, hFontObj).As to choosing and selcting fonts, I can be of no help. Try looking up 'ChooseFont' and 'Font and Text Functions' in the Help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav,
I arrived at a similar conclusion, but I used an edit box+push button combination instead. However I tried to make the edit box read only the colour would not change. I understand from Anthony's example that edit-boxes become static if set to readonly, so I added code to deal with this, but it still does not work. It must be another Windows "design feature".
I arrived at a similar conclusion, but I used an edit box+push button combination instead. However I tried to make the edit box read only the colour would not change. I understand from Anthony's example that edit-boxes become static if set to readonly, so I added code to deal with this, but it still does not work. It must be another Windows "design feature".
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - dannycat
Jugoslav,
I arrived at a similar conclusion, but I used an edit box+push button combination instead. However I tried to make the edit box read only the colour would not change. I understand from Anthony's example that edit-boxes become static if set to readonly, so I added code to deal with this, but it still does not work. It must be another Windows "design feature".
I arrived at a similar conclusion, but I used an edit box+push button combination instead. However I tried to make the edit box read only the colour would not change. I understand from Anthony's example that edit-boxes become static if set to readonly, so I added code to deal with this, but it still does not work. It must be another Windows "design feature".
Steve
In my example, I have just set the ReadOnly property of an edit box, recompiled and run itandthe read-only edit boxsent a WM_CTLCOLORSTATIC message OK as expected which I was able to intercept andwas then able to paint its background. Can you post your code to see what is happening?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - dannycat
I arrived at a similar conclusion, but I used an edit box+push button combination instead. However I tried to make the edit box read only the colour would not change. I understand from Anthony's example that edit-boxes become static if set to readonly, so I added code to deal with this, but it still does not work. It must be another Windows "design feature".
Huh? No, it must be something else:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I must apologise, I can get the edit-box readonly colour change to work after all. I'd not changed the control typefrom WM_CTLCOLOREDIT to WM_CTLCOLORSTATIC in the definition part on my dialog code.
I'm going to try to get the font changes now. I only really want to make the text in group boxes bold.
Thanks.
I'm going to try to get the font changes now. I only really want to make the text in group boxes bold.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - dannycat
I must apologise, I can get the edit-box readonly colour change to work after all. I'd not changed the control typefrom WM_CTLCOLOREDIT to WM_CTLCOLORSTATIC in the definition part on my dialog code.
I'm going to try to get the font changes now. I only really want to make the text in group boxes bold.
Thanks.
I'm going to try to get the font changes now. I only really want to make the text in group boxes bold.
Thanks.
Here is how to create and use a 10 point, bold italic Verdana font
TYPE(T_LOGFONT):: LF
INTEGER::i, hFont
LF=T_LOGFONT(-10,0,0,0,FW_BOLD, 1_1,0_1,0_1,0_1, 0_1,0_1,0_1,0_1,"Verdana"C) !10-pointVerdana font
hFont = CreateFontIndirect(LF)
To set the font for a control, you can use
i = SendMessage(GetDlgItem(Dlg%hWnd,IDC_YOURCONTROL), WM_SETFONT, hFont, 0)
I have tried this and find the text output using this bold font,is not as black as when using the default black font.
I have no idea why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - anthonyrichards
Here is how to create and use a 10 point, bold italic Verdana font
You would better just bold the original system font. Semi-pseudo code follows, I don't have time to look at exact prototypes:
[cpp]type(T_LOGFONT) LF hFont = SendDlgItemMessage(IDC_GROUP, WM_GETFONT) !(Alternatively, use GetStockObject(DEFAULT_GUI_FONT))Don't forget to destroy hFont2 after you're done with the dialog. Failure to do so creates a (small though) GDI memory leak.
iret = GetObject(hFont, LOC(LF)) LF%lfWeight = FW_BOLD hFont2 = CreateFontIndirect(LF) iret = SendDlgItemMessage(IDC_GROUP, WM_SETFONT, hFont2) [/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: the text contrast being less when in a read-only edit box, I think this is because the box is given a greyed-out look when selected as read-only , so the contrast between background and text will always be less whatever text boldness is selected.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page