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. Placing the dialog bar

Placing the dialog bar

Scheduled Pinned Locked Moved C / C++ / MFC
15 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.
  • M manoharbalu

    It's not doing any changes. m_SysWnd.MoveWindow(100,100,100,100,true); //New positions Am I missing anything?

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #6

    manoharbalu wrote:

    Am I missing anything?

    Without seeing all the relevant code, we would be guessing at best. What is m_SysWnd? Where are you calling MoveWindow() from?

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    1 Reply Last reply
    0
    • M manoharbalu

      It's not doing any changes. m_SysWnd.MoveWindow(100,100,100,100,true); //New positions Am I missing anything?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #7

      I have just run a simple test and it works fine. The only difference is that I am using basic Win32 rather than MFC.

      1 Reply Last reply
      0
      • M manoharbalu

        It's not doing any changes. m_SysWnd.MoveWindow(100,100,100,100,true); //New positions Am I missing anything?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #8

        Here is what I have:

        RECT rectParent, rectDialog;
        SIZE sizeParent, sizeDialog;
        POINT point;

        // get the size of the dialog
        GetWindowRect(hDialog, &rectDialog);
        sizeDialog.cx = rectDialog.right - rectDialog.left;
        sizeDialog.cy = rectDialog.bottom - rectDialog.top;

        // get the size of the parent Window's client area
        GetClientRect(GetParent(hDialog), &rectParent);
        sizeParent.cx = rectParent.right - rectParent.left;
        sizeParent.cy = rectParent.bottom - rectParent.top;

        // parent's sizes minus dialog's sizes divided by 2
        // give the coordinates of the centre position
        point.x = (sizeParent.cx - sizeDialog.cx) / 2;
        point.y = (sizeParent.cy - sizeDialog.cy) / 2;
        // we need to make parent coordinates relative to the screen
        ClientToScreen(GetParent(hDialog), &point);

        // now move the Window to the new position
        MoveWindow(hDialog, point.x, point.y, sizeDialog.cx, sizeDialog.cy, true);

        M 1 Reply Last reply
        0
        • L Lost User

          Here is what I have:

          RECT rectParent, rectDialog;
          SIZE sizeParent, sizeDialog;
          POINT point;

          // get the size of the dialog
          GetWindowRect(hDialog, &rectDialog);
          sizeDialog.cx = rectDialog.right - rectDialog.left;
          sizeDialog.cy = rectDialog.bottom - rectDialog.top;

          // get the size of the parent Window's client area
          GetClientRect(GetParent(hDialog), &rectParent);
          sizeParent.cx = rectParent.right - rectParent.left;
          sizeParent.cy = rectParent.bottom - rectParent.top;

          // parent's sizes minus dialog's sizes divided by 2
          // give the coordinates of the centre position
          point.x = (sizeParent.cx - sizeDialog.cx) / 2;
          point.y = (sizeParent.cy - sizeDialog.cy) / 2;
          // we need to make parent coordinates relative to the screen
          ClientToScreen(GetParent(hDialog), &point);

          // now move the Window to the new position
          MoveWindow(hDialog, point.x, point.y, sizeDialog.cx, sizeDialog.cy, true);

          M Offline
          M Offline
          manoharbalu
          wrote on last edited by
          #9

          Thanks for your reply. I have changed the same code which you had sent to MFC as shown below. But still its not working. Please help me what is wrong..? // MainFrm.h CSysWindow m_SysWnd; //CSysWindow derived from CDialogbar // MainFrm.CPP int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!m_SysWnd.Create(this, IDD_SYS2,CBRS_TOP|CBRS_FLYBY|CBRS_TOOLTIPS, IDD_SYS2)) { TRACE0("Failed to create DlgBar\n"); return -1; // fail to create } m_SysWnd.SetBarStyle( m_SysWnd.GetBarStyle()| CBRS_ALIGN_TOP|CBRS_BORDER_TOP | CBRS_FLOAT_MULTI ); m_SysWnd.AttachCtrls(); //To Attach the Combo box to the control bar window RECT rectParent, rectDialog; SIZE sizeParent, sizeDialog; POINT pointNew; HWND hDialog = m_SysWnd.m_hWnd; CWnd * hParentWnd = m_SysWnd.GetParent(); // get the size of the dialog m_SysWnd.GetWindowRect(&rectDialog); sizeDialog.cx = rectDialog.right - rectDialog.left; sizeDialog.cy = rectDialog.bottom - rectDialog.top; // get the size of the parent Window's client area hParentWnd->GetClientRect(&rectParent); sizeParent.cx = rectParent.right - rectParent.left; sizeParent.cy = rectParent.bottom - rectParent.top; // parent's sizes minus dialog's sizes divided by 2 // give the coordinates of the centre position pointNew.x = (sizeParent.cx - sizeDialog.cx) / 2; pointNew.y = (sizeParent.cy - sizeDialog.cy) / 2; // we need to make parent coordinates relative to the screen hParentWnd->ClientToScreen(&pointNew); // now move the Window to the new position m_SysWnd.MoveWindow(pointNew.x, pointNew.y, sizeDialog.cx, sizeDialog.cy, true);

          M L 3 Replies Last reply
          0
          • M manoharbalu

            Thanks for your reply. I have changed the same code which you had sent to MFC as shown below. But still its not working. Please help me what is wrong..? // MainFrm.h CSysWindow m_SysWnd; //CSysWindow derived from CDialogbar // MainFrm.CPP int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!m_SysWnd.Create(this, IDD_SYS2,CBRS_TOP|CBRS_FLYBY|CBRS_TOOLTIPS, IDD_SYS2)) { TRACE0("Failed to create DlgBar\n"); return -1; // fail to create } m_SysWnd.SetBarStyle( m_SysWnd.GetBarStyle()| CBRS_ALIGN_TOP|CBRS_BORDER_TOP | CBRS_FLOAT_MULTI ); m_SysWnd.AttachCtrls(); //To Attach the Combo box to the control bar window RECT rectParent, rectDialog; SIZE sizeParent, sizeDialog; POINT pointNew; HWND hDialog = m_SysWnd.m_hWnd; CWnd * hParentWnd = m_SysWnd.GetParent(); // get the size of the dialog m_SysWnd.GetWindowRect(&rectDialog); sizeDialog.cx = rectDialog.right - rectDialog.left; sizeDialog.cy = rectDialog.bottom - rectDialog.top; // get the size of the parent Window's client area hParentWnd->GetClientRect(&rectParent); sizeParent.cx = rectParent.right - rectParent.left; sizeParent.cy = rectParent.bottom - rectParent.top; // parent's sizes minus dialog's sizes divided by 2 // give the coordinates of the centre position pointNew.x = (sizeParent.cx - sizeDialog.cx) / 2; pointNew.y = (sizeParent.cy - sizeDialog.cy) / 2; // we need to make parent coordinates relative to the screen hParentWnd->ClientToScreen(&pointNew); // now move the Window to the new position m_SysWnd.MoveWindow(pointNew.x, pointNew.y, sizeDialog.cx, sizeDialog.cy, true);

            M Offline
            M Offline
            mo1492
            wrote on last edited by
            #10

            MFC handles the docking state and sizing of control bars. Your code does not show that you are docking the control bar; are you? After creation of m_SysWnd: m_SysWnd.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); // CMainFrame enable docking DockControlBar(&m_wndDlgBar); // CMainFrame dock control bar As far as moving the bar to a specific location look at CMainFrame::FloatControlBar() which undocks the controlbar and allows for positioning. FloatControlBar(&m_SysWnd,CPoint(100,100)); In regards to resizing the bar, you will probably have to provide some implementation of CDialogBar::CalcFixedLayout() or CDialogBar::CalcDynamicLayout() override which provides size info. CSize CSysWindow::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { if (bStretch) // if not docked stretch to fit { // This is a fixed size. You will have to provide your own implementation. return CSize(100,100); //return CSize(bHorz ? 32767 : m_sizeDefault.cx, // bHorz ? m_sizeDefault.cy : 32767); } else return m_sizeDefault; } A Google search on these functions may help. Best regards.

            1 Reply Last reply
            0
            • M manoharbalu

              Thanks for your reply. I have changed the same code which you had sent to MFC as shown below. But still its not working. Please help me what is wrong..? // MainFrm.h CSysWindow m_SysWnd; //CSysWindow derived from CDialogbar // MainFrm.CPP int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!m_SysWnd.Create(this, IDD_SYS2,CBRS_TOP|CBRS_FLYBY|CBRS_TOOLTIPS, IDD_SYS2)) { TRACE0("Failed to create DlgBar\n"); return -1; // fail to create } m_SysWnd.SetBarStyle( m_SysWnd.GetBarStyle()| CBRS_ALIGN_TOP|CBRS_BORDER_TOP | CBRS_FLOAT_MULTI ); m_SysWnd.AttachCtrls(); //To Attach the Combo box to the control bar window RECT rectParent, rectDialog; SIZE sizeParent, sizeDialog; POINT pointNew; HWND hDialog = m_SysWnd.m_hWnd; CWnd * hParentWnd = m_SysWnd.GetParent(); // get the size of the dialog m_SysWnd.GetWindowRect(&rectDialog); sizeDialog.cx = rectDialog.right - rectDialog.left; sizeDialog.cy = rectDialog.bottom - rectDialog.top; // get the size of the parent Window's client area hParentWnd->GetClientRect(&rectParent); sizeParent.cx = rectParent.right - rectParent.left; sizeParent.cy = rectParent.bottom - rectParent.top; // parent's sizes minus dialog's sizes divided by 2 // give the coordinates of the centre position pointNew.x = (sizeParent.cx - sizeDialog.cx) / 2; pointNew.y = (sizeParent.cy - sizeDialog.cy) / 2; // we need to make parent coordinates relative to the screen hParentWnd->ClientToScreen(&pointNew); // now move the Window to the new position m_SysWnd.MoveWindow(pointNew.x, pointNew.y, sizeDialog.cx, sizeDialog.cy, true);

              M Offline
              M Offline
              mo1492
              wrote on last edited by
              #11

              Sorry, this is the correct code: CSize CSysWindow::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { if (bStretch) // if not docked stretch to fit { return CDialogBar::CalcFixedLayout(bStretch, bHorz); } else // This is a fixed size. You will have to provide your own implementation. return CSize(100,100); }

              M 1 Reply Last reply
              0
              • M manoharbalu

                Thanks for your reply. I have changed the same code which you had sent to MFC as shown below. But still its not working. Please help me what is wrong..? // MainFrm.h CSysWindow m_SysWnd; //CSysWindow derived from CDialogbar // MainFrm.CPP int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!m_SysWnd.Create(this, IDD_SYS2,CBRS_TOP|CBRS_FLYBY|CBRS_TOOLTIPS, IDD_SYS2)) { TRACE0("Failed to create DlgBar\n"); return -1; // fail to create } m_SysWnd.SetBarStyle( m_SysWnd.GetBarStyle()| CBRS_ALIGN_TOP|CBRS_BORDER_TOP | CBRS_FLOAT_MULTI ); m_SysWnd.AttachCtrls(); //To Attach the Combo box to the control bar window RECT rectParent, rectDialog; SIZE sizeParent, sizeDialog; POINT pointNew; HWND hDialog = m_SysWnd.m_hWnd; CWnd * hParentWnd = m_SysWnd.GetParent(); // get the size of the dialog m_SysWnd.GetWindowRect(&rectDialog); sizeDialog.cx = rectDialog.right - rectDialog.left; sizeDialog.cy = rectDialog.bottom - rectDialog.top; // get the size of the parent Window's client area hParentWnd->GetClientRect(&rectParent); sizeParent.cx = rectParent.right - rectParent.left; sizeParent.cy = rectParent.bottom - rectParent.top; // parent's sizes minus dialog's sizes divided by 2 // give the coordinates of the centre position pointNew.x = (sizeParent.cx - sizeDialog.cx) / 2; pointNew.y = (sizeParent.cy - sizeDialog.cy) / 2; // we need to make parent coordinates relative to the screen hParentWnd->ClientToScreen(&pointNew); // now move the Window to the new position m_SysWnd.MoveWindow(pointNew.x, pointNew.y, sizeDialog.cx, sizeDialog.cy, true);

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #12

                I cannot see anything obvious in your code, although you may need to put that code at a later point; perhaps in the toolbar's OnCreate method. Looking at the documentation it suggests that a CToolBar should include the WS_CHILD style at creation, but you do not include that. Unfortunately I do not use MFC so I cannot recreate your situation. If it still does not work then you will need to use your debugger to see what is happening.

                1 Reply Last reply
                0
                • M mo1492

                  Sorry, this is the correct code: CSize CSysWindow::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { if (bStretch) // if not docked stretch to fit { return CDialogBar::CalcFixedLayout(bStretch, bHorz); } else // This is a fixed size. You will have to provide your own implementation. return CSize(100,100); }

                  M Offline
                  M Offline
                  manoharbalu
                  wrote on last edited by
                  #13

                  Thanks for your kind reply. Please help me to create a single window that has the following in the client area: 1. Dialog bar on top (used as a toolbar) 2. A view to display a graph trend (Updated every cycle) 3. After the above view, a Dialog bar to be placed. (Used as a tool bar) 4. A Grid control to display set of values which will be updated every cycle. As I am not an expert into this, Please guide me steps to create the above window and update it every cycle as defined.

                  M 1 Reply Last reply
                  0
                  • M manoharbalu

                    Thanks for your kind reply. Please help me to create a single window that has the following in the client area: 1. Dialog bar on top (used as a toolbar) 2. A view to display a graph trend (Updated every cycle) 3. After the above view, a Dialog bar to be placed. (Used as a tool bar) 4. A Grid control to display set of values which will be updated every cycle. As I am not an expert into this, Please guide me steps to create the above window and update it every cycle as defined.

                    M Offline
                    M Offline
                    mo1492
                    wrote on last edited by
                    #14

                    Sorry, the group does not write code for you. See How to Ask a Question at the top. If you are not familiar with these tasks, you need to get training on programming in MFC. I've learned a lot just by using Google to search for tasks I want to perform in MFC and in many cases finding example code that helped me get the task done. If you write code to perform a task and it doesn't work as expected, then ask the group for help with the particular section of your code that isn't working and they will help you; like you did with your current question. Best regards

                    M 1 Reply Last reply
                    0
                    • M mo1492

                      Sorry, the group does not write code for you. See How to Ask a Question at the top. If you are not familiar with these tasks, you need to get training on programming in MFC. I've learned a lot just by using Google to search for tasks I want to perform in MFC and in many cases finding example code that helped me get the task done. If you write code to perform a task and it doesn't work as expected, then ask the group for help with the particular section of your code that isn't working and they will help you; like you did with your current question. Best regards

                      M Offline
                      M Offline
                      manoharbalu
                      wrote on last edited by
                      #15

                      Sorry for that. As you said I will refer google. Thanks

                      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