🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7523

SetWindowsHookEx

#7523
From: JD
Date: Fri, 28 Jan 2005 08:54
45 lines
2488 bytes
I'm using SetWindowsHookEx to monitor when the application's
window state is changed:

    WndReturnHook = ::SetWindowsHookEx( WH_CALLWNDPROCRET, (int (__stdcall*)())CallWndRetCallBackProc, HInstance, ::GetCurrentThreadId() );

int __stdcall TMyClass::CallWndRetCallBackProc( int Code, WPARAM WParam, LPARAM LParam )
{
    static bool IsMinimized = false;
    if( Code == HC_ACTION )
      {
          CWPRETSTRUCT *cwp = (CWPRETSTRUCT*) LParam;
          if( cwp->message == WM_SYSCOMMAND )
            {
                switch( cwp->wParam )
                  {
                      case  SC_RESTORE:
                      case SC_MAXIMIZE: // stuff
                                        IsMinimized = false;
                                        break;
                      case SC_MINIMIZE: // other stuff
                                        IsMinimized = true;
                  }
            }
      }
    return ::CallNextHookEx( WndReturnHook, Code, WParam, LParam );
}

This works but it's not 100%. If the System Menu is used to
change the form state, the above fails to catch the change in
state.

I've determined that the difference in using the System Menu
v/s the Border Icons is that the Border Icons sends the message
to the form while the System Menu sends the message to the
TApplication (verified by using TApplication::OnMessage).

I'm bewildered here because I've hooked into the application's
main thread. It even catches changes in the state of forms that
are not the main form (which is another issue for discussion)
so why not when the message is sent to TApplication?

What else can I try?

~ JD
Technical Details
Message-ID: <41f9fdbd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeder.wxs.nl!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5f60c991e080790d,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "JD" <nospam@nospam.com>
Sender: "JD" <nospam@nospam.com>
Reply-To: "JD" <nospam@nospam.com>
Subject: SetWindowsHookEx
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 172.137.74.73     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <41f9fdbd$1@newsgroups.borland.com>
Date: 28 Jan 2005 00:54:21 -0800
X-Trace: newsgroups.borland.com 1106902461 207.105.83.66 (28 Jan 2005 00:54:21 -0800)
Lines: 46
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeder.wxs.nl!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail