I'll go first:
While working with the DDT version of Fred's example I ended up with what Elias called "verbose" code. I've posted my reasoning in that thread. Here's the technical issue I think I was dealing with:
Windows sends multiple focus messages through the CALLBACK. Most are not related to any user action. Without resorting to SDK, is there another way to make sure we respond only to the user initiated focus message?
I use HasFocusFlag to track which control currently has focus.
I use the MessageBoxCount to respond only to the first focus message sent by cmdButton2.
While working with the DDT version of Fred's example I ended up with what Elias called "verbose" code. I've posted my reasoning in that thread. Here's the technical issue I think I was dealing with:
Windows sends multiple focus messages through the CALLBACK. Most are not related to any user action. Without resorting to SDK, is there another way to make sure we respond only to the user initiated focus message?
I use HasFocusFlag to track which control currently has focus.
I use the MessageBoxCount to respond only to the first focus message sent by cmdButton2.
Code:
CALLBACK FUNCTION ShowfrmVBConvertProc() STATIC HasFocusFlag AS LONG 'track control with focus STATIC MessageBoxCount AS LONG 'track number of calls to MSGBOX IF HasFocusFlag = %IDC_cmdButton2 THEN 'tracking only MSGBOX calls for button2 INCR MessageBoxCount ELSE MessageBoxCount = 0 END IF SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL 'test for %BN_SETFOCUS message to control the MSGBOX for button2 focus CASE %IDC_cmdButton1 SELECT CASE AS LONG CBCTLMSG CASE %BN_CLICKED CONTROL SET TEXT CBHNDL, %IDC_txtText1, "You Clicked cmdButton1 (the top button)!" CASE %BN_SETFOCUS HasFocusFlag = %IDC_cmdButton1 END SELECT CASE %IDC_cmdButton2 SELECT CASE AS LONG CBCTLMSG CASE %BN_CLICKED CONTROL SET TEXT CBHNDL, %IDC_txtText1, "You Clicked cmdButton2 (the middle button)!" CASE %BN_SETFOCUS HasFocusFlag = %IDC_cmdButton2 INCR MessageBoxCount IF MessageBoxCount = 1 THEN MSGBOX "Button #2 just got a GotFocus message." CONTROL SET FOCUS CBHNDL, %IDC_cmdButton2 ELSE CONTROL SET TEXT CBHNDL, %IDC_txtText1, "You Clicked cmdButton2 (the middle button)!" END IF END SELECT CASE %IDC_cmdButton3 SELECT CASE AS LONG CBCTLMSG CASE %BN_CLICKED CONTROL SET TEXT CBHNDL, %IDC_txtText1, "You Clicked cmdButton3 (the bottom button)!" CASE %BN_SETFOCUS HasFocusFlag = %IDC_cmdButton3 END SELECT CASE %IDC_txtText1 END SELECT END SELECT END FUNCTION
Comment