0

Is there any way to determine a minimization of a Dialog from within a control which is on the dialog?

I'm using the window message ON_WM_SIZE which should be called with the Type SIZE_MINIMIZED when the dialog gets minimized.

BEGIN_MESSAGE_MAP(CEditT, CEdit)
   ON_WM_SIZE()
END_MESSAGE_MAP()

void CEditT::OnSize(UINT nType, int cx, int cy)
{
   CEdit::OnSize(nType, cx, cy);
   switch(nType)
   {
      case SIZE_MINIMIZED:
         m_backgroundRedraw = TRUE;
   }
}

However this method never gets called, when the Dialog is being minimized. I need to track that minimization in order to correctly redraw my control with transparencies when it's being restored again.

Vinz
  • 3,030
  • 4
  • 31
  • 52

2 Answers2

0

First find the parent dialog from within your control using

CWnd *parent = GetParent();
HWND hWnd = parent->GetSafeHwnd();  // get its window handle
BOOL dlgMinimized = IsMinimized(hWnd);   // get min. state

The API is documented as:

BOOL WINAPI IsIconic(
  _In_  HWND hWnd
);

Reference here.

IsMinimized is a macro defined in windowsx.h and corresponds to IsIconic as documented by Microsoft.

I would suggest a different method. Catch the SIZE_MAXIMIZED nType in your Dialog OnSize() method, and maintain this state in a member variable. Then you can check it from the children setting up a WM_USER+XXX message handler in the dialog to respond with the current value.

At this point, you need to SendMessage(WM_USER+XXX,...) from a part of the code in your child control that actually gets called so it can perform some task. To see what messages are send to/from the child, I would check with spy++.

DNT
  • 2,356
  • 14
  • 16
  • Okay 2 questions. Where is that IsMinimized method from? And where would you suggest calling this? WM_ERASEBKGND and WM_PAINT are only called when the window is not minimized! – Vinz Oct 05 '14 at 15:12
0

This does not need to be that complicated. You should trap the WM_SYSCOMMAND message on the dialog level. That message handles minimize events. Then, simply call an exposed method of the control in response to that event.

rrirower
  • 4,338
  • 4
  • 27
  • 45