Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing variable values to a Dialog
#1
Hi Gintaras,
I am trying to figure out how to pass variables to a smart dialog (e.g. the calling windows Hwnd for purposes of parent and some string variable). The problem is that the dlgproc already uses the function line

Code:
Copy      Help
function# hDlg message wParam lParam

so I can't pass anything in with the initial call like I would like to such as:

Code:
Copy      Help
mac "SampleDlg" 0 CallingHwnd SomeStrVar

I see that this is handled in a sub in the latest versions of QM

Code:
Copy      Help
#sub DlgProc
function# hDlg message wParam lParam

but unfortunately I haven't been able to update past 2.3.6.5 yet.

Is there another way you can suggest?
Thanks,
S
#2
Need 2 functions.

Function Dialog161
Code:
Copy      Help
function a b

if(!ShowDialog("Dialog161_2" &Dialog161_2 0)) ret
Function Dialog161_2
Code:
Copy      Help
;\Dialog_Editor
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

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0 "*" "" "" ""
#3
then to pass the variables into the Dlg control - like for use in various case statements (not controls), the only way I see is to re-define them as non-private thread-scope variables. Is this the correct way?
S

Macro Macro100
Code:
Copy      Help
int i = 100
str s = "Foo"
mac "CallTestDlg" 0  i s

Function CallTestDlg
Code:
Copy      Help
function i str's
int- tTestInt = i
str- tTestStr = s
str controls = "3"
str c3Che
if(!ShowDialog("TestDlg" &TestDlg &controls)) ret


Function TestDlg
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

int- tTestInt
str- tTestStr

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54012003 0x0 40 48 48 10 "Check"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,,mes F"{tTestInt} {tTestStr}"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#4
It is one of ways.
Another - ShowDialog ... param, and DT_GetParam.

Macro Macro2508
Code:
Copy      Help
Dialog161 5 "fff"
Function Dialog161
Code:
Copy      Help
function a str'b

type VARIABLES10387 a str'b
VARIABLES10387 x; x.a=a; x.b=b

if(!ShowDialog("Dialog161_2" &Dialog161_2 0 0 0 0 0 &x)) ret
Function Dialog161_2
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam

VARIABLES10387& x=+DT_GetParam(hDlg)
sel message
,case WM_INITDIALOG
,out x.a
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,out x.b
,case IDCANCEL
ret 1

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0 "*" "" "" ""

With #sub DlgProc v would be much easier, then DlgProc simply can use main function's variables.
#5
Yes I see. Thanks! Hopefully will be able to update to use subs soon.
S
#6
thanks again. I have read the ShowDialog page so many times in the Help Menu but somehow skipped over the [param] parameter for passing vales to dialog procedure usign DT_GetParam. Always amazed how much there was in QM from the beginning and how much has been added!!!!!

The syntax for the following line of code:

Code:
Copy      Help
VARIABLES10387& x=+DT_GetParam(hDlg)

confused me but I finally spent time understanding the difference between Pointers and Reference Varaiables that you describe so well in QM Help and also its relevance to Passing and returning strings, arrays in user-defined functions also described in help section.

I think I finally get the significance (and implications) of all the little '&*+ modifiers that I have been using uncomprehendingly all these years as I based my code on your samples....now I get (a little better) why you prefer lpstr, etc.

Thanks again for teaching me so much!!!
S


Forum Jump:


Users browsing this thread: 1 Guest(s)