Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calling a function AFTER OnInitDialog completes.

Calling a function AFTER OnInitDialog completes.

Scheduled Pinned Locked Moved C / C++ / MFC
c++
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aquawicket
    wrote on last edited by
    #1

    I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }

    R M N 3 Replies Last reply
    0
    • A aquawicket

      I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }

      R Offline
      R Offline
      rgordon99
      wrote on last edited by
      #2

      Hey, Just force it by calling the ShowWindow function right before you call return: ShowWindow(SW_SHOW); This will force the window to be displayed. Cheers ...

      1 Reply Last reply
      0
      • A aquawicket

        I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        See How do I wait until my dialog box is displayed before doing something?[^]

        1 Reply Last reply
        0
        • A aquawicket

          I was looking to run a function after OnInitDialog completes and has fully drawn the dialog to the screen. I am getting some good results using this method, however, not all of the dialog objects and dialog are showing up. Not to sure why either. // stdafx.h #define WM_MY_USER_DEFINED_MESSAGE WM_APP + 0x10 // MyDialog.h virtual BOOL OnInitDialog(); afx_msg LRESULT OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() // MyDialog.cpp BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_MESSAGE(WM_MY_USER_DEFINED_MESSAGE, OnMyUserDefinedMessage) END_MESSAGE_MAP() BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); PostMessage(WM_MY_USER_DEFINED_MESSAGE); return TRUE; } LRESULT CMyDialog::OnMyUserDefinedMessage(WPARAM wParam, LPARAM lParam) { //I would imagine that if we are here, the dialog has completley drawn by now. //but this does not seem to be the case Sleep(5000); AfxMessageBox(L"ok"); return NULL; }

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          aquawicket wrote:

          Sleep(5000);

          There is no use if you put a sleep here. Remove it. When put a sleep the application will stop all processing including the painting. Try calling the RedrawWindow() function instead of that sleep.

          nave [OpenedFileFinder]

          A 1 Reply Last reply
          0
          • N Naveen

            aquawicket wrote:

            Sleep(5000);

            There is no use if you put a sleep here. Remove it. When put a sleep the application will stop all processing including the painting. Try calling the RedrawWindow() function instead of that sleep.

            nave [OpenedFileFinder]

            A Offline
            A Offline
            aquawicket
            wrote on last edited by
            #5

            Sweet.. Got it workin.. RedrawWindow() seemed to do the trick.. I didn't realize I was halting everything with Sleep(); I figured the dialog would be drawn before it ever got to that.. Thanks everyone.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups