Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

DlgHookProc & WM_CTLCOLORDLG

ahasan
Beginner
1,707 Views
CVF 6.6, Win32 app. -- I created a hook procedure for the Open and Saveas Dlg boxes (Explorer style) to position the Dlg boxes on the screen. The hook proc. works fine for that. I would also like to repaint the bkgnd color of the Dlg boxes by processing the WM_CTLCOLORDLG message in the hook procedure, but so far I have been unsuccessful.I am not sure how to return the handle of the background brush?Thanks in advance for any assistance.
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
1,707 Views
Well... just return it :-). Note that return value of a HookProc or DialogProc is not exactly LOGICAL, but an INTEGER. Pay attention to brush creation/destruction, as it has to be properly cleaned up::
integer, save:: hBrush=0, hDC
integer, parameter:: myColor = #000080
case (WM_INITDIALOG)
hBrush = CreateSolidBrush(myColor)
case (WM_CTLCOLORDLG, &
WM_CTLCOLORSTATIC)
hDC = wParam
!SetBkColor & SetBkMode are necessary for controls
!within the dialog.
iSt = MSFWIN$SetBkColor(hDC, #000080)
iSt = SetBkMode(hDC, TRANSPARENT)
OpenHookProc = hBrush
case (WM_DESTROY)
i = DeleteObject(hBrush)
Alas, (I tried it) it has no effect on toolbar and static controls in the original dialog (unless you subclass it on WM_INITDIALOG), so the end result is rather ugly.
Jugoslav
0 Kudos
ahasan
Beginner
1,707 Views
jugoslavdujic, thanks a million. I am trying to convert some old MSDOS engineering apps, that I wrote, into win32 apps. Not a professional programmer, sowhen I hit a snag, help is very much appreciated.
0 Kudos
ahasan
Beginner
1,707 Views

I modified my Open/Save dialog box hook procedure with the code you provided, and also subclassed the dlg procedure while processing the WM_INITDIALOG message inthe hook procedure. The Open and Saveas Dlg boxes are centered on the screen, and respond to all user input. However,I monitored the messages being sent toboth the hook and subclassed dialog procedures, and never saw the WM_CTLCOLORDLG (#0136, 310 dec)message, so the application never had an oportunity to process this message. The message streams for both dlg proceduresincluded position change, redraw, notify, and destroy messages (to name a few), and appeared to be normal except for the absence of the WM_CTLCOLORDLG. The discussion of the WM_CTLCOLORDLG message in the SDK states that the"...WM_CTLCOLORDLG message is sent to the dialog box itself...." However,the hook procedure (and I believe the subclassed proc.) is actually a procedure for a child of the original dlg box. Is it possible thatthe WM_CTLCOLORDLG message is not being sent to the child window? If this is the problem,is it possible to divert the message to the child dlg box message que?

Message Edited by halcyong@fcc.net on 01-24-2004 01:42 PM

Message Edited by halcyong@fcc.net on 01-24-2004 01:44 PM

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,707 Views

I'm getting WM_CTLCOLORDLG here.

I suspect the problem is in your subclassing code -- could you post it?

Jugoslav
0 Kudos
ahasan
Beginner
1,707 Views
When I execute the attached code, I get messages such as 24, 70 (position change), 131, 34 (activated child), 71, 11 (redraw), etc. in the subclassed dlg box proc, but no WM_CTLCOLORDLG (#0136, 310 dec.). Thanks for taking a look.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,707 Views
1) You subclassed the wrong dialog -- you should subclass GetParent(hDlg), as the main dialog is the one misbehaving.
2) You should repeat the case(WM_CTLCOLORSTATIC, WM_CTLCOLORDLG) in both HookProc and SubclassProc -- the first takes care about your dialog, the latter about the main dialog.
Jugoslav
0 Kudos
ahasan
Beginner
1,707 Views
Thank you JugoslavDujic. I am still playing around with thehookand subclass procedures to get the results I need. Thehook and subclass procedures together seem to slow the display of the dialog box a little. Very interesting.
0 Kudos
Reply