Announcement

Collapse
No announcement yet.

Graphic Window Close Button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dave Biggs
    replied
    Here's some sample code that intercepts the user's attempt to close a Graphic Window..
    Code:
    #INCLUDE "WIN32API.INC"
     
    FUNCTION SubProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                     BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
     LOCAL OldProc AS DWORD
     OldProc = GetProp (hWnd, "OldProc")             ' Local copy of address for G.Window procedure
     
      SELECT CASE AS LONG wMsg
     
        CASE %WM_SYSCOMMAND
          IF (WParam AND &HFFF0) = %SC_CLOSE THEN
            ' Interupt close here
            IF MSGBOX ("Delay required?", %MB_YESNO OR %MB_TASKMODAL, "Shutdown Check") = %IDYES THEN
              EXIT FUNCTION
            END IF
          END IF
     
        CASE %WM_DESTROY                             ' Graphic Window about to be destroyed
          GRAPHIC ATTACH hWnd, 0
          SetWindowLong hWnd, %GWL_WNDPROC, OldProc  ' remove subclassing before exit
          RemoveProp hWnd, "OldProc"                 ' RmoveProp
          GRAPHIC WINDOW END
      END SELECT
     
     FUNCTION = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)  ' pass msgs on to original proc
    END FUNCTION
    '------------------/SubProc
     
    FUNCTION PBMAIN () AS LONG
     LOCAL hWin, OldProc AS DWORD
     LOCAL Temp AS STRING
     
      GRAPHIC WINDOW "Close trap test", 400, 400, 300, 300 TO hWin
     
      SetProp hWin, "OldProc", SetWindowLong(hWin, %GWL_WNDPROC, CODEPTR(SubProc)) ' Subclass G.Window
     
      GRAPHIC ATTACH hWin, 0
      GRAPHIC BOX (40, 40) - (120, 15), 0, %BLUE
     
      DO WHILE IsWindow(hWin)
        SLEEP 1
      LOOP
      GRAPHIC WINDOW END
    END FUNCTION
    '------------------/PBMain

    Leave a comment:


  • Michael Mattias
    replied
    Are you talking about preventing the execution of GRAPHIC WINDOW CLOSE if the app is not ready for that?

    That you will have to control in your application. I am not a GRAPHIC WINDOW guy, but I know there are examples here of subclassing these things... that being the case, you should be able to trap the WM_SYSCOMMAND/SC_CLOSE notification and "eat" it so the default action (close window) does not occur when you do not want that to happen.

    WM_SYSCOMMAND/SC_CLOSE is sent on Alt+F4, Clicking on the "X" on the caption bar, or selecting "close" from the system menu (applies to all windows, so you do this with any program).

    Leave a comment:


  • Fraser Portwood
    started a topic Graphic Window Close Button

    Graphic Window Close Button

    Hello

    Does anybody know if it is possible to disable or trap the GRAPHIC WINDOW CLOSE BUTTON to prevent it from being terminated before the console application is ready terminate.

    I am trying to use a GRAPHIC WINDOW as a user front end to a hidden window, the problem is the user terminates it the console application is not aware of it.

    Regards
Working...
X