LOOP remains active after closing via Task Bar cure
#1
In a current project I'm using GRAPHIC WINDOW CLICK in a DO/LOOP.
(Is similar to MODELESS pump and CALLBACK but only clicks not Windows messages)

If I closed the window using right click on task bar icon compiling again failed because program is still running.
(needed to close using Task Manager)

The cure is API IsWindow (hWin) in the DO/LOOP.
Code:
  'Mouse click "pump"
  do
    graphic window click to ClickState, PosX, PosY
  ' if ClickState then                    '<== to also check for double click
    ' sleep 550 'default Windows time 500,             '<== for double click
    ' graphic window click to ClickState, dummy, dummy '<== for double click
      ExitRequest = ClickProc( ClickState, PosX, PosY) '<== Exit clicked on window
      if ExitRequest then exit function
      if IsWindow (hGrafWin) = 0 then exit function    '<== the cure!
  ' end if                                             '<== for double click
    sleep 100
  loop
I've found no way to monitor for mouse clicks in TXT.WINDOW. But there could be a DO/LOOP.

Use CON.MOUSE and CON.HANDLE for the above to work in PBCC.

PBWIN has function ISWIN, but GRAPHIC WINDOW and TXT.WINDOW can also be created in PBCC which doesn't.

related: Console programs can have a callback. See PBCC samples\Internet\TCP or \UDP.
Reply
#2
You could also test DC (example below shows) and CLICK returns 2 for double clicks. As for text windows, subclassing is a way (works with Graphic Windows too)
Code:
FUNCTION PBMAIN () AS LONG
  LOCAL hWin, ClickState, PosX, PosY AS LONG

  GRAPHIC WINDOW NEW "Click test" , 400 , 200 , 300 , 200 TO hWin
  GRAPHIC ATTACH hWin, 0

  DO WHILE GRAPHIC(DC)
     GRAPHIC WINDOW CLICK TO ClickState, PosX, PosY
     SELECT CASE ClickState
     CASE 1 : GRAPHIC CELL = 2,2 : GRAPHIC PRINT "Single Click " ; ClickState; PosX; PosY; "  "
     CASE 2 : GRAPHIC CELL = 2,2 : GRAPHIC PRINT "Double Click " ; ClickState; PosX; PosY; "  "
     END SELECT
     SLEEP 1
  LOOP

  GRAPHIC WINDOW END

END FUNCTION

Text Window Subclassing:
Code:
#COMPILE EXE
#DIM ALL
#IF %DEF(%PB_CC32)  ' if to compile with PBCC, turn off console
  #CONSOLE OFF
#ENDIF
%UNICODE = 1
#INCLUDE "WIN32API.INC"
GLOBAL oldProc AS DWORD

'====================================================================
FUNCTION PBMAIN () AS LONG
  LOCAL hTWin AS LONG

  TXT.WINDOW ("Click test", 100, 200, 15, 50) TO hTWin
  oldProc = SetWindowLong(hTWin, %GWL_WNDPROC, CODEPTR(SubClassProc))

  TXT.COLOR = %BLUE
  TXT.CELL = 1, 2: TXT.PRINT "Click or double-click anywhere in this window"
  TXT.CELL = 3, 2: TXT.PRINT "Press the Any-key to exit."
  TXT.WAITKEY$

  IF oldProc THEN  ' remove subclassing before exit
      SetWindowLong hTWin, %GWL_WNDPROC, oldProc
  END IF
  TXT.END
END FUNCTION '

'====================================================================
FUNCTION SubClassProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                      BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
  SELECT CASE AS LONG wMsg
  CASE %WM_LBUTTONDOWN   : TXT.CELL = 6, 2: TXT.PRINT "Single Click."
  CASE %WM_LBUTTONDBLCLK : TXT.CELL = 6, 2: TXT.PRINT "Double Click."
  END SELECT

  FUNCTION = CallWindowProc(oldProc, hWnd, wMsg, wParam, lParam)

END FUNCTION
Reply
#3
Thanks, but the subject is curing program still running after closing by right click on task bar.

I think your DO/LOOP example will fail to stop because there no EXIT LOOP or EXIT FUNCTION inside the loop.

Cheers,
Reply
#4
Tested and works, because of DO WHILE GRAPHIC(DC), where the DC becomes 0 when the Graphic window is destroyed so it exits DO.
Reply
#5
Blush
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)