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. Problem using then event of OnSize

Problem using then event of OnSize

Scheduled Pinned Locked Moved C / C++ / MFC
databasecomhelptutorialquestion
13 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.
  • N Offline
    N Offline
    Nothend
    wrote on last edited by
    #1

    I built a demo project that using OLE-DB,I add two controls on my form (Single Document),one is DataGrid,the other is ADODC,What my purpose is that I want to resize the size of the two controls when the form shows,the variables that connect to the two controls are m_DataGrid and m_AdoDC; the code is as followed: void CADO2View::OnSize(UINT nType, int cx, int cy) { int iHeight; int iWidth; CRect oRect; COleDBRecordView::OnSize(nType, cx, cy); if (m_AdoDC.m_hWnd==NULL||m_DataGrid.m_hWnd==NULL) { return; } else { m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE); } } But the code doesn't work,so how to resize the controls when the form shows? Nothend -- modified at 19:51 Monday 8th January, 2007

    C H 3 Replies Last reply
    0
    • N Nothend

      I built a demo project that using OLE-DB,I add two controls on my form (Single Document),one is DataGrid,the other is ADODC,What my purpose is that I want to resize the size of the two controls when the form shows,the variables that connect to the two controls are m_DataGrid and m_AdoDC; the code is as followed: void CADO2View::OnSize(UINT nType, int cx, int cy) { int iHeight; int iWidth; CRect oRect; COleDBRecordView::OnSize(nType, cx, cy); if (m_AdoDC.m_hWnd==NULL||m_DataGrid.m_hWnd==NULL) { return; } else { m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE); } } But the code doesn't work,so how to resize the controls when the form shows? Nothend -- modified at 19:51 Monday 8th January, 2007

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Nothend wrote:

      But the code doesn't work,so how to resize the controls when the form shows?

      What happens exaclty ? What does 'not working' mean ? Also, use the pre or code tag when you post code (it will make it more readable)


      Cédric Moonen Software developer
      Charting control [v1.1]

      N 1 Reply Last reply
      0
      • N Nothend

        I built a demo project that using OLE-DB,I add two controls on my form (Single Document),one is DataGrid,the other is ADODC,What my purpose is that I want to resize the size of the two controls when the form shows,the variables that connect to the two controls are m_DataGrid and m_AdoDC; the code is as followed: void CADO2View::OnSize(UINT nType, int cx, int cy) { int iHeight; int iWidth; CRect oRect; COleDBRecordView::OnSize(nType, cx, cy); if (m_AdoDC.m_hWnd==NULL||m_DataGrid.m_hWnd==NULL) { return; } else { m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE); } } But the code doesn't work,so how to resize the controls when the form shows? Nothend -- modified at 19:51 Monday 8th January, 2007

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Well, I didn't look at all the details of your code for my previous answer (your explanation was a bit vague). But I think the problem is here:

        Nothend wrote:

        m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE);

        You said that m_AdoDC is a member of your class, so it will never resize. The only thing that is resizing is your view. So what you need to do is retrieve the new size of your view (using GetClientRect) and then calculate the new sizes of the two other controls.


        Cédric Moonen Software developer
        Charting control [v1.1]

        N 1 Reply Last reply
        0
        • C Cedric Moonen

          Nothend wrote:

          But the code doesn't work,so how to resize the controls when the form shows?

          What happens exaclty ? What does 'not working' mean ? Also, use the pre or code tag when you post code (it will make it more readable)


          Cédric Moonen Software developer
          Charting control [v1.1]

          N Offline
          N Offline
          Nothend
          wrote on last edited by
          #4

          I am sorry about that,because I am a student from China,my English is poor. What I want is that when the view shows,the DataGrid and the ADODC will position the right place on the form(view),not the place I put when using the control bar. As the code shows that,the event of OnSize takes place first than that of DoDataExchange,so the two variables(m_AdoDC and m_DataGrid) are null when OnSize takes place. I use PostMessage(WM_SIZE) in the event of OnInitialUpdate,and then it happpens,but the control ADODC doesn't move when I pull the form ,and the DataGrid does. So how can I do ? Thanks a lot! Nothend

          1 Reply Last reply
          0
          • C Cedric Moonen

            Well, I didn't look at all the details of your code for my previous answer (your explanation was a bit vague). But I think the problem is here:

            Nothend wrote:

            m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE);

            You said that m_AdoDC is a member of your class, so it will never resize. The only thing that is resizing is your view. So what you need to do is retrieve the new size of your view (using GetClientRect) and then calculate the new sizes of the two other controls.


            Cédric Moonen Software developer
            Charting control [v1.1]

            N Offline
            N Offline
            Nothend
            wrote on last edited by
            #5

            I am sorry about that,because I am a student from China,my English is poor. What I want is that when the view shows,the DataGrid and the ADODC will position the right place on the form(view),not the place I put when using the control bar. As the code shows that,the event of OnSize takes place first than that of DoDataExchange,so the two variables(m_AdoDC and m_DataGrid) are null when OnSize takes place. I use PostMessage(WM_SIZE) in the event of OnInitialUpdate,and then it happpens,but the control ADODC doesn't move when I pull the form ,and the DataGrid does. So how can I do ? Thanks a lot!

            H 1 Reply Last reply
            0
            • N Nothend

              I built a demo project that using OLE-DB,I add two controls on my form (Single Document),one is DataGrid,the other is ADODC,What my purpose is that I want to resize the size of the two controls when the form shows,the variables that connect to the two controls are m_DataGrid and m_AdoDC; the code is as followed: void CADO2View::OnSize(UINT nType, int cx, int cy) { int iHeight; int iWidth; CRect oRect; COleDBRecordView::OnSize(nType, cx, cy); if (m_AdoDC.m_hWnd==NULL||m_DataGrid.m_hWnd==NULL) { return; } else { m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE); } } But the code doesn't work,so how to resize the controls when the form shows? Nothend -- modified at 19:51 Monday 8th January, 2007

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Why it dosent work?


              WhiteSky


              N 1 Reply Last reply
              0
              • N Nothend

                I am sorry about that,because I am a student from China,my English is poor. What I want is that when the view shows,the DataGrid and the ADODC will position the right place on the form(view),not the place I put when using the control bar. As the code shows that,the event of OnSize takes place first than that of DoDataExchange,so the two variables(m_AdoDC and m_DataGrid) are null when OnSize takes place. I use PostMessage(WM_SIZE) in the event of OnInitialUpdate,and then it happpens,but the control ADODC doesn't move when I pull the form ,and the DataGrid does. So how can I do ? Thanks a lot!

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                You can use of SendMessage(WM_SIZE)


                WhiteSky


                1 Reply Last reply
                0
                • H Hamid Taebi

                  Why it dosent work?


                  WhiteSky


                  N Offline
                  N Offline
                  Nothend
                  wrote on last edited by
                  #8

                  Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null. I have used the PostMessage(WM_SIZE),it works,but the ADODC control can't move,I don't know why. Thanks Nothend

                  H P 2 Replies Last reply
                  0
                  • N Nothend

                    Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null. I have used the PostMessage(WM_SIZE),it works,but the ADODC control can't move,I don't know why. Thanks Nothend

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #9

                    What happens if you insert ScreenToClient/*for converts coordinates */ after m_AdoDC.GetClientRect(oRect);

                    m_AdoDC.GetClientRect(oRect);
                    m_AdoDC.ScreenToClient(oRect);


                    WhiteSky


                    N 2 Replies Last reply
                    0
                    • N Nothend

                      Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null. I have used the PostMessage(WM_SIZE),it works,but the ADODC control can't move,I don't know why. Thanks Nothend

                      P Offline
                      P Offline
                      prasad_som
                      wrote on last edited by
                      #10

                      Nothend wrote:

                      Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null.

                      Call UpdateData as first statement in OnSize, which eventually calls DoDataExchange.

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      N 1 Reply Last reply
                      0
                      • H Hamid Taebi

                        What happens if you insert ScreenToClient/*for converts coordinates */ after m_AdoDC.GetClientRect(oRect);

                        m_AdoDC.GetClientRect(oRect);
                        m_AdoDC.ScreenToClient(oRect);


                        WhiteSky


                        N Offline
                        N Offline
                        Nothend
                        wrote on last edited by
                        #11

                        It's all the same . Nothing happen. Nothend

                        1 Reply Last reply
                        0
                        • H Hamid Taebi

                          What happens if you insert ScreenToClient/*for converts coordinates */ after m_AdoDC.GetClientRect(oRect);

                          m_AdoDC.GetClientRect(oRect);
                          m_AdoDC.ScreenToClient(oRect);


                          WhiteSky


                          N Offline
                          N Offline
                          Nothend
                          wrote on last edited by
                          #12

                          Do you mind that I send you a email including the demo code to you? Nothend

                          1 Reply Last reply
                          0
                          • P prasad_som

                            Nothend wrote:

                            Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null.

                            Call UpdateData as first statement in OnSize, which eventually calls DoDataExchange.

                            Prasad Notifier using ATL | Operator new[],delete[][^]

                            N Offline
                            N Offline
                            Nothend
                            wrote on last edited by
                            #13

                            I have tried that ,but it would be error. It will show error dialog saying that "Debug Assertion Failed",and if I retry,the XP sends me a error report. Nothend

                            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