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. Pop Up loading message

Pop Up loading message

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

    Hi. I am trying to create a pop up loading message. Something like the MessageBox function would do, but no buttons will be visible or enabled until done loading. The app is dialog based. Loading/Done loading will be controled in the main window, and the pop up will be a modal simply to prevent any action from the user in the main window until done loading. Is this possible? Thanks in advance.

    M A 2 Replies Last reply
    0
    • A acerunner316

      Hi. I am trying to create a pop up loading message. Something like the MessageBox function would do, but no buttons will be visible or enabled until done loading. The app is dialog based. Loading/Done loading will be controled in the main window, and the pop up will be a modal simply to prevent any action from the user in the main window until done loading. Is this possible? Thanks in advance.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      one way is to use a modeless dialog. ::EnableWindow(hwndMain, FALSE); ...create/show modeless status dialog... ...do loading ...destroy modeless status dialog... ::EnableWindow(hwndMain, TRUE);

      A 1 Reply Last reply
      0
      • M Mark Salsbery

        one way is to use a modeless dialog. ::EnableWindow(hwndMain, FALSE); ...create/show modeless status dialog... ...do loading ...destroy modeless status dialog... ::EnableWindow(hwndMain, TRUE);

        A Offline
        A Offline
        acerunner316
        wrote on last edited by
        #3

        I created a new dialog in the resource editor, called IDD_LOADING, and created a new class for it called CLoading. To create it, I have this code in the main dialog. EnableWindow(FALSE); CLoading *pLoadingDlg = new CLoading; pLoadingDlg->Create(IDD_LOADING,this); How do I destroy it? Something like this? CLoading::DestroyWindow(); EnableWindow(TRUE);

        M 2 Replies Last reply
        0
        • A acerunner316

          I created a new dialog in the resource editor, called IDD_LOADING, and created a new class for it called CLoading. To create it, I have this code in the main dialog. EnableWindow(FALSE); CLoading *pLoadingDlg = new CLoading; pLoadingDlg->Create(IDD_LOADING,this); How do I destroy it? Something like this? CLoading::DestroyWindow(); EnableWindow(TRUE);

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          This is what I'd do: pLoadingDlg->DestroyWindow(); delete pLoadingDlg; pLoadingDlg = 0; EnableWindow(TRUE);

          A 1 Reply Last reply
          0
          • A acerunner316

            I created a new dialog in the resource editor, called IDD_LOADING, and created a new class for it called CLoading. To create it, I have this code in the main dialog. EnableWindow(FALSE); CLoading *pLoadingDlg = new CLoading; pLoadingDlg->Create(IDD_LOADING,this); How do I destroy it? Something like this? CLoading::DestroyWindow(); EnableWindow(TRUE);

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Just remembered... Just in case you didn't know, you should probably override OnCancel() in your modeless dialog class and do nothing in your implementation (don't call the base class OnCancel()) so the user can't mess things up with the ESC key :)

            1 Reply Last reply
            0
            • M Mark Salsbery

              This is what I'd do: pLoadingDlg->DestroyWindow(); delete pLoadingDlg; pLoadingDlg = 0; EnableWindow(TRUE);

              A Offline
              A Offline
              acerunner316
              wrote on last edited by
              #6

              So after implementing the create and destroy loading window, it didn't show up. So I added the line pLoadingDlg->ShowWindow(SW_SHOW); Now the window shows up, but when done loading, and the window is destroyed, the focus doesn't return to the main window. How can I fix that? I tried usins popup and overlap style, and it has the same problem. Using the child style, the loading window doesn't even show up. -- modified at 18:56 Monday 27th November, 2006

              M 1 Reply Last reply
              0
              • A acerunner316

                So after implementing the create and destroy loading window, it didn't show up. So I added the line pLoadingDlg->ShowWindow(SW_SHOW); Now the window shows up, but when done loading, and the window is destroyed, the focus doesn't return to the main window. How can I fix that? I tried usins popup and overlap style, and it has the same problem. Using the child style, the loading window doesn't even show up. -- modified at 18:56 Monday 27th November, 2006

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                acerunner316 wrote:

                after implementing the create and destroy loading window, it didn't show up

                For the dalog resource: Style should be Child. Set the Visible property to TRUE.

                acerunner316 wrote:

                when done loading, and the window is destroyed, the focus doesn't return to the main window

                Try this: HWND hwndOldForeground = ::GetForegroundWindow(); EnableWindow(FALSE); CLoading *pLoadingDlg = new CLoading; pLoadingDlg->Create(IDD_LOADING,this); ... ... pLoadingDlg->DestroyWindow(); delete pLoadingDlg; pLoadingDlg = 0; EnableWindow(TRUE); if (hwndOldForeground) { ::SetForegroundWindow(hwndOldForeground); hwndOldForeground = 0; }

                A 1 Reply Last reply
                0
                • M Mark Salsbery

                  acerunner316 wrote:

                  after implementing the create and destroy loading window, it didn't show up

                  For the dalog resource: Style should be Child. Set the Visible property to TRUE.

                  acerunner316 wrote:

                  when done loading, and the window is destroyed, the focus doesn't return to the main window

                  Try this: HWND hwndOldForeground = ::GetForegroundWindow(); EnableWindow(FALSE); CLoading *pLoadingDlg = new CLoading; pLoadingDlg->Create(IDD_LOADING,this); ... ... pLoadingDlg->DestroyWindow(); delete pLoadingDlg; pLoadingDlg = 0; EnableWindow(TRUE); if (hwndOldForeground) { ::SetForegroundWindow(hwndOldForeground); hwndOldForeground = 0; }

                  A Offline
                  A Offline
                  acerunner316
                  wrote on last edited by
                  #8

                  Setting the style to child does not work. The popup window does not show up at all. The Visible property is already checked. The code to SetForeground code does not work. I also tried SetFocus(), but that didn't work either. Any other clever ideas?

                  M S 2 Replies Last reply
                  0
                  • A acerunner316

                    Setting the style to child does not work. The popup window does not show up at all. The Visible property is already checked. The code to SetForeground code does not work. I also tried SetFocus(), but that didn't work either. Any other clever ideas?

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    hmmm I tested the code before I posted it. Are you using the correct parent window when creating the dialog window?

                    A 1 Reply Last reply
                    0
                    • A acerunner316

                      Setting the style to child does not work. The popup window does not show up at all. The Visible property is already checked. The code to SetForeground code does not work. I also tried SetFocus(), but that didn't work either. Any other clever ideas?

                      S Offline
                      S Offline
                      Scott Holt
                      wrote on last edited by
                      #10

                      Setting the style to "Child" does not work because, when you disable a window, Windows will automatically disable its child windows as well. When you used SetFocus, did you do it as follows: HWND hwndSaveFocus = GetFocus() ; ... (display dialog and delete when done) ... SetFocus(hwndsaveFocus) ; Scott

                      A 1 Reply Last reply
                      0
                      • S Scott Holt

                        Setting the style to "Child" does not work because, when you disable a window, Windows will automatically disable its child windows as well. When you used SetFocus, did you do it as follows: HWND hwndSaveFocus = GetFocus() ; ... (display dialog and delete when done) ... SetFocus(hwndsaveFocus) ; Scott

                        A Offline
                        A Offline
                        acerunner316
                        wrote on last edited by
                        #11

                        hwndSaveFocus = GetFocus(); that gives me the error: error C2440: '=' : cannot convert from 'class CWnd *' to 'struct HWND__ *

                        S 2 Replies Last reply
                        0
                        • M Mark Salsbery

                          hmmm I tested the code before I posted it. Are you using the correct parent window when creating the dialog window?

                          A Offline
                          A Offline
                          acerunner316
                          wrote on last edited by
                          #12

                          How do i know if i'm using the correct parent window? When created the "loading..." dialog window, i just inserted a new dialog in the resource editor. And then opened class wizard to generate a new class for the new dialog. And the rest of the code, you pretty much know already.

                          M 1 Reply Last reply
                          0
                          • A acerunner316

                            How do i know if i'm using the correct parent window? When created the "loading..." dialog window, i just inserted a new dialog in the resource editor. And then opened class wizard to generate a new class for the new dialog. And the rest of the code, you pretty much know already.

                            M Offline
                            M Offline
                            Mark Salsbery
                            wrote on last edited by
                            #13

                            You are passing "this" as the parent. I don't know what class you are creating the dialog in. For example, if it is a CFrameWnd derived then you may need to pass the client window as the parent. pLoadingDlg->Create(IDD_LOADING,this); By the way, as Scott mentioned, child windows do get disabled when you disable the parent. This doesn't affect the visiblility of any windows. I disabled the main window in my example to prevent the user from doing anything until the operation completes, which is the Microsoft recommended method. Of course, you can do what you want with the UI as you need to. This does work :) Here's the dialog resource I tested with: IDD_STATUS DIALOGEX 0, 0, 186, 25 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE EXSTYLE WS_EX_STATICEDGE FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN CTEXT "Test Status",IDC_STATIC,15,7,156,12 END

                            A 1 Reply Last reply
                            0
                            • M Mark Salsbery

                              You are passing "this" as the parent. I don't know what class you are creating the dialog in. For example, if it is a CFrameWnd derived then you may need to pass the client window as the parent. pLoadingDlg->Create(IDD_LOADING,this); By the way, as Scott mentioned, child windows do get disabled when you disable the parent. This doesn't affect the visiblility of any windows. I disabled the main window in my example to prevent the user from doing anything until the operation completes, which is the Microsoft recommended method. Of course, you can do what you want with the UI as you need to. This does work :) Here's the dialog resource I tested with: IDD_STATUS DIALOGEX 0, 0, 186, 25 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE EXSTYLE WS_EX_STATICEDGE FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN CTEXT "Test Status",IDC_STATIC,15,7,156,12 END

                              A Offline
                              A Offline
                              acerunner316
                              wrote on last edited by
                              #14

                              this is what i have: pLoadingDlg->Create(IDD_LOADING,this); IDD_LOADING is configured as Style: child, Border: dialog frame, title bar, visible, tool window. Is this correct? The Loading dialog still doesn't show up. But the main window is disabled as expected. I can't click anything during the loading time.

                              M 1 Reply Last reply
                              0
                              • A acerunner316

                                this is what i have: pLoadingDlg->Create(IDD_LOADING,this); IDD_LOADING is configured as Style: child, Border: dialog frame, title bar, visible, tool window. Is this correct? The Loading dialog still doesn't show up. But the main window is disabled as expected. I can't click anything during the loading time.

                                M Offline
                                M Offline
                                Mark Salsbery
                                wrote on last edited by
                                #15

                                acerunner316 wrote:

                                IDD_LOADING is configured as Style: child, Border: dialog frame, title bar, visible, tool window.

                                OK for reference, I tested with the same except no title bar and no toolwindow. What I'm wondering is in this line pLoadingDlg->Create(IDD_LOADING,this); What class "this" points to? Where are you calling this from and what class is the window derived from?

                                A 1 Reply Last reply
                                0
                                • M Mark Salsbery

                                  acerunner316 wrote:

                                  IDD_LOADING is configured as Style: child, Border: dialog frame, title bar, visible, tool window.

                                  OK for reference, I tested with the same except no title bar and no toolwindow. What I'm wondering is in this line pLoadingDlg->Create(IDD_LOADING,this); What class "this" points to? Where are you calling this from and what class is the window derived from?

                                  A Offline
                                  A Offline
                                  acerunner316
                                  wrote on last edited by
                                  #16

                                  this is called in a function belonging to the main dialog's class.

                                  M 1 Reply Last reply
                                  0
                                  • A acerunner316

                                    this is called in a function belonging to the main dialog's class.

                                    M Offline
                                    M Offline
                                    Mark Salsbery
                                    wrote on last edited by
                                    #17

                                    acerunner316 wrote:

                                    this is called in a function belonging to the main dialog's class.

                                    and called from what function?

                                    A 1 Reply Last reply
                                    0
                                    • M Mark Salsbery

                                      acerunner316 wrote:

                                      this is called in a function belonging to the main dialog's class.

                                      and called from what function?

                                      A Offline
                                      A Offline
                                      acerunner316
                                      wrote on last edited by
                                      #18

                                      Called from yet another function belonging to the same class. I only have one class because everything have been in one dialog box until now.

                                      M 1 Reply Last reply
                                      0
                                      • A acerunner316

                                        Called from yet another function belonging to the same class. I only have one class because everything have been in one dialog box until now.

                                        M Offline
                                        M Offline
                                        Mark Salsbery
                                        wrote on last edited by
                                        #19

                                        acerunner316 wrote:

                                        Called from yet another function belonging to the same class.

                                        OK, my point is, as long as you're not creating it in the class' WM_CREATE handler or OnInitDialog() override it should show. Are you creating the dialog, doing the processing, and destroying the dialog all in one function? If so, then you could try this: ... pLoadingDlg->Create(IDD_LOADING,this); Invalidate(FALSE); UpdateWindow(); ....do processing ...destroy dialog as usual

                                        A 1 Reply Last reply
                                        0
                                        • M Mark Salsbery

                                          acerunner316 wrote:

                                          Called from yet another function belonging to the same class.

                                          OK, my point is, as long as you're not creating it in the class' WM_CREATE handler or OnInitDialog() override it should show. Are you creating the dialog, doing the processing, and destroying the dialog all in one function? If so, then you could try this: ... pLoadingDlg->Create(IDD_LOADING,this); Invalidate(FALSE); UpdateWindow(); ....do processing ...destroy dialog as usual

                                          A Offline
                                          A Offline
                                          acerunner316
                                          wrote on last edited by
                                          #20

                                          Yes i am creating, processing and destroying all in one function. But on different calls of the function. Therefore, the pointer to CLoading has to be static. I've tried your new node, it works! But the dialog box is created in the upper left corner of the main dialog box. How can I position it so that it pops up in the center like with the popup and overlap styles?

                                          M 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