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. pass variable between dialogs

pass variable between dialogs

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • V Offline
    V Offline
    viperlogic
    wrote on last edited by
    #1

    hi,i have one dialog called "main" and another "login", when the program starts, "main" starts and in the OnInitDialog() it calls another dialog called "login" and the main is hidden using ShowWindow(SW_HIDE). From the "login" dialog how can i show the "main" dialog without restarting it and hence the OnInitDialog() starting again. or how do i pass a variable from "login" to "main" to use in an if statment in the OnInitDialog() to indicated the "login" has previously been called hope i make some bit of sense!! thanks

    R T 2 Replies Last reply
    0
    • V viperlogic

      hi,i have one dialog called "main" and another "login", when the program starts, "main" starts and in the OnInitDialog() it calls another dialog called "login" and the main is hidden using ShowWindow(SW_HIDE). From the "login" dialog how can i show the "main" dialog without restarting it and hence the OnInitDialog() starting again. or how do i pass a variable from "login" to "main" to use in an if statment in the OnInitDialog() to indicated the "login" has previously been called hope i make some bit of sense!! thanks

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      If you display the "login"-dialog with a call to DoModal() from the "main"-dialog's OnInitDialog(), the "main"-dialog won't be displayed until the user have dismissed the "login"-dialog. Save the status depending on whether the login procedure was successful or not in a member of the "login"-dialog so that it can be retrieved when the execution continues in the "main"-dialog's OnInitDialog(). If the login procedure failed, simply use PostQuitMessage() to close the application or take whatever action you like. Hope this helps -- Roger


      It's supposed to be hard, otherwise anybody could do it!

      V 1 Reply Last reply
      0
      • R Roger Stoltz

        If you display the "login"-dialog with a call to DoModal() from the "main"-dialog's OnInitDialog(), the "main"-dialog won't be displayed until the user have dismissed the "login"-dialog. Save the status depending on whether the login procedure was successful or not in a member of the "login"-dialog so that it can be retrieved when the execution continues in the "main"-dialog's OnInitDialog(). If the login procedure failed, simply use PostQuitMessage() to close the application or take whatever action you like. Hope this helps -- Roger


        It's supposed to be hard, otherwise anybody could do it!

        V Offline
        V Offline
        viperlogic
        wrote on last edited by
        #3

        thanks for the reply PostQuitMessage(0); does the job alright that i was looking for. but for future reference i would still like to know how to pass variables between dialogs say declare a int in "main" and pass it to "login" and "login" sends it back with a value inside it. thanks -- modified at 11:14 Friday 24th March, 2006

        W 1 Reply Last reply
        0
        • V viperlogic

          thanks for the reply PostQuitMessage(0); does the job alright that i was looking for. but for future reference i would still like to know how to pass variables between dialogs say declare a int in "main" and pass it to "login" and "login" sends it back with a value inside it. thanks -- modified at 11:14 Friday 24th March, 2006

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          It depens on the type of dialog you are using. For non-modal dialogs you can send a message the same as you would send any other message, using SendMessage() specifying your own paramaters for lParam and wParam. But with Modal dialogs, the main dialog is halted until the child dialog is closed. You are able to send a message from the child to the parent using PostMessage(). Another method is through the use of global pointers. I'm sure there are other methods, but the above 2 have always fulfilled my needs.

          1 Reply Last reply
          0
          • V viperlogic

            hi,i have one dialog called "main" and another "login", when the program starts, "main" starts and in the OnInitDialog() it calls another dialog called "login" and the main is hidden using ShowWindow(SW_HIDE). From the "login" dialog how can i show the "main" dialog without restarting it and hence the OnInitDialog() starting again. or how do i pass a variable from "login" to "main" to use in an if statment in the OnInitDialog() to indicated the "login" has previously been called hope i make some bit of sense!! thanks

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            catch the return value like this :

            CMainDlg::OnInitDialog() {
            CDialog::OnInitDialog();

            CLoginDlg dlg;
            INT\_PTR nResponse = dlg.DoModal();
            if (nResponse == IDCANCEL) {
                this->EndDialog(IDCANCEL);
            }
            
            return TRUE;
            

            }

            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