Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog listboxes empty on re-call dialog
#1
I am sorry to have to paste the code here, but I am completely baffled why this is happening.
The first code is a dialog in which the user can set: Font, Color, Font size, Bold/Normal.
The second code is a very simple dialog with one button, if that button is pressed the above described dialog opens.

The first time you press the button, it works like expected.
When you close (cancel / ok /top right X click) and then press the button a second time, the 2 listboxes are empty!

I assume that it may be the thread global defined containers may be the problem, but I need those containers in the CALLER DIALOG.
I assume that every time you call a dialog, the code under "case WM_INITDIALOG" is always run. This means the FONT DIALOG always begins with a new baseline regarding the thread declared vairables (see under "case WM_INITDIALOG").



;;==================== FONT DIALOG

Function font_changer
Code:
Copy      Help
\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 451 209 "Dialog"
;3 ListBox 0x54230101 0x200 5 7 130 95 ""
;4 Edit 0x54030080 0x200 5 105 442 80 ""
;5 ListBox 0x54230101 0x204 143 7 130 95 ""
;6 Edit 0x54030080 0x200 417 89 24 13 ""
;7 Static 0x54000000 0x0 377 91 38 8 "Size (8-40):"
;8 Button 0x54012003 0x0 376 76 64 10 "Bold"
;9 Edit 0x54030880 0x200 351 2 96 12 ""
;10 Edit 0x54030880 0x200 351 19 96 12 ""
;11 Edit 0x54030880 0x200 351 36 96 13 ""
;12 Edit 0x54030880 0x200 351 52 96 13 ""
;13 Static 0x54000002 0x0 300 4 48 10 "Color:"
;14 Static 0x54000002 0x0 300 20 48 10 "Font:"
;15 Static 0x54000002 0x0 301 38 48 9 "Style:"
;16 Static 0x54000002 0x0 301 54 48 9 "Size:"
;1 Button 0x54030001 0x4 349 191 48 14 "OK"
;2 Button 0x54030000 0x4 399 191 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040301 "*" "" "" ""

str controls = "3 4 5 6 8 9 10 11 12"
str lb3 e4 lb5 e6 c8Bol e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG        
,,int- cur_fontsize=14
,,int- cur_bold=0
,,int- cur_color=0
,,str- cur_font="Courier new"
,,int- lb_col=id(3 hDlg)
,,int- lb_fon=id(5 hDlg)
,,int- bold
,,ARRAY(int)- col_hex.redim
,,ARRAY(int)- col_r.redim
,,ARRAY(int)- col_g.redim
,,ARRAY(int)- col_b.redim
,,ARRAY(str)- col_str.redim
,,str- get_fonts=""
,,int- selcol=0
,,int- selfon=0
,,__Font-- f
,,
,,;; LISTBOX: color
,,sub.ColorList        
,,_s=col_str
,,TO_CBFill lb_col _s 1
,,_s="Black"        
,,LB_SelectString(lb_col _s)
,,selcol=LB_SelectedItem(lb_col) ;; Get the selected item#

,,
,,;; LISTBOX: font        
,,GetFonts(get_fonts)
,,TO_CBFill lb_fon get_fonts 1
,,LB_SelectString(lb_fon cur_font)
,,selfon=LB_SelectedItem(lb_fon 0)

,,;; FONT and SIZE of PREVIEW INPUTFIELD "Test 123 QuickMacros"
,,f.Create(cur_font cur_fontsize 0)
,,f.SetDialogFont(hDlg "4")
,,_s="Test 123 QuickMacros"
,,_s.setwintext(id(4 hDlg))

,,;; TEXTCOLOR of PREVIEW INPUTFIELD "Test 123 QuickMacros"
,,DT_SetTextColor hDlg col_hex[selcol] "4"  ;; 'Black' is selected, so the corresponding HEX value can now be used

,,;; TOP LEFT READ ONLY INPUTFIELDS, PUT THE DEFAULT VALUES IN THEM
,,_s="Black"
,,_s.setwintext(id(9 hDlg))        
,,cur_font.setwintext(id(10 hDlg))
,,_s="Normal"
,,_s.setwintext(id(11 hDlg))
,,_s=cur_fontsize
,,_s.setwintext(id(12 hDlg))

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL

,case LBN_SELCHANGE<<16|3 ;; COLOR    
,,selcol=LB_SelectedItem(lb_col _s)
,,DT_SetTextColor hDlg col_hex[selcol] "4"  ;; ,DT_SetTextColor hDlg 0x008000 "4"
,,cur_color=col_hex[selcol]        
,,col_str[selcol].setwintext(id(9 hDlg))

,case LBN_SELCHANGE<<16|5 ;; FONT
,,selfon=LB_SelectedItem(lb_fon)
,,cur_font.getl(get_fonts selfon)
,,f.Create(cur_font 14 0)
,,f.SetDialogFont(hDlg "4")
,,cur_font.getl(get_fonts selfon)
,,cur_font.setwintext(id(10 hDlg))
,,

,case 8 ;; BOLD or NORMAL (checkbox)        
,,selfon=LB_SelectedItem(lb_fon)
,,cur_font.getl(get_fonts selfon)
,,cur_bold=but(8 hDlg) ;; chk get val
,,f.Create(cur_font cur_fontsize cur_bold)
,,f.SetDialogFont(hDlg "4")
,,if(cur_bold=1)
,,,_s="Bold"
,,else
,,,_s="Normal"
,,_s.setwintext(id(11 hDlg))
,,
,,
,case EN_CHANGE<<16|6 ;;SIZE (text inputfield)
,,selfon=LB_SelectedItem(lb_fon)
,,_s.getwintext(id(6 hDlg))
,,cur_fontsize=val(_s)
,,if(cur_fontsize>8&&cur_fontsize<40)
,,,f.Create(cur_font cur_fontsize cur_bold)
,,else
,,,cur_fontsize=14
,,f.SetDialogFont(hDlg "4")
,,_s=cur_fontsize
,,_s.setwintext(id(12 hDlg))
ret 1

#sub ColorList v

ARRAY(int)- col_hex
ARRAY(int)- col_r
ARRAY(int)- col_g
ARRAY(int)- col_b
ARRAY(str)- col_str


str list_col=
;Black|000000|0,0,0
;White|FFFFFF|255,255,255
;Red|FF0000|255,0,0
;Lime|00FF00|0,255,0
;Blue|0000FF|0,0,255
;Yellow|FFFF00|255,255,0
;Cyan / Aqua|00FFFF|0,255,255
;Magenta / Fuchsia|FF00FF|255,0,255
;Silver|C0C0C0|192,192,192
;Gray|808080|128,128,128
;Maroon|800000|128,0,0
;Olive|808000|128,128,0
;Green|008000|0,128,0
;Purple|800080|128,0,128
;Teal|008080|0,128,128
;Navy|000080|0,0,128

list_col.ListSort(6)

foreach _s list_col    
,ARRAY(str) list_col_split
,tok _s list_col_split -1 "|"
,
,;; Put colorname in container ('red' , 'green' , ...etc..)
,col_str[]=list_col_split[0]    

,;; Transform the HEX value of the color defined in "list_col" to an correct QM value.
,;; The values in "list_col" are copied from a website, they must be reversed first to usable in QM.
,;; example; in website: FF 00 C0, in QM reversed: C0 00 FF =>  C000FF
,str hex1.left(list_col_split[1] 2)
,str hex2.get(list_col_split[1] 2 2)
,str hex3.right(list_col_split[1] 2)    
,col_hex[]=val(F"0x{hex3}{hex2}{hex1}")

,;; Although overkill, I put the RGB values in seperate array containers.
,ARRAY(str) rgb_col_split
,tok list_col_split[2] rgb_col_split -1 ","
,col_r[]=val(rgb_col_split[0])
,col_g[]=val(rgb_col_split[1])
,col_b[]=val(rgb_col_split[2])

;;==================== CALLER DIALOG

Function font_changer_caller
Code:
Copy      Help
\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 63 "Dialog"
;3 Button 0x54032000 0x0 55 12 94 32 "font changer"
;END DIALOG
;DIALOG EDITOR: "" 0x2040301 "*" "" "" ""

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 IDOK
,case IDCANCEL
,case 3 ;; font changer
,,font_changer
ret 1
#2
Yes, the thread variables possibly is the reason.
QM thread variables behave like local static variables in C/C++:
int- cur_fontsize=14 ;;=14 is executed once
int- cur_fontsize; cur_fontsize=14 ;;use this
#3
Thank you for your feedback on this!


Forum Jump:


Users browsing this thread: 1 Guest(s)