Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting data from dialog controls without closing the dialog
#1
Sorry Ken, I accidentally deleted your message. You wrote:
Quote:im trying to get a little list of things into a dialoge box that reads from a text file. i want to add items to that list within the dialoge form and save it with a button click but i cant seem to send the form contents back to the macro with out causing the dialoge to close (sending the string back to the macro, doing a setfile command, and then restarting just before the dialoge initialization line). heres my dialoge code; how do i change it just to do a save?

Code:
Copy      Help
;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 92 118 "Form"
;3 Edit 0x54231044 0x204 0 0 88 98 ""
;1 Button 0x54030001 0x4 6 102 40 14 "Save"
;2 Button 0x54030000 0x4 52 102 34 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2010703 "" ""


ret
;messages
sel message
,case WM_INITDIALOG DT_Init(hDlg lParam); ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 1 e3.setfile("C:\qm\projects.txt")

,case IDCANCEL DT_Cancel hDlg
ret 1


thanks


______________________________________________

Method 1
In the dialog procedure, use str.getwintext or other functions to get data from the edit control, as well as from other controls you need.

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

str controls = "3"
str e3
if(!ShowDialog("ken_gray_dialog" &ken_gray_dialog &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 4 4 96 14 ""
;4 Button 0x54032000 0x0 118 116 48 14 "Save"
;END DIALOG
;DIALOG EDITOR: "" 0x2010703 "*" ""


ret
;messages
sel message
,case WM_INITDIALOG DT_Init(hDlg lParam); ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4 ;;Save
,str s.getwintext(id(3 hDlg))
,s.setfile("C:\qm\projects.txt")
,
,case IDCANCEL DT_Cancel hDlg
ret 1

Method 2
Use an user-defined type for dialog controls. Set its name in Dialog Editor Options. In the dialog procedure, call DT_GetControls(hDlg). This function retrieves data from dialog controls in the same way and format as when you click OK. It returns pointer to the variable that was passed to ShowDialog, so you can assign it to a reference variable of that type. This method is is better if you have many controls to get data from, or if you don't know how to explicitly get data from particular controls.

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

type KEN_GRAY_DIALOG2 ~controls ~e3 ~c5Che
KEN_GRAY_DIALOG2 d.controls="3 5"
if(!ShowDialog("ken_gray_dialog2" &ken_gray_dialog2 +&d)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;2 Button 0x54030001 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x204 4 4 96 14 ""
;4 Button 0x54032000 0x4 118 116 48 14 "Save"
;5 Button 0x54012003 0x4 6 32 48 13 "Check"
;END DIALOG
;DIALOG EDITOR: "KEN_GRAY_DIALOG2" 0x2010703 "*" ""


ret
;messages
sel message
,case WM_INITDIALOG DT_Init(hDlg lParam); ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4 ;;Save
,KEN_GRAY_DIALOG2& dd=DT_GetControls(hDlg)
,out dd.e3
,out dd.c5Che
,;dd.e3.setfile("C:\qm\projects.txt")
,
,case IDCANCEL DT_Cancel hDlg
ret 1

Whenever you add or remove controls, QM shows a warning message box, because the type definition is changed. In most cases you can safely click OK.
#2
:lol:

Thanks.
BTW: i made some changes to make it multilne and to show me the entire text file in multi-line text field so i can edit the entire file at once.

i would like it to put the cursor at the bottom of the list (rather than the cancel button) however, it selects the entire text rather than just moving the cursor to the bottom ready for the next entry. how can i do this?

Code:
Copy      Help
;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 99 64 "Form"
;5 Edit 0x54231044 0x204 0 0 98 48 ""
;2 Button 0x54030001 0x4 52 50 48 14 "Cancel"
;4 Button 0x54032000 0x4 2 50 48 14 "Save"
;END DIALOG
;DIALOG EDITOR: "" 0x2010703 "*" ""
#3
On WM_INITDIALOG, set focus to the edit control, set selection, and return 0.

Code:
Copy      Help
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,int hedit=id(3 hDlg)
,SetFocus hedit
,SendMessage hedit EM_SETSEL -2 -2
,SendMessage hedit WM_VSCROLL 7 0 ;;def SB_BOTTOM 7
,ret
#4
awesome!

works great!

thanks


Forum Jump:


Users browsing this thread: 1 Guest(s)