Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merge the code for the two dialog functions
#1
Hi,
I created two dialog functions, function A and function B
The code of these two functions differs only in two places:

1.Title bar text (Line 1)
2.The value of the _s variable in subfunction right_menu (Line 56)

I want to merge the same part of the two codes into one function, so that it will be convenient to modify it

Thanks in advance for any advice and help
david


Function A
 
Code:
Copy      Help
str t="A"

str dd=
F
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "{t}_Dialog" "4"
;3 Edit 0x54030080 0x200 68 52 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SetTimer hDlg 1 100 0 ;;Edit
,case WM_TIMER
,sel wParam
,,case 1 ;;Edit
,,int ec=id(3 hDlg); if(ec=0) ret
,,SetWindowSubclass(ec &sub.WndProc_Subclass_Edit 3 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass_Edit ;;Edit
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_CONTEXTMENU
,sub.right_menu hwnd
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass_Edit uIdSubclass)
ret R

#sub right_menu
function hwnd
str s=
;1 1    A test1
;2 2    A test2
;3 3    A test3

MenuPopup m.AddItems(s)
int i=m.Show
str s1 s2
if(i and m.GetItemText(i s1 s2))
,EditReplaceSel hwnd 0 s2 1|2|4

Function B
Code:
Copy      Help
str t="B"

str dd=
F
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "{t}_Dialog" "4"
;3 Edit 0x54030080 0x200 68 52 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SetTimer hDlg 1 100 0 ;;Edit
,case WM_TIMER
,sel wParam
,,case 1 ;;Edit
,,int ec=id(3 hDlg); if(ec=0) ret
,,SetWindowSubclass(ec &sub.WndProc_Subclass_Edit 3 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass_Edit ;;Edit
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_CONTEXTMENU
,sub.right_menu hwnd
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass_Edit uIdSubclass)
ret R

#sub right_menu
function hwnd
str s=
;1 1    B test1
;2 2    B test2
;3 3    B test3

MenuPopup m.AddItems(s)
int i=m.Show
str s1 s2
if(i and m.GetItemText(i s1 s2))
,EditReplaceSel hwnd 0 s2 1|2|4


Messages In This Thread
Merge the code for the two dialog functions - by Davider - 12-25-2022, 04:57 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)