Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subclass "uIdSubclass" parameter
#1
Currently I subclass a buttons like this:
SetWindowSubclass(id(50 hDlg) &sub.WndProc_Subclass_buttons 1 0)
SetWindowSubclass(id(51 hDlg) &sub.WndProc_Subclass_buttons 1 0)
...etc

Questions:
1)
Is the above way the correct method regarding the "uIdSubclass" parameter?  (which is "1", see above.)
I am asking this because I want to pass the control ID in "uIdSubclass" so I can use it in the subfunction (see question 2)
(And probably I was using subclassing incorrect?)

2)
Can I subclass like this?
SetWindowSubclass(id(50 hDlg) &sub.WndProc_Subclass_buttons 50 0)
SetWindowSubclass(id(51 hDlg) &sub.WndProc_Subclass_buttons 51 0)
(So I can use "uIdSubclass" to store control ID and then use it in subfunction below. And if this is not the correct way to pass control ID to subclass subfunction, is there another way?)


Below the subclass subfunction, where I output the clicked control ID
 
Code:
Copy      Help
#sub WndProc_Subclass_buttons ;;menu File -> New -> Templates -> Wndproc -> WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData
sel message
    case WM_RBUTTONUP
    case WM_RBUTTONDBLCLK
    case WM_MBUTTONUP
    case WM_MBUTTONDBLCLK
    case WM_LBUTTONUP
        out uIdSubclass ;; output the ID of the clicked control ;; <================  here I use the "uIdSubclass"
    case WM_LBUTTONDBLCLK
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
    case WM_NCDESTROY
    RemoveWindowSubclass(hwnd &sub.WndProc_Subclass_buttons uIdSubclass)
ret R
#2
Yes Ron you can subclass like that. Several subclasses can share the same subclass procedure and the ID(uIdSubclass) can identify each call. 

Function DialogButtonSubclassExample
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 32 72 48 14 "Button1"
;4 Button 0x54032000 0x0 96 72 48 14 "Button2"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SetWindowSubclass(id(3 hDlg) &sub.Button_Subclass 3 0)
,SetWindowSubclass(id(4 hDlg) &sub.Button_Subclass 4 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


#sub Button_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData
;OutWinMsg message wParam lParam ;;uncomment to see received messages

sel message
,case WM_LBUTTONDOWN
,sel uIdSubclass
,,case 3
,,out "left click Button1"
,,case 4
,,out "left click Button2"

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.Button_Subclass uIdSubclass) 
,
,;case ...

ret R


in #1 you would have to use something like
Code:
Copy      Help
out GetDlgCtrlID(hwnd)

to see  the id
#3
Ah!
Thank you!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)