News: SPECIAL OFFER: EZGUI Classic (4.0) until May 31, 2013 only $29 !

TO REGISTER on Forum, contact tech support: http://cwsof.com/support.html
 
Pages: [1]   Go Down
  Print  
Author Topic: Redirecting the X (system menu exit) click  (Read 273 times)
Chris Burgess
EZGUI SLL Beta
Full Member
*
Posts: 161


View Profile
« on: March 19, 2012, 10:37:56 PM »

Needed to generate a time much shorter than the standard 0.01 seconds minimum - need to go down to at least 100 microseconds (i.e. 10Khz) - it's to communicate to a purpose-made PCI card.    A simple one button app was made:
Code:
Sub MAIN_Events(CID&, CMsg&, CVal&, Cancel&)
     Select Case CID&
          Case %EZ_Window
               Select Case CMsg&
                    Case %EZ_Loading
                    Case %EZ_Loaded
                    Case %EZ_Started
                      AppMain
                    Case %EZ_Close
                      'Do                              ' THIS
                      ' Sleep 1                        ' DOES
                      ' EZ_UnloadForm  "Main"          ' NOT
                      'Loop                            ' WORK
                    Case Else
               End Select
          Case Else
     End Select
End Sub


Code:
Sub MAIN_BUTTON1_Events( MyID&, CMsg&, CVal&, Cancel&)
     Select Case CMsg&
          Case %EZ_Click
               Terminate = 1
          Case Else
     End Select
End Sub 

Code:
Sub AppMain()

  Do
   If Terminate > 0 Then Exit Do
    PCI
    EZ_DoEvents 25
  Loop

 EZ_UnloadForm  "Main"

End Sub

All works well so far - getting 60KHZ plus at the PCI and the CPU is at only 50% (not an issue as it's the only app that will run on this PC).

The button "Button1" sets a variable ("Terminate") to 1, breaking the loop and causing the app to terminate.

Only issue - the red X system menu button does not word correctly (app exits but doesn't terminate and has to be killed off in task manager).  The commented out code above doesn't work either.

Disabling this with the D property on the form is our workaround for now - but the users want the red X back.

Setting Cancel& to 1 stops EZ_UnloadForm from working, so that's not an option either.

Is there a way of getting the red X to not exit but to instead just set Terminate to "1", just as if the user clicked "Button1"?


 









Logged
Chris Boss
Administrator
Hero Member
*****
Posts: 1812


View Profile
« Reply #1 on: March 19, 2012, 10:57:57 PM »

You are trying to impliment your own message loop, which I don't recommend.

What you really want is EZGUI's game loop mode.

Use EZ_DefGameLoop to start a game loop.

Game loop means the EZGUI message loop will use PeekMessahe instead of GetMessage, which speeds up the message loop so it can use up to 100% of the CPU if need be.

This will generate the %EZ_GameLoop event which will occur every iteration of the message loop.

You can use this instead of a timer event.

You can use the EZ_StartFrame and EZ_EndFrame commands in this event to control the timing.

Another way to control the timing would be to use the EZ_GetPTime function to get a precision timer value.

If you don't require 100% of the CPU, you can call SLEEP (or EZ_Sleep) to release the CPU for other apps.

Logged
Chris Burgess
EZGUI SLL Beta
Full Member
*
Posts: 161


View Profile
« Reply #2 on: March 25, 2012, 04:31:33 PM »

The game loop did the trick - I'm getting a PCI sample rate of 36uS (about 28Khz) - we needed at least 100uS (i.e. 10Khz), so it's making the requirement comfortably (about 3 times quicker than the maximum allowable time).

The program now exits normally and is completely stable.  CPU time is steady at 50%, exactly the same as the previous version without the game loop.

Chris

Logged
Pages: [1]   Go Up
  Print  
 
Jump to: