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. How can Create new rect with width?

How can Create new rect with width?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
10 Posts 4 Posters 1 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.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, I have a Rect, e.g: CRect rect=CRect(10,20,20,40); i have new width for rect like 80. now how can i create rect with this width and other values are remains same. please help me for this. thanks in advance.

    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

    H CPalliniC M 3 Replies Last reply
    0
    • L Le rner

      Hi all, I have a Rect, e.g: CRect rect=CRect(10,20,20,40); i have new width for rect like 80. now how can i create rect with this width and other values are remains same. please help me for this. thanks in advance.

      IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

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

      I think you can use of CRect::DeflateRect.

      Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

      L 1 Reply Last reply
      0
      • H Hamid Taebi

        I think you can use of CRect::DeflateRect.

        Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #3

        Hamid. wrote:

        CRect::DeflateRect.

        but this use for Decreases the width and height of CRect.

        IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

        H 1 Reply Last reply
        0
        • L Le rner

          Hi all, I have a Rect, e.g: CRect rect=CRect(10,20,20,40); i have new width for rect like 80. now how can i create rect with this width and other values are remains same. please help me for this. thanks in advance.

          IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          rect.InflateRect(0,0,70,0);

          :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          L 1 Reply Last reply
          0
          • CPalliniC CPallini

            rect.InflateRect(0,0,70,0);

            :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            L Offline
            L Offline
            Le rner
            wrote on last edited by
            #5

            please explain why this.

            IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

            CPalliniC 1 Reply Last reply
            0
            • L Le rner

              please explain why this.

              IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Your original rect (10,20,20,40) has

              width = right - left = 20 - 10 = 10 pixels.

              If you want it 80 pixels wide (with minimum change on coordinates) then you should move its right side 70 pixels to the right:

              leftnew = left;
              rightnew = right + 70; // now width = rightnew - leftnew = 80
              topnew = top;
              bottomnew = bottom;

              That's what InflateRect(0,0,70,0) does. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              L 1 Reply Last reply
              0
              • CPalliniC CPallini

                Your original rect (10,20,20,40) has

                width = right - left = 20 - 10 = 10 pixels.

                If you want it 80 pixels wide (with minimum change on coordinates) then you should move its right side 70 pixels to the right:

                leftnew = left;
                rightnew = right + 70; // now width = rightnew - leftnew = 80
                topnew = top;
                bottomnew = bottom;

                That's what InflateRect(0,0,70,0) does. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                L Offline
                L Offline
                Le rner
                wrote on last edited by
                #7

                thanks , if new width is decrease so i can use DeflateRect or InflateRect.

                IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                CPalliniC 1 Reply Last reply
                0
                • L Le rner

                  Hamid. wrote:

                  CRect::DeflateRect.

                  but this use for Decreases the width and height of CRect.

                  IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

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

                  You can decrease your width of current width with this function.

                  Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

                  1 Reply Last reply
                  0
                  • L Le rner

                    thanks , if new width is decrease so i can use DeflateRect or InflateRect.

                    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #9

                    You may also use inflate with negative values. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    In testa che avete, signor di Ceprano?

                    1 Reply Last reply
                    0
                    • L Le rner

                      Hi all, I have a Rect, e.g: CRect rect=CRect(10,20,20,40); i have new width for rect like 80. now how can i create rect with this width and other values are remains same. please help me for this. thanks in advance.

                      IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                      M Offline
                      M Offline
                      Michael Dunn
                      wrote on last edited by
                      #10

                      Juat assign a new value to the right member:

                      rect.right = rect.left + the_new_width;

                      --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

                      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