Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text color control in dialog initiated by a button
#1
In the dialog that follows button-3 starts a long calculation procedure, simulated in the example by a wait statement for 5s. Before that, a static message is displayed and also the color of the font of another static control has to be changed. Nevertheless, the later occurs only when the 5s holding period is finished. I welcome any advice or guidance to overcome this peculiar behavior. Many thanks in advance.

Function Dialog32_Buttons_Control
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 195 108 "Dialog"
;3 Button 0x54032000 0x0 19 18 48 14 "Button-3"
;4 Button 0x54032000 0x0 83 18 48 14 "Button-4"
;5 Static 0x54000000 0x0 59 57 48 12 "Text"
;6 Static 0x54000000 0x0 20 2 48 12 "Busy"
;1 Button 0x54030001 0x4 77 90 48 14 "OK"
;2 Button 0x54030000 0x4 135 90 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

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


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,DT_SetTextColor(hDlg 0xFF0000 "6")    

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,EnableWindow(id(4, hDlg) 0)

,DT_SetTextColor(hDlg 170 "6")    
,_s="Started"
,_s.setwintext(id(5 hDlg))
,5
,_s="Ended"
,_s.setwintext(id(5 hDlg))
;,DT_SetTextColor(hDlg 0xFF0000 "6")    
,EnableWindow(id(4, hDlg) 1)
,
,case 4
,_s="Continue"
,_s.setwintext(id(5 hDlg))
,
,
,case IDOK
,case IDCANCEL
ret 1
#2
This works as I wish. However, I am still wondering whether this is the proper solution :

Function Dialog32_Buttons_Control2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 195 108 "Dialog"
;3 Button 0x54032000 0x0 19 18 48 14 "Button-3"
;4 Button 0x54032000 0x0 83 18 48 14 "Button-4"
;5 Static 0x54000000 0x0 59 57 48 12 "Text"
;6 Static 0x54000000 0x0 20 2 48 12 "Busy"
;1 Button 0x54030001 0x4 77 90 48 14 "OK"
;2 Button 0x54030000 0x4 135 90 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

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


#sub DlgProc
function# hDlg message wParam lParam
,
sel message
,case WM_INITDIALOG
,DT_SetTextColor(hDlg 0xFF0000 "6")    

,case WM_DESTROY
,case WM_COMMAND goto messages2

,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,out "sta"
,,5
,,out "end"
,,_s="Ended"
,,_s.setwintext(id(5 hDlg))
,,DT_SetTextColor(hDlg 0xFF0000 "6")    
,,EnableWindow(id(4, hDlg) 1)

ret



;messages2
;OutWinMsg message wParam lParam

sel wParam
,case 3
,EnableWindow(id(4, hDlg) 0)

,DT_SetTextColor(hDlg 170 "6")    
,_s="Started"
,_s.setwintext(id(5 hDlg))
,SetTimer hDlg 1 1000 0

,
,
,case 4
,_s="Continue"
,_s.setwintext(id(5 hDlg))


,case IDOK
,case IDCANCEL
ret 1
#3
Most painting in windows occurs asynchronously, when the window gets WM_PAINT. But it cannot get messages if blocked by some calculations or wait, unless the calculation processes messages or the wait is preceded by opt waitmsg 1.

for i 0 1000
,0 ;;'wait 0' means "process messages"
,...

But in most cases it's better to do that calculations in another thread.
#4
Thank you for your advice. I am sorry to ask whether the WM_TIMER method is sufficient. Could you also explain what do you mean "another thread". Is it likely that you mean issuing a "mac ..." command and signaling its completion somehow to the main code?
#5
Don't need timer, just insert

0

before calculations. It processes WM_PAINT.

Easiest code with thread:

,opt waitmsg 1
,wait 0 H mac("sub.Thread")
#6
Perfect, many thanks!


Forum Jump:


Users browsing this thread: 1 Guest(s)