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. File Dialog after dialog creation

File Dialog after dialog creation

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
2 Posts 2 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
    act_x
    wrote on last edited by
    #1

    I have Visual c++ dialog application . once the dialog has been created immediately I need to show a File Dialog . Doing it in OnInitDialog doesnt work as expected as it pops up the file dialog . Is there some other point where i can make this call or do i have to have some internal variable that a timer checks after a while and then shows the dialog ? Engineering is the effort !

    G 1 Reply Last reply
    0
    • A act_x

      I have Visual c++ dialog application . once the dialog has been created immediately I need to show a File Dialog . Doing it in OnInitDialog doesnt work as expected as it pops up the file dialog . Is there some other point where i can make this call or do i have to have some internal variable that a timer checks after a while and then shows the dialog ? Engineering is the effort !

      G Offline
      G Offline
      GeMe_Hendrix
      wrote on last edited by
      #2

      Well there's a few ways to tackle this problem. Indeed you could use a timer. But the most important thing for you to understand is how message queues in Windows work. However, first the answer to your question. Try creating your own custom message ad handler for it first therefore at the top of your dialog CPP file... #define WM_MYOWNMESSAGE WM_USER + 1001; ... Then in the header file put... afx_msg LRESULT OnMyOwnMessage(WPARAM wParam, LPARAM lParam); ...Then the appropriate body for it... LRESULT CMyDialog::OnMyOwnMessage(WPARAM wParam, LPARAM lParam) { ... Show the file dialog box (I know it has to be modal) return 0; }; ... And finally in the body put... ON_MESSAGE(WM_MYOWNMESSAGE, OnMyOwnMessage) ... in the BEGIN_MESSAGE_MAP section... ... To call the message handler put this in the OnInitDialog function just before it returns... PostMessage(WM_MYOWNMESSAGE, 0, 0); So okay, this should work. But why should this work? You could do the same thing with a timer (Its another message WM_TIMER). Well as you well know OnInitDialog gets called when all the handles for all the windows you are creating are created but not shown. We post a custom message on to the message queue of the dialog box. This eventually gets processed. As I'm placing it on the message queue in OnInitDialog it will only get processed after this point in which the dialog box will be shown. I'm sure there are other ways but I find this one works very well for me :!)

      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