Capture when Maximize button is clicked

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Capture when Maximize button is clicked

Postby Marloes » Sun Nov 29, 2015 6:41 am

How can I capture when the maximize button is clicked in FireMonkey?
Marloes
Active Poster
Active Poster
 
Posts: 13
Joined: Mon Dec 01, 2014 5:35 am

Re: Capture when Maximize button is clicked

Postby rlebeau » Mon Nov 30, 2015 3:50 pm

AFAIK, FireMonkey does not provide that information. On Windows at least (not sure about other platforms), you can override the Form's virtual CreateHandle() method, calling the base class method first to create the underlying HWND and then subclass it using the Win32 API. Then you would be able to process WM_SYSCOMMAND messages looking for SC_MAXIMIZE notifications.

For example:

Code: Select all
class TMyForm : public TForm
{
    //...
#ifdef _Windows
protected:
    virtual void __fastcall CreateHandle();
private:
    static LRESULT CALLBACK SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR  uIdSubclass, DWORD_PTR dwRefData);
#endif
    //...
};


Code: Select all
#ifdef _Windows
#include <FMX.Platform.Win.hpp>

void __fastcall TMyForm::CreateHandle()
{
    TForm::CreateHandle();

    HWND hWnd = FormToHWND(this);
    // Or:
    // HWND hWnd = WindowHandleToPlatform(Handle)->Wnd;

    SetWindowSubclass(hWnd, &SubclassProc, 1, reinterpret_cast<DWORD_PTR>(this));
}

LRESULT CALLBACK TMyForm::SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR  uIdSubclass, DWORD_PTR dwRefData)
{
    switch (uMsg)
    {
        case WM_NCDESTROY:
            RemoveWindowSubclass(hWnd, &SubclassProc, uIdSubclass);
            break;

        case WM_SYCOMMAND:
            if ((wParam & 0xFFF0) == SC_MAXIMIZE)
            {
                // do something...

                // if you need to access members of the Form:
                //
                // TMyForm *pThis = reinterpret_cast<TMyForm*>(dwRefData);
                // use pThis as needed...
            }
            break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
#endif
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1464
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA


Return to Technical

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 15 guests