Home > Archive > dBASE Questions and Answers > December 2006 > interupt a loop by detecting an event on taskbartray.cc









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author interupt a loop by detecting an event on taskbartray.cc
Adam DeVita

2006-12-12, 7:15 pm

Good day,
I have some code that detects a function form event handle waiting so that a loop can be stopped by the user. I would like to minimize the form to the taskbar, using taskbartray.cc .

How can I detect from within my form's continuous loop if the user has clicked on the taskbartray icon?

At the moment, all the taskbar tray events execute AFTER I use the form halt button.
Jean-Pierre Martel

2006-12-12, 7:15 pm

In article <4pGRGSgHHHA.328@news-server>, info@clinsaver.com says...
>
> How can I detect from within my form's continuous loop
> if the user has clicked on the taskbartray icon?


Just guessing: have you tried Form.onGotFocus() ?

Jean-Pierre Martel, editor
The dBASE Developers Bulletin
Blue Star dBASE Plus Core Concepts Graduate
Adam DeVita

2006-12-12, 7:15 pm

Good day,

> Just guessing: have you tried Form.onGotFocus() ?


Yes I have tried using the ongotfocus() event several ways.

I haven't been able to find the example code of the interupt routine that I'm using, so I've copied the related components form my main form below. The objective of the code is to call the monitor functions every 2s to search for and process input data. T
he program stays in the loop unless the Halt button is pressed (this works). The goal is to expand the capacity to halt on the taskbartray so that the program can be started and stopped via the taskbar while the form itself is invisible. Since other form
events are not executed until after the pushbutton3 returns (which it doesn't do), only the halt button stops it.

Monitorform
/* size info etc... left out for brevity*/

// this is taskbartray code copied from the example. (TaskbarTray.zip containing the .CC file, and a sample form can be found in the Binaries news group.)
this.TASKBARTRAY1 = new TASKBARTRAY(this)
with (this.TASKBARTRAY1)
onRightMouseDown = {|flags, col, row| class::DisplayEvent(
"onRightMouseDown", flags, col, row )}
onRightMouseUp = class::TASKBARTRAY1_
ONRIGHTMOUSEUP
height = 22
left = 234
top = 46
width = 28
endwith


this.PUSHBUTTON2 = new PUSHBUTTON(this) //The "Stop" button
with (this.PUSHBUTTON2) //dimensions aer omitted for brevity
text = "Halt"
endwith

this.PUSHBUTTON3 = new PUSHBUTTON(this) //the start button
with (this.PUSHBUTTON3)
onClick = class::PUSHBUTTON3_O
NCLICK
text = "Start"
endwith


function TASKBARTRAY1_onRight
MouseUp(flags, col, row) //copied from Demotaskbartray.wfm
class::DisplayEvent(
program( ), flags, col, row )
this.displayPopup( ) // Display the popup menu now.
return

// Displays the event information in the command window.

function DisplayEvent( cFPname, flags, col, row ) //copied from Demotaskbartray.wfm
? "Event trapped by TaskbarTray : " + cFPName + ", flags = " + flags + ;
", col = " + col + ", row = " + row
form.tsk_evnt=true
return

Function UserStop(hWND) //Detects if pushbutton 2 has been pressed.

If Type("PeekMessage") # "FP"
extern CLOGICAL PeekMessage(CSTRING,
CHANDLE,;
CLONG, CLONG, CLONG) User32;
From "PeekMessageA"
EndIf
#define PM_NOYIELD 2
#define WM_LBUTTONDOWN HToI("201")
#define WM_LBUTTONUP HToI("202")

FORM.MsgBuff = Space(14) // Buffer for MSG structure
RETURN PeekMessage(FORM.MsgBuff,; // Scratch buffer for msg info.
hWND,; // Look for msgs for specified hWND
WM_LBUTTONDOWN,; // Low msg filter (left button down)
WM_LBUTTONUP,; // High msg filter
PM_NOYIELD) // Don't yield to other applications
//////////

function PUSHBUTTON3_onClick //start button click event
if form.running = false
form.running = true
form.text="Processing"
endif


do while form.running = true // alternate for testing FORM.LoopCount = 1 To 9900000
sleep 2 // sleep so that CPU usage isn't 100% all the time.

If FORM.UserStop(FORM.PUSHBUTTON2.hWND) // Did user click stop button?
FORM.Text3.Text = "Paused."

If MsgBox("Do you want to stop monitoring for HL7 Files?",;
"Stop?", 4 + 32 + 256) = 6 //yes
form.running = false
form.text="Halted"

Exit // exit the loop
EndIf
EndIf
//want to instert a detect if the taskbartray has been clicked on, an event should be waiting to be processed.
if form.running = true
form.monitor_my_dir() //function polls a directory forincoming files & processes.
endif //simulate by a=new array(), a.dir(), etc...

enddo


return


Jean-Pierre Martel

2006-12-13, 12:16 am

In article <K70hK1iHHHA.1212@news-server>, info@clinsaver.com says...
>
> Yes I have tried using the ongotfocus() event several ways.


I was wrong: it has to be the Taskbartray1.onLeftMouseDown() event
handler. For example:

this.TASKBARTRAY1 = new TASKBARTRAY(this)
with (this.TASKBARTRAY1)
onLeftMouseDown = {;msgbox("The TaskbarTray icon was clicked")}
onRightMouseUp = class::TASKBARTRAY1_
ONRIGHTMOUSEUP
height = 22
left = 234
top = 46
width = 28
endwith

To detect when the user clicks the TaskbarTray icon during a long
process, I would do this (untested):

Function PUSHBUTTON3_onClick
* Beginning of first change
_app.AllowYieldOnMsg = true
Form.TaskbarTray1.onLeftMouseDown = ;
{;this.wasClicked = true)}
* End of first change
if form.running = false
form.running = true
form.text="Processing"
endif
do while form.running = true
*** sleep 2 // never use Sleep
if Form.UserStop(FORM.PUSHBUTTON2.hWND)
Form.Text3.Text = "Paused."
if MsgBox("Do you want to stop monitoring for HL7 Files?",;
"Stop?", 4 + 32 + 256) = 6 // yes
form.running = false
form.text = "Halted"
exit // exit the loop
endif
endif
* Beginning of 2nd change
_app.executeMessages()
if Form.TaskbarTray1.wasClicked = true
Form.TaskbarTray1.onLeftMouseDown = ;
{;msgbox("The TaskbarTray icon was clicked")}
Form.TaskbarTray1.wasClicked = false
Form.text = "Halted"
Form.running = false
exit
endif
* End of 2nd change
form.monitor_my_dir()
enddo
return

Jean-Pierre Martel, editor
The dBASE Developers Bulletin
Blue Star dBASE Plus Core Concepts Graduate
Adam

2006-12-13, 7:14 pm

Good day,
While I'm sure this would work for most users, it seems that my 2 bBase compiliers (dB2k ver 0.4 b1661 and dBase PLUS 2.01) don't support _app.executeMessages().

In parallel to this, I've also attempted to use the winevents.cc ::doNow from the code library. I was able to make an alternate stop loop for the pushbutton2 onclick event, but I wasn't able to make the taskbar work.
Adam
Jean-Pierre Martel Wrote:

> In article <K70hK1iHHHA.1212@news-server>, info@clinsaver.com says...
>
> I was wrong: it has to be the Taskbartray1.onLeftMouseDown() event
> handler. For example:
>
> this.TASKBARTRAY1 = new TASKBARTRAY(this)
> with (this.TASKBARTRAY1)
> onLeftMouseDown = {;msgbox("The TaskbarTray icon was clicked")}
> onRightMouseUp = class::TASKBARTRAY1_
ONRIGHTMOUSEUP
> height = 22
> left = 234
> top = 46
> width = 28
> endwith
>
> To detect when the user clicks the TaskbarTray icon during a long
> process, I would do this (untested):
>
> Function PUSHBUTTON3_onClick
> * Beginning of first change
> _app.AllowYieldOnMsg = true
> Form.TaskbarTray1.onLeftMouseDown = ;
> {;this.wasClicked = true)}
> * End of first change
> if form.running = false
> form.running = true
> form.text="Processing"
> endif
> do while form.running = true
> *** sleep 2 // never use Sleep
> if Form.UserStop(FORM.PUSHBUTTON2.hWND)
> Form.Text3.Text = "Paused."
> if MsgBox("Do you want to stop monitoring for HL7 Files?",;
> "Stop?", 4 + 32 + 256) = 6 // yes
> form.running = false
> form.text = "Halted"
> exit // exit the loop
> endif
> endif
> * Beginning of 2nd change
> _app.executeMessages()
> if Form.TaskbarTray1.wasClicked = true
> Form.TaskbarTray1.onLeftMouseDown = ;
> {;msgbox("The TaskbarTray icon was clicked")}
> Form.TaskbarTray1.wasClicked = false
> Form.text = "Halted"
> Form.running = false
> exit
> endif
> * End of 2nd change
> form.monitor_my_dir()
> enddo
> return
>
> Jean-Pierre Martel, editor
> The dBASE Developers Bulletin
> Blue Star dBASE Plus Core Concepts Graduate


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com