Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to have a macro call a case within a dialog
#1
Hi Gintaras,

I have a Dialog which has Button names prefixed with and & so that one can choose to use the keyboard or the mouse. But since this Dialog is also used while playing a MIDI controller I have made these keys available without having to activate the Dialog window using a separate macro for each of these keys. This way one can quickly switch scenarios during a performance, using just one finger press.

While creating this solution, two questions came up:
The code for each key is the same in the Dialog and in the associated macro, so if I change something it has to be done twice. This I could easily be solved this by calling the individual macros from the dialog, however it is so nice to have all the code in one place for an overview while editing the routines.

1-? Is there any possibility to have a macro use code from a case statement inside a Dialog?
2-? Is there a possible solution to have one macro which is triggered by different keys?

Regards,
GertC
#2
Function Dialog196
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog196"
;3 Button 0x54032000 0x0 8 8 48 14 "A"
;4 Button 0x54032000 0x0 64 8 48 14 "B"
;5 Button 0x54032000 0x0 120 8 48 14 "C"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040400 "*" "" "" ""

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


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,out "A"
,
,case 4
,out "B"
,
,case 5
,out "C"
,
,case IDOK
,case IDCANCEL
ret 1

Macro Macro167
Code:
Copy      Help
int w=win("Dialog196" "#32770")
if(!w) ret

int hh=SetWindowsHookEx(WH_KEYBOARD_LL &sub.Hook_WH_KEYBOARD_LL _hinst 0)
opt waitmsg 1
wait 0 -WC w
UnhookWindowsHookEx hh


#sub Hook_WH_KEYBOARD_LL v
function# nCode message KBDLLHOOKSTRUCT&k
if(nCode<0) goto gNext
if(k.flags&(LLKHF_INJECTED|LLKHF_UP)) goto gNext

;FormatKeyString k.vkCode 0 &_s; out _s ;;debug

sel k.vkCode
,case VK_F9
,SendMessage w WM_COMMAND 3 0 ;;button id 3
,ret 1 ;;"eat" the event so that other application would not receive it; remove this if don't need
,
,case VK_F10
,SendMessage w WM_COMMAND 4 0
,ret 1
,
,case VK_F11
,SendMessage w WM_COMMAND 5 0
,ret 1
,
,;case 'A' ;;example for alpha-numeric keys

;gNext
ret CallNextHookEx(0 nCode message &k)

Run the first macro, then second. Then press F9, F10, F11. Will be executed A B C button code. To end both threads, close the dialog.

Note: the case code must be as fast as possible, else keys and dialog will hang etc. Or, if need to wait, use opt waitmsg 1. But better run the long-running code in its own thread (mac).


Forum Jump:


Users browsing this thread: 1 Guest(s)