Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: onytoo
  Where is onytoo?
 Padang
 Indonesia
 onytoo
 To: Jijo Pappachan
  Where is Jijo Pappachan?
 Kerala
 India
 Jijo Pappachan
 Tags
Subject: RE: Close button Click API
Thread ID: 310802 Message ID: 310852 # Views: 50 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: Win32API programming
Date: Sunday, June 26, 2011 3:29:50 AM         
   


>
> Hi Onyto,
> I have tried your code. but OnDestroy event is firing after VFP show "Do you want to save changes?"
> messagebox. My actual intention is to suppress that message and save automatically on WM_DESTROY event.
>
>
> Jijo
> JUST THINK, THERE IS A WAY
> my blog:http://weblogs.foxite.com/jijo_pappachan/


Hmm. yes you right.
I have modified the codes, would you try it again?

DECLARE LONG GetClassName IN WIN32API LONG, STRING @, LONG
DECLARE LONG FindWindowEx IN WIN32API LONG, LONG, STRING, STRING
DECLARE LONG GetWindowLong IN WIN32API LONG, LONG
DECLARE LONG CallWindowProc IN WIN32API LONG, LONG, LONG, LONG, LONG

#define GWL_WNDPROC (-4)
#define WM_SYSCOMMAND  0x0112
#define SC_CLOSE       0xF060

SET SAFETY OFF

lcFile = "test.prg"

MODIFY COMMAND (lcFile) NOWAIT

lcClass = SPACE(255)
lnLength = GetClassName(_VFP.hWnd, @lcClass, 255)
lcClass = LEFT(lcClass, lnLength) + CHR(0)
lhWnd = FindWindowEx(_SCREEN.hWnd, 0, lcClass, lcFile + CHR(0))

IF lhWnd != 0
  loHandler = CREATEOBJECT("CHandler", lhWnd)
  READ EVENTS
ENDIF


DEFINE CLASS CHandler AS Custom
  nOldWndProc = 0
  nHwnd = 0
  PROCEDURE Init(thWnd)
    this.nOldWndProc = GetWindowLong(thWnd, GWL_WNDPROC)
    BINDEVENT(thWnd, WM_SYSCOMMAND, this, "OnSysCommand", 4)
    this.nHwnd = thWnd
  ENDPROC

  PROCEDURE Destroy
    UNBINDEVENTS(this.nhWnd)
  ENDPROC

  PROCEDURE OnSysCommand(thWnd, tnMsg, twParam, tlParam)
    LOCAL lnResult
    IF twParam = SC_CLOSE
      WAIT WINDOW "Saving changes..." NOWAIT
      
      *!* you can put your saving method here!!!
      *!*
      
      *!* internal save and close
      KEYBOARD '{CTRL+W}'
      CLEAR EVENTS
      RETURN 0
    ENDIF
    RETURN CallWindowProc(this.nOldWndProc, thWnd, tnMsg, twParam, tlParam)
  ENDPROC
ENDDEFINE


Regards,
Onytoo

ENTIRE THREAD

Close button Click API Posted by Jijo Pappachan @ 6/25/2011 8:27:05 AM
RE: Close button Click API Posted by onytoo @ 6/25/2011 10:27:42 AM
RE: Close button Click API Posted by Jijo Pappachan @ 6/25/2011 10:45:02 AM
RE: Close button Click API Posted by onytoo @ 6/26/2011 3:29:50 AM
RE: Close button Click API Posted by Jijo Pappachan @ 6/27/2011 6:23:18 AM
RE: Close button Click API Posted by onytoo @ 6/27/2011 11:13:28 AM
RE: Close button Click API Posted by Yousfi Benameur @ 6/27/2011 10:21:56 AM
RE: Close button Click API Posted by onytoo @ 6/27/2011 11:17:27 AM
RE: Close button Click API Posted by Yousfi Benameur @ 6/26/2011 1:05:05 AM
RE: Close button Click API Posted by Jijo Pappachan @ 6/27/2011 6:24:25 AM