Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom control event
#1
the controls in the dialog box, some events are not available, can I customize? How to achieve Huh

E.g,
Right click on the button to pop up a message box
Right click on the item in the combo box to pop a message box

Any suggestions are welcome, I hope someone can provide an example, thanks in advance



Function Macro2
Code:
Copy      Help
str s=
;one
;two
;three
;four

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Button 0x54032000 0x0 116 52 100 14 "Right click on the popup"
;4 ComboBox 0x54230641 0x0 8 8 96 120 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
You will need to subclass the controls. You have been shown how before.
#3
I found the subclass here, but the code is a bit hard to understand. Can you provide the above example?  Smile

http://www.quickmacros.com/forum/showthr...t=subclass
#4
Function DialogSubclassExample
Code:
Copy      Help
str s=
;one
;two
;three
;four

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Win Dialog subclass example"
;3 Button 0x54032000 0x0 116 52 100 14 "Right click on the popup"
;4 ComboBox 0x54230641 0x0 8 8 96 120 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int hbc=id(3 hDlg)
,int hcbc=child("" "ComboLBox" id(4 hDlg) 0x0 "id=1000") ;;list
,SetWindowSubclass hbc &sub.WndProc_Subclass 1 0
,SetWindowSubclass hcbc &sub.WndProc_Subclass 1 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong. Example: SetWindowSubclass(hwnd &sub.WndProc_Subclass 1 0)

;OutWinMsg message wParam lParam _s _i ;;uncomment to see received messages
sel message
,case WM_RBUTTONUP
,Acc a.FromMouse
,int mi=iif((a.elem<>0) 2 1)
,mac "sub.rcmessage" "" mi
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass) ;;replace ThisFunction with the name of this function or subfunction (eg sub.WndProc_Subclass)
,;case ...

ret R

#sub rcmessage 
function i
sel i
,case 1
,mes("button was right clicked")
,case 2
,mes("combo list was right clicked")
#5
very good  Smile

I have a question, Press the right button on the list box item, but there is no selected item,

can select it, and then pop up the text of the item ?
#6
#1 you didn't say or ask how to select it
#7
Right click and select it  at the same time   Shy

I added some code, but still don't implement the right click function.  Sad
 
Code:
Copy      Help
 
#sub rcmessage
function i
sel i
case 1
_s.getwintext(id(4 hDlg))
mac+ _s
case 2
_s.getwintext(id(4 hDlg))
mac+ _s

Macro Run or open Func
Code:
Copy      Help
out

QMITEM qmac; int imac
ARRAY(str) amac
rep
,imac=qmitem(-imac 2 &qmac 1)
,if(imac=0) break
,if qmac.itype=1
,,amac[]=qmac.name

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 174 132 "Win Dialog subclass example"
;3 Button 0x54032000 0x0 22 110 132 14 "Click Run | Right Click Open"
;4 ComboBox 0x54230641 0x0 7 22 158 78 ""
;5 Static 0x54000000 0x0 8 8 160 12 "Double-click run function | right click open function"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=amac
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int hbc=id(3 hDlg)
,int hcbc=child("" "ComboLBox" id(4 hDlg) 0x0 "id=1000") ;;list
,SetWindowSubclass hbc &sub.WndProc_Subclass 1 0
,SetWindowSubclass hcbc &sub.WndProc_Subclass 1 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3 ;;Click Run Function
,_s.getwintext(id(4 hDlg))
,mac _s
,
,case CBN_DBLCLK<<16|4
,_s.getwintext(id(4 hDlg))
,mac _s

ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong. Example: SetWindowSubclass(hwnd &sub.WndProc_Subclass 1 0)

;OutWinMsg message wParam lParam _s _i ;;uncomment to see received messages
sel message
,case WM_RBUTTONUP
,Acc a.FromMouse
,int mi=iif((a.elem<>0) 2 1)
,mac "sub.rcmessage" "" mi
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass) ;;replace ThisFunction with the name of this function or subfunction (eg sub.WndProc_Subclass)
,;case ...

ret R

#sub rcmessage
function i
sel i
,case 1
,;_s.getwintext(id(4 hDlg))
,mac+ _s
,
,case 2
,;_s.getwintext(id(4 hDlg))
,mac+ _s
#8
Function DialogSubclassExample
Code:
Copy      Help
out
QMITEM qmac; int imac
ARRAY(str) amac
rep
,imac=qmitem(-imac 2 &qmac 1)
,if(imac=0) break
,if qmac.itype=1
,,amac[]=qmac.name

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Win Dialog subclass example"
;3 Button 0x54032000 0x0 116 52 100 14 "Right click on the popup"
;4 ComboBox 0x54230641 0x0 8 8 96 120 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=amac
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int hbc=id(3 hDlg)
,int hcbc=child("" "ComboLBox" id(4 hDlg) 0x0 "id=1000") ;;list
,SetWindowSubclass hbc &sub.WndProc_Subclass 1 0
,SetWindowSubclass hcbc &sub.WndProc_Subclass 1 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong. Example: SetWindowSubclass(hwnd &sub.WndProc_Subclass 1 0)

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_RBUTTONUP
,Acc a.FromMouse
,int rcrn=a.Role
,str rcitem=a.Name
,if rcrn=34
,,int rccbh=a.Hwnd
,,int rciti= a.elem -1
,,mac "sub.rcmessage" "" rcrn rcitem rciti rccbh
,else
,,mac "sub.rcmessage" "" rcrn rcitem
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass) ;;replace ThisFunction with the name of this function or subfunction (eg sub.WndProc_Subclass)
,;case ...

ret R

#sub rcmessage 
function i [~item][itemindex][chwnd]
str mtext
sel i
,case 43:
,mtext="button was right clicked"
,case 34:
,,;mtext.format("combo list item: (%s) was right clicked" item)
,,CB_SelectItem(chwnd itemindex)
,,mac+ item
,case 33:
,,mtext="combo list was right clicked on an empty item"
if(!empty(mtext))
,mes(mtext)
#9
Cannot compile


Attached Files Image(s)
   
#10
Seems your qm doesn't like optional function parameters .
What qm version are you using?

try this 

Function DialogSubclassExample
Code:
Copy      Help
out
QMITEM qmac; int imac
ARRAY(str) amac
rep
,imac=qmitem(-imac 2 &qmac 1)
,if(imac=0) break
,if qmac.itype=1
,,amac[]=qmac.name

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Win Dialog subclass example"
;3 Button 0x54032000 0x0 116 52 100 14 "Right click on the popup"
;4 ComboBox 0x54230641 0x0 8 8 96 120 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=amac
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int hbc=id(3 hDlg)
,int hcbc=child("" "ComboLBox" id(4 hDlg) 0x0 "id=1000") ;;list
,SetWindowSubclass hbc &sub.WndProc_Subclass 1 0
,SetWindowSubclass hcbc &sub.WndProc_Subclass 1 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong. Example: SetWindowSubclass(hwnd &sub.WndProc_Subclass 1 0)

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_RBUTTONUP
,Acc a.FromMouse
,int rcrn=a.Role
,str rcitem=a.Name
,if rcrn=34
,,int rccbh=a.Hwnd
,,int rciti= a.elem -1
,,mac "sub.rcmessage" "" rcrn rcitem rciti rccbh
,else
,,mac "sub.rcmessage" "" rcrn rcitem
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass) ;;replace ThisFunction with the name of this function or subfunction (eg sub.WndProc_Subclass)
,;case ...

ret R

#sub rcmessage 
function# i [~item][#itemindex][#chwnd]
str mtext
sel i
,case 43:
,mtext="button was right clicked"
,case 34:
,,;mtext.format("combo list item: (%s) was right clicked" item)
,,CB_SelectItem(chwnd itemindex)
,,mac+ item
,case 33:
,,mtext="combo list was right clicked on an empty item"
if(!empty(mtext))
,mes(mtext)

and if still error try this
 Function DialogSubclassExample
Code:
Copy      Help
out
QMITEM qmac; int imac
ARRAY(str) amac
rep
,imac=qmitem(-imac 2 &qmac 1)
,if(imac=0) break
,if qmac.itype=1
,,amac[]=qmac.name

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Win Dialog subclass example"
;3 Button 0x54032000 0x0 116 52 100 14 "Right click on the popup"
;4 ComboBox 0x54230641 0x0 8 8 96 120 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=amac
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,;int hbc=id(3 hDlg)
,int hcbc=child("" "ComboLBox" id(4 hDlg) 0x0 "id=1000") ;;list
,;SetWindowSubclass hbc &sub.WndProc_Subclass 1 0
,SetWindowSubclass hcbc &sub.WndProc_Subclass 1 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong. Example: SetWindowSubclass(hwnd &sub.WndProc_Subclass 1 0)

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_RBUTTONUP
,Acc a.FromMouse
,int rcrn=a.Role
,str rcitem=a.Name
,if rcrn=34
,,int rccbh=a.Hwnd
,,int rciti= a.elem -1
,,mac "sub.rcmessage" "" rcrn rcitem rciti rccbh
,;else
,,;mac "sub.rcmessage" "" rcrn rcitem
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass) ;;replace ThisFunction with the name of this function or subfunction (eg sub.WndProc_Subclass)
,;case ...

ret R

#sub rcmessage 
function# i ~item #itemindex #chwnd
str mtext
sel i
,case 43:
,mtext="button was right clicked"
,case 34:
,,;mtext.format("combo list item: (%s) was right clicked" item)
,,CB_SelectItem(chwnd itemindex)
,,mac+ item
,case 33:
,,mtext="combo list was right clicked on an empty item"
if(!empty(mtext))
,mes(mtext)

and if your not using the latest qm please update qm and try again. Latest version is 2.4.8.2

can be found here http://www.quickmacros.com/download.html
#11
I am using 2.4.8.1,   I will update later,   Thank you for your reminders and help

With the new version, there are still errors


Attached Files Image(s)
   
#12
you didn't try the versions for testing posted above try both versions posted?
#13
The second piece of code is available, but I added a right click to the button and it does not take effect.
 
Code:
Copy      Help
 
case 43:
mtext="button was right clicked"
mac+ item
#14
because i disabled it for testing
#15
In addition, right-click on the item in the list box to open the function, but when opened, the item is not selected.

I don't understand the number 43 34 Where did it come from? Huh
#16
dont understand what your saying sorry
#17
I hope that when I right click on the item, It will select the item first and then open it.
#18
this code would fail  every time. You can't run a dialog button text. In this case item is just the name of the button.
case 43:
mtext="button was right clicked"
mac+ item
#19
case 43:

    case 34:

I don't understand why it would be 43 34 instead of 4 3
#20
"I hope that when I right click on the item, It will select the item first and then open it."
it does that it just happens so fast you dont see it cause qm window covers dialog window

you need to look at the code above and figure out where the numbers are coming from
#21
Now, right click on the button and won't open function 6 , why  Huh


Attached Files Image(s)
   
#22
because you don't understand the code at all .I explained above that you cannot use mac + in case 43 as the value of item in that case is the button name.

and also the button is not programed to do anything other than popup a message. And in the code your using the button subclassing is disabled
#23
Still don't understand, I have changed the content of the comment to normal.

 in case 43 as the value of item in that case is the button name.

I don't understand this sentence, how write code?
#24
I reinstalled the English version of the system and QM2.8.2, the following code, still prompts an error

Function DialogSubclassExample
Code:
Copy      Help
out
QMITEM qmac; int imac
ARRAY(str) amac
rep
,imac=qmitem(-imac 2 &qmac 1)
,if(imac=0) break
,if qmac.itype=1
,,amac[]=qmac.name

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Win Dialog subclass example"
;3 Button 0x54032000 0x0 116 52 100 14 "Right click on the popup"
;4 ComboBox 0x54230641 0x0 8 8 96 120 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "4"
str cb4
cb4=amac
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int hbc=id(3 hDlg)
,int hcbc=child("" "ComboLBox" id(4 hDlg) 0x0 "id=1000") ;;list
,SetWindowSubclass hbc &sub.WndProc_Subclass 1 0
,SetWindowSubclass hcbc &sub.WndProc_Subclass 1 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong. Example: SetWindowSubclass(hwnd &sub.WndProc_Subclass 1 0)

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_RBUTTONUP
,Acc a.FromMouse
,int rcrn=a.Role
,str rcitem=a.Name
,if rcrn=34
,,int rccbh=a.Hwnd
,,int rciti= a.elem -1
,,mac "sub.rcmessage" "" rcrn rcitem rciti rccbh
,else
,,mac "sub.rcmessage" "" rcrn rcitem
int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass) ;;replace ThisFunction with the name of this function or subfunction (eg sub.WndProc_Subclass)
,;case ...

ret R

#sub rcmessage
function# i [~item][#itemindex][#chwnd]
str mtext
sel i
,case 43:
,mtext="button was right clicked"
,case 34:
,,;mtext.format("combo list item: (%s) was right clicked" item)
,,CB_SelectItem(chwnd itemindex)
,,mac+ item
,case 33:
,,mtext="combo list was right clicked on an empty item"
if(!empty(mtext))
,mes(mtext)


Attached Files Image(s)
   


Forum Jump:


Users browsing this thread: 1 Guest(s)