MFC - execute code immediately after displaying a dialog box (equivalent to .NET Form.Shown)

I am making small changes to the C ++ MFC project. I am a .NET developer, so for me, new Windows programming.

I need to run some method right after the CDialog is fully displayed (painted) for the first time, but only once.

How can i do this? In .NET, I would handle the Form.Shown event .

Do I need to process some kind of message? Which the? Do I need to override some CDialog methods? Or is there no easy way? I am thinking of handling WM_ACTIVATE and then using a flag to ensure that I call another method only once.

+3
source share
3 answers

: , , -

Short story:
INT_PTR CALLBACK
DlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
  switch (uiMsg) {

  case WM_INITDIALOG:
    return TRUE;

  case WM_WINDOWPOSCHANGED:
    if ((((WINDOWPOS*)lParam)->flags & SWP_SHOWWINDOW) &&
        !g_fShown) {
      g_fShown = TRUE;
      PostMessage(hwnd, WM_APP, 0, 0);
    }
    break;


  case WM_APP:
      MessageBox(hwnd,
                 IsWindowVisible(hwnd) ? TEXT("Visible")
                                       : TEXT("Not Visible"),
                 TEXT("Title"), MB_OK);
      break;

  case WM_CLOSE:
   EndDialog(hwnd, 0);
   break;
  }

  return FALSE;
}

MFC, , WM_WINDOWPOSCHANGED, ON_MESSAGE WM_APP. . CodeProject.

+3

, , - . 10 . .

0

Hell put the code in OnPaint () and run bool m_fullyInitilized in your class. I also like the timer. Although I usually go with 100 ms. I also move all initialization code from oninit, in these cases. Just to protect against too much processing.

0
source

Source: https://habr.com/ru/post/1699227/


All Articles