In a data entry dialog, the label controls are used to inform the user about the purpose
of the edit field. They also provide the mnemonic that is used to set the focus to the
edit field when the user presses the Alt+<mnemonic> keys. In order for the correct edit
field to receive the focus when the user presses the mnemonic, the edit control is created
immediately after its associated label.
This means that if the dialog is laid out properly, the subclass procedure would look like
that shown below.
The same logic can be used for EN_SETFOCUS/EN_KILLFOCUS.
Note:
g_hFontBold -> global variable for bold font
g_hFont -> global variable for normal font
Code:
FUNCTION SubclassProc _ ( _ BYVAL hWnd AS DWORD, _ ' control handle BYVAL uMsg AS DWORD, _ ' type of message BYVAL wParam AS DWORD, _ ' first message parameter BYVAL lParam AS LONG _ ' second message parameter ) EXPORT AS LONG LOCAL hWndLabel AS DWORD LOCAL lpOldWndProc AS DWORD ' address of original window procedure lpOldWndProc = GetProp(hWnd, "OLDWNDPROC") SELECT CASE uMsg CASE %WM_SETFOCUS hWndLabel = GetWindow(hWnd, %GW_HWNDPREV) SendMessage hWndLabel, %WM_SETFONT, g_hFontBold, %TRUE CASE %WM_KILLFOCUS hWndLabel = GetWindow(hWnd, %GW_HWNDPREV) SendMessage hWndLabel, %WM_SETFONT, g_hFont, %TRUE CASE %WM_DESTROY ' Remove control subclassing SetWindowLong hWnd, %GWL_WNDPROC, RemoveProp(hWnd, "OLDWNDPROC") END SELECT FUNCTION = CallWindowProc(lpOldWndProc, hWnd, uMsg, wParam, lParam) END FUNCTION
Leave a comment: