- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
AEN_KILLFOCUSnotification mesg. is processed bymy Dlg Proc followed bya BN_CHECKEDmesg. (clicking on a checkboxcauses anedit ctrll to lose focus). However, I would like to process the BN_CHECKED mesg. first. Trying to do this, I inserted the following codeimmediately after Case (EN_KILLFOCUS):
Case(EN_KILLFOCUS)
do
! looks at all messages in hDlg's Q
iret = PeekMessage(mesg2, hDlg, 0, 0, PM_NOREMOVE)
if(iret .EQ. 0) exit
if(Hiword(mesg2%wParam) .EQ. BN_CLICKED .AND. &
(mesg2%lParam .EQ. hCheck1 .OR. mesg2%lParam .EQ. &
hCheck2)) then
! looks at all messages in hDlg's Q
iret = PeekMessage(mesg2, hDlg, 0, 0, PM_NOREMOVE)
if(iret .EQ. 0) exit
if(Hiword(mesg2%wParam) .EQ. BN_CLICKED .AND. &
(mesg2%lParam .EQ. hCheck1 .OR. mesg2%lParam .EQ. &
hCheck2)) then
! note, SendMessage does not return until message is processed
iret = SendMessage(hDlg, WM_COMMAND, MakewParam(0,&
iret = SendMessage(hDlg, WM_COMMAND, MakewParam(0,&
BN_CLICKED), mesg2%lParam)
! ??? remove BN_CLICKED notification message from the Q here ???
exit
end if
end do
end if
end do
.
.
end select
This does not work, and I am really not sure if this is an appropriate use for PeekMessage(). In the above code, PeekMessage always returns 1 (with the same mesg2%message = 15) which causes an infinite loop. Also, not sure how to remove the BN_CLICKED notification mesg. from the Dlg Proc. Q if it is found.
Is there a way to use the PeekMessage Filters to find a notification message?
Thanks for any help!
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't do it with PeekMessage. PeekMessage only inspects the posted messages, i.e. the ones waiting in the message queue. However, many messages (I think all of WM_COMMAND) are sent directly from one window to another, or from functions like IsDialogMessage, TranslateMessage etc. -- alot of "ping-pong"is going on. In this case, I suppose BN_CLICKED is sent from check box's window procedure directly to its parent dialog (via SendMessage) when the check box receives WM_LBUTTONDOWN (preceded by BN_SETFOCUS?).
Maybe you can workaround it if you query GetFocus() when EN_KILLFOCUS arrives and compare it with check box's handle. I don't have time to test it, and I'm not sure about the outcome -- whether it will retrieve check box's handle or edit box's handle.
Another idea that comes to my mind is to "delay" the decision what to do on EN_KILLFOCUS by reference-counting messages. I mean something like:
Code:
LOGICAL, SAVE:: bFocusKilled = .FALSE. INTEGER, SAVE:: iMessageCount = 0 ... IF (bFocusKilled) THEN iMessageCount = iMessageCount+1 IF (iMessageCount > 5) THEN iMessageCount = 0 !Do your normal EN_KILLFOCUS processing here END IF END IF SELECT CASE(Msg) .... CASE(EN_KILLFOCUS) !Set this message for "delayed" processing in the block above bFocusKilled = .TRUE. iMessageCount = 0 ... CASE(BN_CLICKED) !If BN_CLICKED is in the following, say, 5 messages, cancel !the "delayed" processing bFocusKilled = .FALSE. iMessageCount = 0
(I won't be able to reply for the following two weeks. Hope this helps)
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the info about PeekMessage andGetFocus(). GetFocus works fine:
case (EN_KILLFOCUS)
-----
hWnd = GetFocus()
if(hWnd .EQ. hCheck2) then
iret SendMessage(hDlg, WM_COMMAND, MakewParam(0, BN_CLICKED), hCheck2)
end if
I thought that the BN_CLICKED notification message would be processed twice by the Dlg Proc: oncefor the message from the Checkbox control, and oncefor theSendMessage() above. However, only one execution of the code under case(BN_CLICKED) occurred, interesting!
Other than the SDK, is there anotherdiscussion on how Windows handles messages? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, note that your code willnot work correctlyif you use keyboard instead of mouse for navigation through the dialog. If you press Alt+CheckBoxMnemonic, or use Tab key, the edit box will lose focus and the checkbox will gain it, but it won't actually get clicked.
I'm not sure about the effect you see on BN_CLICKED -- I'd expect it to be received twice as well. You can use Spy++ and watch the messages coming to the dialog to see what's going on, and/or place a breakpoint in the debugger.
The SDK is the most comprehensive source you can find, but sometimes even it is vague on certain aspects (for example, EN_KILLFOCUS does not say which control still has the focus on the time of message arrival). The info on sent/posted messages is hidden in the first sentence of every description -- "The WM_BLAHBLAH message is sent/posted...". In any case, the best place for asking related questions is comp.os.ms-windows.programmer.win32 Usenet group, which has also a webinterface on Googleif you don't have direct Usenet access.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for theinfo on comp.os.ms-windows.programmer.win32 Usenet group. Also,yourcode example forcounting messages in your first replywas very helpful.

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