- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello All
I was wondering if it is possible to change the background color of a control (in my case the Edit Box) after the call to DlgModal has been made.
What I want to do is provide some visual and audible feedback to the user that the value he/she placed in the Edit Box was mal-formed or out of range. (I'm thinking here of checking numerical entries.) What I have done is designated a call back function for the DLG_LOSEFOCUS event for the controls of interest and in that call back function make the appropriate tests. Should the tests indicate a problem, my intent was to color the Edit Box's background red.
Well, I've got everything working except for the most critical part - I can't get the background color to change. Here's a snippet of my code from the call back function:
**************************************
* read the string from the control
**************************************
RC = DlgGet( pDialog, pControlID, pTempString)
***************************************
* determine if the field is numeric
***************************************
pIsNumeric = StringIsNumeric( pTempString )
if( .not. pIsNumeric )then
pColor = Z'FF'
RC = DlgSendCtrlMessage( pDialog, pControlID, WM_CTLCOLOREDIT, 0, pColor )
endif
From rooting around on the Internet via Google, the above seemed to have some promise. Also, I partially based it upon an example snippet that was shown in the IVF help file in the entry for DlgSendCtrlMessage as shown below:
Example
use IFLOGM
include 'resource.fd'
type (dialog) dlg
integer callbacktype
integer cref
integer iret
if (callbacktype == dlg_init) then
! Change the color of the Progress bar to red
! NOTE: The following message succeeds only if Internet Explorer 4.0 ! or later is installed
cref = Z'FF' ! Red
iret = DlgSendCtrlMessage(dlg, IDC_PROGRESS1, PBM_SETBARCOLOR, 0, cref)
endif
But, obviously, I have dropped the ball somewhere. This doesn't seem to work.
I have seen other posts on this forum (concerning list boxes and combo boxes) where the solution seemed to be to intercept some Windows messages sent to the List Box or Combo Box and change some brushes' colors before the control was drawn.
I was hoping that for my case with a simpler control (Edit Box) and simpler case (after the dialog was instantiated and visible) that I could simply send the Edit Box a message telling it to change its background color.
Am I on the right track and just using the wrong message or syntax or am I trying to do something that is not possible?
I am using IVF 11.0.066, integrated into Visual Studio 2008, on a Windows Vista 32 bit platform. My client has asked that the solution be in 100% FORTRAN.
Any feedback from you much more experienced forum members would be much appreciated.
Should I come up with a way to do this, I'll be sure to post the solution back here, in case others have an interest in this.
Thanks in advance,
Bob Kiser
I was wondering if it is possible to change the background color of a control (in my case the Edit Box) after the call to DlgModal has been made.
What I want to do is provide some visual and audible feedback to the user that the value he/she placed in the Edit Box was mal-formed or out of range. (I'm thinking here of checking numerical entries.) What I have done is designated a call back function for the DLG_LOSEFOCUS event for the controls of interest and in that call back function make the appropriate tests. Should the tests indicate a problem, my intent was to color the Edit Box's background red.
Well, I've got everything working except for the most critical part - I can't get the background color to change. Here's a snippet of my code from the call back function:
**************************************
* read the string from the control
**************************************
RC = DlgGet( pDialog, pControlID, pTempString)
***************************************
* determine if the field is numeric
***************************************
pIsNumeric = StringIsNumeric( pTempString )
if( .not. pIsNumeric )then
pColor = Z'FF'
RC = DlgSendCtrlMessage( pDialog, pControlID, WM_CTLCOLOREDIT, 0, pColor )
endif
From rooting around on the Internet via Google, the above seemed to have some promise. Also, I partially based it upon an example snippet that was shown in the IVF help file in the entry for DlgSendCtrlMessage as shown below:
Example
use IFLOGM
include 'resource.fd'
type (dialog) dlg
integer callbacktype
integer cref
integer iret
if (callbacktype == dlg_init) then
! Change the color of the Progress bar to red
! NOTE: The following message succeeds only if Internet Explorer 4.0 ! or later is installed
cref = Z'FF' ! Red
iret = DlgSendCtrlMessage(dlg, IDC_PROGRESS1, PBM_SETBARCOLOR, 0, cref)
endif
But, obviously, I have dropped the ball somewhere. This doesn't seem to work.
I have seen other posts on this forum (concerning list boxes and combo boxes) where the solution seemed to be to intercept some Windows messages sent to the List Box or Combo Box and change some brushes' colors before the control was drawn.
I was hoping that for my case with a simpler control (Edit Box) and simpler case (after the dialog was instantiated and visible) that I could simply send the Edit Box a message telling it to change its background color.
Am I on the right track and just using the wrong message or syntax or am I trying to do something that is not possible?
I am using IVF 11.0.066, integrated into Visual Studio 2008, on a Windows Vista 32 bit platform. My client has asked that the solution be in 100% FORTRAN.
Any feedback from you much more experienced forum members would be much appreciated.
Should I come up with a way to do this, I'll be sure to post the solution back here, in case others have an interest in this.
Thanks in advance,
Bob Kiser
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - rkiseral
Hello All
I was wondering if it is possible to change the background color of a control (in my case the Edit Box) after the call to DlgModal has been made.
iret = DlgSendCtrlMessage(dlg, IDC_PROGRESS1, PBM_SETBARCOLOR, 0, cref)
endif
But, obviously, I have dropped the ball somewhere. This doesn't seem to work.
I have seen other posts on this forum (concerning list boxes and combo boxes) where the solution seemed to be to intercept some Windows messages sent to the List Box or Combo Box and change some brushes' colors before the control was drawn.
I was wondering if it is possible to change the background color of a control (in my case the Edit Box) after the call to DlgModal has been made.
iret = DlgSendCtrlMessage(dlg, IDC_PROGRESS1, PBM_SETBARCOLOR, 0, cref)
endif
But, obviously, I have dropped the ball somewhere. This doesn't seem to work.
I have seen other posts on this forum (concerning list boxes and combo boxes) where the solution seemed to be to intercept some Windows messages sent to the List Box or Combo Box and change some brushes' colors before the control was drawn.
Alas, no. For whatever reason, it's simple with progress bars (and status bars IIRC) but terribly complicated with pretty much anything else. Namely, you cannot send WM_CTLCOLOREDIT to the control (well, you can, but it won't work). Instead, the control sends WM_CTLCOLOREDIT to the parent dialog to "query" for its colors each time it wants to be redrawn. And with IFLOGM, you don't have a place to handle that message.
So, you're stuck with one of
* Using pure APIs to manage the dialog
* Subclass the dialog
* Use some of my XFLOGM wrappers instead (however, I must admit they're a bit dusty by now. I haven't even tested them with V.11).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Subclassing your dialog is straightforward and done using a call to the function SetWindowLong. However, when processingthose messages you want to intercept that request a colour for a control before it is drawn, you must return a handle to a brush of your selected colour and return from the dialog procedure immediately, or it will not work. For example,when intercepting a message that contains a scrollbar control's request for a colour using a dialog procedure called ColorDlgProc in place of the dialog's default procedure:
INTEGER*4 FUNCTION ColorDlgProc(hWnd, mesg, wParam, lParam)
!DEC$ATTRIBUTES STDCALL:: ColorDlgProc
!USE whatever modules you need here....
use dfwin
USE DFWINTY
USE DFLIB
USE DFLOGM
USE INPUTINFO
!
IMPLICIT NONE
INTEGER*4 hWnd, mesg,lParam, wParam
INTEGER*4 ctrlid, holdbrush, hRedBackbrush
SELECT CASE (mesg)
CASE(WM_CTLCOLORSCROLLBAR) ! Intercept message issued just before a scroll bar is painted
ctrlid = GetDlgCtrlId(lParam)! Get the ID of this scrollbar from the Lparam message parameter, so you can test if it is yours
IF(ctrlid.eq.IDC_MYSCROLLBAR) THEN ! select the new color foryour scrollbar background
hOldBrush = SelectObject(wparam, hRedBackBrush) ! Wparam is the handle to the device context used to draw the control
ColorDlgProc= hRedBackBrush
return ! Immediate return is specified if this is to work correctly
ENDIF
The return value for ColorDlgProc is a handle to a brush that you will have defined earlier in order to have it ready to use.
The code is similar for messages WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC. Remember to pass on all other messages to the dialog's original procedure, the handle to which (hOldProc) you will have saved after using SetWindowLong to set the new dialog procedure to be used to handle these particular messages. This default handling can be carried out in the following way:
CASE DEFAULT
ColorDlgProc= CallWindowProc(hOldProc, hWnd, Mesg, wParam, lParam)
END SELECT
P.S. If you want to change text colour at the same time, then just select a new pen into the control's device context using SelectObject(wparam, hNewPen) after creating a new pen,using the CreatePen function and saving its handle in hNewPen. It is good practice to delete pens and brushes that you no longer require using DeleteObject function.
INTEGER*4 FUNCTION ColorDlgProc(hWnd, mesg, wParam, lParam)
!DEC$ATTRIBUTES STDCALL:: ColorDlgProc
!USE whatever modules you need here....
use dfwin
USE DFWINTY
USE DFLIB
USE DFLOGM
USE INPUTINFO
!
IMPLICIT NONE
INTEGER*4 hWnd, mesg,lParam, wParam
INTEGER*4 ctrlid, holdbrush, hRedBackbrush
SELECT CASE (mesg)
CASE(WM_CTLCOLORSCROLLBAR) ! Intercept message issued just before a scroll bar is painted
ctrlid = GetDlgCtrlId(lParam)! Get the ID of this scrollbar from the Lparam message parameter, so you can test if it is yours
IF(ctrlid.eq.IDC_MYSCROLLBAR) THEN ! select the new color foryour scrollbar background
hOldBrush = SelectObject(wparam, hRedBackBrush) ! Wparam is the handle to the device context used to draw the control
ColorDlgProc= hRedBackBrush
return ! Immediate return is specified if this is to work correctly
ENDIF
The return value for ColorDlgProc is a handle to a brush that you will have defined earlier in order to have it ready to use.
The code is similar for messages WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC. Remember to pass on all other messages to the dialog's original procedure, the handle to which (hOldProc) you will have saved after using SetWindowLong to set the new dialog procedure to be used to handle these particular messages. This default handling can be carried out in the following way:
CASE DEFAULT
ColorDlgProc= CallWindowProc(hOldProc, hWnd, Mesg, wParam, lParam)
END SELECT
P.S. If you want to change text colour at the same time, then just select a new pen into the control's device context using SelectObject(wparam, hNewPen) after creating a new pen,using the CreatePen function and saving its handle in hNewPen. It is good practice to delete pens and brushes that you no longer require using DeleteObject function.

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