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. 2 CDialog questions

2 CDialog questions

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
16 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.
  • R Offline
    R Offline
    raner
    wrote on last edited by
    #1

    Hi (1)I need to display multiple dialog, so i tried the following..which seem to work ok, except i need to click "OK" or close the dialog box before the next one appears.How can i make them appear all at once? for(int i=0;iDoModal(); } (2)How to i set the caption and position of the dialog boxes at runtime? i tried using SetWindowText() to set the caption but it ran into error while executing.I've absolutely no idea how to set the position of dialog boxes at runtime.

    J J X 3 Replies Last reply
    0
    • R raner

      Hi (1)I need to display multiple dialog, so i tried the following..which seem to work ok, except i need to click "OK" or close the dialog box before the next one appears.How can i make them appear all at once? for(int i=0;iDoModal(); } (2)How to i set the caption and position of the dialog boxes at runtime? i tried using SetWindowText() to set the caption but it ran into error while executing.I've absolutely no idea how to set the position of dialog boxes at runtime.

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      (1) You need modeless dialogs to do what you want. Check your docs about these dialogs. (2) SetWindowText is the way to go, but you cannot use it just after new CDlg; first you've got to actually create the dialog. As for positioning, use SetWindowPos. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • R raner

        Hi (1)I need to display multiple dialog, so i tried the following..which seem to work ok, except i need to click "OK" or close the dialog box before the next one appears.How can i make them appear all at once? for(int i=0;iDoModal(); } (2)How to i set the caption and position of the dialog boxes at runtime? i tried using SetWindowText() to set the caption but it ran into error while executing.I've absolutely no idea how to set the position of dialog boxes at runtime.

        J Offline
        J Offline
        Joan M
        wrote on last edited by
        #3

        1: If you want them to appear "at the same time" you cannot use DoModal, you should use:

        dlg->Create(...);
        dlg->ModifyStyle(0,WS_VISIBLE);

        2: If you do it in this way you have to be able to change the caption using

        dlg->SetwindowText("texahdfhsklfhsdal");

        And if you want to move the dialogs, you can do it with dlg->MoveWindow(...); or with dlg->SetWindowPos(...);. Hope this helps...

        https://www.robotecnik.com freelance robots, PLC and CNC programmer.

        R 2 Replies Last reply
        0
        • R raner

          Hi (1)I need to display multiple dialog, so i tried the following..which seem to work ok, except i need to click "OK" or close the dialog box before the next one appears.How can i make them appear all at once? for(int i=0;iDoModal(); } (2)How to i set the caption and position of the dialog boxes at runtime? i tried using SetWindowText() to set the caption but it ran into error while executing.I've absolutely no idea how to set the position of dialog boxes at runtime.

          X Offline
          X Offline
          xxhimanshu
          wrote on last edited by
          #4

          ;)u cant do so..because the focus will be on first dialog and until u dismiss that it will not let go the control onto the next line..for using multiple dialogs at asme time..use property sheets..and that will appear as tabs of anything u see..like internet opetions..I hope you can go on with it.... cheers Himanshu

          1 Reply Last reply
          0
          • J Joan M

            1: If you want them to appear "at the same time" you cannot use DoModal, you should use:

            dlg->Create(...);
            dlg->ModifyStyle(0,WS_VISIBLE);

            2: If you do it in this way you have to be able to change the caption using

            dlg->SetwindowText("texahdfhsklfhsdal");

            And if you want to move the dialogs, you can do it with dlg->MoveWindow(...); or with dlg->SetWindowPos(...);. Hope this helps...

            R Offline
            R Offline
            raner
            wrote on last edited by
            #5

            I've never tried using a modeless dialog before, so i'll have to spend some time experimenting with it. But anyway, will it pose a problem then, if i name all the dialog instances identically? Thks all ;)

            J 1 Reply Last reply
            0
            • J Joan M

              1: If you want them to appear "at the same time" you cannot use DoModal, you should use:

              dlg->Create(...);
              dlg->ModifyStyle(0,WS_VISIBLE);

              2: If you do it in this way you have to be able to change the caption using

              dlg->SetwindowText("texahdfhsklfhsdal");

              And if you want to move the dialogs, you can do it with dlg->MoveWindow(...); or with dlg->SetWindowPos(...);. Hope this helps...

              R Offline
              R Offline
              raner
              wrote on last edited by
              #6

              I tried create() and then ModifyStyle(0,WS_VISIBLE)...however i've an OnPaint() for my CDlg and it doesnt seem to be called...why is that so and what can i do?

              J 1 Reply Last reply
              0
              • R raner

                I've never tried using a modeless dialog before, so i'll have to spend some time experimenting with it. But anyway, will it pose a problem then, if i name all the dialog instances identically? Thks all ;)

                J Offline
                J Offline
                Joan M
                wrote on last edited by
                #7

                raner wrote: if i name all the dialog instances identically What do you mean? the name of the variable that represents the dialog? If you meant that: you cannot do it because you'll reassign a new dialog to the same variable and this would generate memory leaks... (at it's best). You must create an array of dialog variables and then assign the right one in the for clause in order to do what you want (see below)

                CDlg dlgArray[4];
                for(int i=0;i<4;i++)
                {
                dlgArray[i]=new CDlg;
                dlgArray[i]->Create(...);
                dlgArray[i]->ModifyStyle(0,WS_VISIBLE);
                dlgArray[i]->SetWindowText(...);
                }

                if you want to dynamically allocate a different number of dialogs you can take a look at the wrapper CArray (easy way to generate arrays of various kind of variables). Well, I have no idea about if you meant that or not, but I hope this helps (my english is not my best)... PS: Remember the "rule": always that you've used a new you must use a delete. Or what is the same, whatever you create whatever you must destroy. Sample: delete dlgArray[i];

                https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                1 Reply Last reply
                0
                • R raner

                  I tried create() and then ModifyStyle(0,WS_VISIBLE)...however i've an OnPaint() for my CDlg and it doesnt seem to be called...why is that so and what can i do?

                  J Offline
                  J Offline
                  Joan M
                  wrote on last edited by
                  #8

                  I think that for dialogs the best place to manage drawing issues is the OnEraseBackground... But it's strange, could you paste some code?

                  https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                  R 1 Reply Last reply
                  0
                  • J Joan M

                    I think that for dialogs the best place to manage drawing issues is the OnEraseBackground... But it's strange, could you paste some code?

                    R Offline
                    R Offline
                    raner
                    wrote on last edited by
                    #9

                    thks for your previous reply about creating multiple instances :)..it's exactly what i was looking for!...(and i find your english very clear actually) as for the code, below are just some of the codes.i don't know if it's sufficient for you to find out what's going on.Actually if you don't mind emailing me your email address, i cant send you a more complete source code. in my CView class..

                    dlgGraph[i]=new CGrapDlg(this);
                    dlgGraph[i]->SetLink(i);
                    if (dlgGraph[i]->GetSafeHwnd()==0){
                    dlgGraph[i]->Create(); //displays dialog window
                    }
                    dlgGraph[i]->ModifyStyle(0,WS_VISIBLE);

                    in my CGrapDlg...

                    CGrapDlg::CGrapDlg(CView *pView) //modeless constructor
                    :CDialog()
                    {
                    m_pView=pView;
                    }

                    BOOL CGrapDlg::Create()
                    {
                    return CDialog::Create(CGrapDlg::IDD);
                    }

                    void CGrapDlg::OnPaint()
                    {
                    CWnd* graphFrame = (CWnd*)GetDlgItem(IDC_GRAPH_FRAME);
                    CDC* pDC = graphFrame->GetDC();

                    try{
                    	plotGraph.Plot(pDC,link);} //plotGraph is a CObject-derived class
                    catch(...)
                    {
                    	AfxMessageBox("Error plotting graph.Has files been opened?");
                    }
                    
                    ReleaseDC(pDC);
                    

                    }

                    Thanks alot, really.

                    J 1 Reply Last reply
                    0
                    • R raner

                      thks for your previous reply about creating multiple instances :)..it's exactly what i was looking for!...(and i find your english very clear actually) as for the code, below are just some of the codes.i don't know if it's sufficient for you to find out what's going on.Actually if you don't mind emailing me your email address, i cant send you a more complete source code. in my CView class..

                      dlgGraph[i]=new CGrapDlg(this);
                      dlgGraph[i]->SetLink(i);
                      if (dlgGraph[i]->GetSafeHwnd()==0){
                      dlgGraph[i]->Create(); //displays dialog window
                      }
                      dlgGraph[i]->ModifyStyle(0,WS_VISIBLE);

                      in my CGrapDlg...

                      CGrapDlg::CGrapDlg(CView *pView) //modeless constructor
                      :CDialog()
                      {
                      m_pView=pView;
                      }

                      BOOL CGrapDlg::Create()
                      {
                      return CDialog::Create(CGrapDlg::IDD);
                      }

                      void CGrapDlg::OnPaint()
                      {
                      CWnd* graphFrame = (CWnd*)GetDlgItem(IDC_GRAPH_FRAME);
                      CDC* pDC = graphFrame->GetDC();

                      try{
                      	plotGraph.Plot(pDC,link);} //plotGraph is a CObject-derived class
                      catch(...)
                      {
                      	AfxMessageBox("Error plotting graph.Has files been opened?");
                      }
                      
                      ReleaseDC(pDC);
                      

                      }

                      Thanks alot, really.

                      J Offline
                      J Offline
                      Joan M
                      wrote on last edited by
                      #10

                      1. I don't know if this is the problem or not... but it seems that you've derived the CGrapDlg class from a CView not from a CDialog... 2. this is not a problem, only a typo that makes things clearer: if you derive from a dialog write xxxdlg and if you derive from a window write xxxwnd (only if you want of course). 3. I don't understand the use of the "link" var: if you have declared plotGraph inside (as a member of) the CGrapDlg class you don't need that, because PlotGraph it's unique and property of the actual instance of CGrapDlg. (Be sure not ot miss the fact that the handle (if that is what Plot(DC,Handle)) needs is not a numeric ID that can be assigned... Each window has its own handle that can be obtained using GetWndHandle() (memory obtained (don't trust a lot the last part)). Hope this helps.

                      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                      R 1 Reply Last reply
                      0
                      • J Joan M

                        1. I don't know if this is the problem or not... but it seems that you've derived the CGrapDlg class from a CView not from a CDialog... 2. this is not a problem, only a typo that makes things clearer: if you derive from a dialog write xxxdlg and if you derive from a window write xxxwnd (only if you want of course). 3. I don't understand the use of the "link" var: if you have declared plotGraph inside (as a member of) the CGrapDlg class you don't need that, because PlotGraph it's unique and property of the actual instance of CGrapDlg. (Be sure not ot miss the fact that the handle (if that is what Plot(DC,Handle)) needs is not a numeric ID that can be assigned... Each window has its own handle that can be obtained using GetWndHandle() (memory obtained (don't trust a lot the last part)). Hope this helps.

                        R Offline
                        R Offline
                        raner
                        wrote on last edited by
                        #11

                        1. No, i derived CGrapDlg from CDialog,not CView, but i passed a CView parameter into its constructor because a tutorial i was following did that and because i was creating CGrapDlg from my CView class. 3. yes, plotGraph is a member of CGrapDlg and "link" is just a variable needed for my program to know where to retrieve data for my drawing purposes, it's not a handle. is there any problem with the way i'm creating the modeless dialog? thks thks

                        J 1 Reply Last reply
                        0
                        • R raner

                          1. No, i derived CGrapDlg from CDialog,not CView, but i passed a CView parameter into its constructor because a tutorial i was following did that and because i was creating CGrapDlg from my CView class. 3. yes, plotGraph is a member of CGrapDlg and "link" is just a variable needed for my program to know where to retrieve data for my drawing purposes, it's not a handle. is there any problem with the way i'm creating the modeless dialog? thks thks

                          J Offline
                          J Offline
                          Joan M
                          wrote on last edited by
                          #12

                          AArgh! sorry! I didn't see the ": CDialog" !!!! (how do I hate this sort of things...) There isn't any problem in your dialog creation... Place a breakpoint, a TRACE or something else at the beggining of the function (OnPaint) in order to know if it is being called or not. Once you'll know if the f(x) is being called or not, if the function is being called, try to know if the DC that you are getting is the right one drawing something easy to it... If the function is not called try to place its content in the OnErasebackground handler (I don't remember where, but I have read that the right place to process the drawing messages in the dialogs is that function). hope this helps...

                          https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                          R 1 Reply Last reply
                          0
                          • J Joan M

                            AArgh! sorry! I didn't see the ": CDialog" !!!! (how do I hate this sort of things...) There isn't any problem in your dialog creation... Place a breakpoint, a TRACE or something else at the beggining of the function (OnPaint) in order to know if it is being called or not. Once you'll know if the f(x) is being called or not, if the function is being called, try to know if the DC that you are getting is the right one drawing something easy to it... If the function is not called try to place its content in the OnErasebackground handler (I don't remember where, but I have read that the right place to process the drawing messages in the dialogs is that function). hope this helps...

                            R Offline
                            R Offline
                            raner
                            wrote on last edited by
                            #13

                            thks for your reply. as u suggested, i try debugging and found out that OnPaint() was called and entered.Below, is relevant code snippet in OnPaint().It was found though, that "plotGraph.Plot(pDC,link)" was not executed.plotGraph is a CObject-derived class and Plot(CDC *pDC,int link) is the function definition...link var is just for my own program purpose.

                            CWnd\* graphFrame = (CWnd\*)GetDlgItem(IDC\_GRAPH\_FRAME);
                            CDC\* pDC = graphFrame->GetDC();
                            plotGraph.Plot(pDC,link);
                            

                            The odd thing is this had worked fine while i was using modal dialog boxes. any idea what is or might be wrong? a big thank you.

                            J 1 Reply Last reply
                            0
                            • R raner

                              thks for your reply. as u suggested, i try debugging and found out that OnPaint() was called and entered.Below, is relevant code snippet in OnPaint().It was found though, that "plotGraph.Plot(pDC,link)" was not executed.plotGraph is a CObject-derived class and Plot(CDC *pDC,int link) is the function definition...link var is just for my own program purpose.

                              CWnd\* graphFrame = (CWnd\*)GetDlgItem(IDC\_GRAPH\_FRAME);
                              CDC\* pDC = graphFrame->GetDC();
                              plotGraph.Plot(pDC,link);
                              

                              The odd thing is this had worked fine while i was using modal dialog boxes. any idea what is or might be wrong? a big thank you.

                              J Offline
                              J Offline
                              Joan M
                              wrote on last edited by
                              #14

                              Seeing this I can only tell you: NOTE: surely the things that I'll tell you will be very obvious for you, but let's give it a try, who knows... 1. check if you are getting the right pointer to graphFrame. 2. Once you will be sure that the right pointer is obtained, then you should check if the pDC variable is getting the desired value. 3. After all this... you should check if the link var points to where it should(or have the value it should)... 4. the most fool thing to check... sometimes the compiler gets mad and only a deletion of some files and a full rebuild gets it to work... but before doing so... raner wrote: "plotGraph.Plot(pDC,link)" was not executed please, place a do_nothing little bit of code like the next one before and after that line in order to see if the execution gets broken before or during that line call.

                              if (true)
                              {
                              plotGraph.Plot(pDC,link);
                              }

                              Using that piece of code you'll be able to see if you enter inside the if clause or not... and you'll be able to see if the error comes before that call or not... 5. if you have the font code of the plotGraph class, try to debug the Plot function in order to know what is happening, hope this helps...

                              https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                              R 1 Reply Last reply
                              0
                              • J Joan M

                                Seeing this I can only tell you: NOTE: surely the things that I'll tell you will be very obvious for you, but let's give it a try, who knows... 1. check if you are getting the right pointer to graphFrame. 2. Once you will be sure that the right pointer is obtained, then you should check if the pDC variable is getting the desired value. 3. After all this... you should check if the link var points to where it should(or have the value it should)... 4. the most fool thing to check... sometimes the compiler gets mad and only a deletion of some files and a full rebuild gets it to work... but before doing so... raner wrote: "plotGraph.Plot(pDC,link)" was not executed please, place a do_nothing little bit of code like the next one before and after that line in order to see if the execution gets broken before or during that line call.

                                if (true)
                                {
                                plotGraph.Plot(pDC,link);
                                }

                                Using that piece of code you'll be able to see if you enter inside the if clause or not... and you'll be able to see if the error comes before that call or not... 5. if you have the font code of the plotGraph class, try to debug the Plot function in order to know what is happening, hope this helps...

                                R Offline
                                R Offline
                                raner
                                wrote on last edited by
                                #15

                                i noted down your suggestions and will try them to debug my pgm..in the meantime..u have any idea where to set the message map for OnEraseBackground?...because i cant find it in the Class Wizard. really grateful for your help :-O

                                J 1 Reply Last reply
                                0
                                • R raner

                                  i noted down your suggestions and will try them to debug my pgm..in the meantime..u have any idea where to set the message map for OnEraseBackground?...because i cant find it in the Class Wizard. really grateful for your help :-O

                                  J Offline
                                  J Offline
                                  Joan M
                                  wrote on last edited by
                                  #16

                                  You should right-click your dialog class in the class wizard, and then, select "Add Windows Message Handler", once this has been done, in the "Filter for messages available to class" combobox (right bottom of the dialog), select "WINDOW". Now, you have only to select "WM_ERASEBKGND" from the "New Windows messages/events" listbox (left top of the dialog), after that you have to press the Add and Edit button. Hope this helps...

                                  https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                                  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