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. line thinkness

line thinkness

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresjsonhelp
25 Posts 6 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 arun_pk

    int paint_line(HWND hwnd, HDC hdc, int x0, int y0, int x9, int y9, int thickness, COLORREF rgb) { HBRUSH hbr; HPEN hpen, hpen_sav; hpen = CreatePen(PS_SOLID, thickness, rgb); hpen_sav = (HPEN) SelectObject(hdc, hpen); hbr = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); MoveToEx(hdc, x0, y0, NULL); LineTo(hdc, x9, y9); DeleteObject(SelectObject(hdc, hbr)); SelectObject(hdc, hpen_sav); DeleteObject(hpen); return 0; }

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

    Your code is fine, I called it this way:

    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    paint_line(hWnd, hdc, 0, 0, 400, 400, 5, RGB(255,0,0));
    EndPaint(hWnd, &ps);
    break;

    and got a beautiful red thick line in my window. :)

    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?

    A 2 Replies Last reply
    0
    • A arun_pk

      int paint_line(HWND hwnd, HDC hdc, int x0, int y0, int x9, int y9, int thickness, COLORREF rgb) { HBRUSH hbr; HPEN hpen, hpen_sav; hpen = CreatePen(PS_SOLID, thickness, rgb); hpen_sav = (HPEN) SelectObject(hdc, hpen); hbr = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); MoveToEx(hdc, x0, y0, NULL); LineTo(hdc, x9, y9); DeleteObject(SelectObject(hdc, hbr)); SelectObject(hdc, hpen_sav); DeleteObject(hpen); return 0; }

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #6

      Have you set any mapping mode at the DC ? :) (did you tried with thickness = 100 ?)

      virtual void BeHappy() = 0;

      A 1 Reply Last reply
      0
      • C Code o mat

        Are you completely sure your thickness parameter's value isn't 0 or 1 when you call your paint_line function? Aside of that i believe what line widths and styles you can use depends on the driver "behind" the DC, are you maybe drawing onto some "special" target, like a PDF writer or -dunno- a plotter machine's printer driver or somesuch?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

        A Offline
        A Offline
        arun_pk
        wrote on last edited by
        #7

        thanks for the reply I have tried from 0 to 50... :( but no change in the thickness.... i m plotting line in Wingdi normal graph

        L C 2 Replies Last reply
        0
        • E Eugen Podsypalnikov

          Have you set any mapping mode at the DC ? :) (did you tried with thickness = 100 ?)

          virtual void BeHappy() = 0;

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

          sorry Eugen i am a beginer.I am not sure with Mapping Mode

          E 1 Reply Last reply
          0
          • A arun_pk

            sorry Eugen i am a beginer.I am not sure with Mapping Mode

            E Offline
            E Offline
            Eugen Podsypalnikov
            wrote on last edited by
            #9

            Could you post your calling context of the function too ? :) (it is a function that does call the paint_line(..) function)

            virtual void BeHappy() = 0;

            A 1 Reply Last reply
            0
            • A arun_pk

              thanks for the reply I have tried from 0 to 50... :( but no change in the thickness.... i m plotting line in Wingdi normal graph

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

              Use the debugger to trace through your function to see what exact value is being passed in the thickness parameter. It is likely that you are not passing this parameter correctly.

              txtspeak is the realm of 9 year old children, not developers. Christian Graus

              1 Reply Last reply
              0
              • CPalliniC CPallini

                Your code is fine, I called it this way:

                case WM_PAINT:
                hdc = BeginPaint(hWnd, &ps);
                paint_line(hWnd, hdc, 0, 0, 400, 400, 5, RGB(255,0,0));
                EndPaint(hWnd, &ps);
                break;

                and got a beautiful red thick line in my window. :)

                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]

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

                I m working on a maintanance project which is too big. the same code which i send to you is been used in my project but its not working .is there any possiblity to set some default thickness of lines throughout the graph.i scare that like that some handling has been done .. because i even tried till 50...

                1 Reply Last reply
                0
                • A arun_pk

                  thanks for the reply I have tried from 0 to 50... :( but no change in the thickness.... i m plotting line in Wingdi normal graph

                  C Offline
                  C Offline
                  Code o mat
                  wrote on last edited by
                  #12

                  Place a breakpoint on the beginning of your paint_line method and once it gets hit, check the thickness parameter's value to see if it really is not 0 or 1.

                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

                  A 2 Replies Last reply
                  0
                  • E Eugen Podsypalnikov

                    Could you post your calling context of the function too ? :) (it is a function that does call the paint_line(..) function)

                    virtual void BeHappy() = 0;

                    A Offline
                    A Offline
                    arun_pk
                    wrote on last edited by
                    #13

                    inside paint line this is the portion where i create a pen hpen = CreatePen(PS_SOLID, thickness, rgb); i have tried like giving hpen = CreatePen(PS_SOLID, 0, rgb); . . . . . . . . . . . hpen = CreatePen(PS_SOLID, 50, rgb);

                    E 1 Reply Last reply
                    0
                    • A arun_pk

                      inside paint line this is the portion where i create a pen hpen = CreatePen(PS_SOLID, thickness, rgb); i have tried like giving hpen = CreatePen(PS_SOLID, 0, rgb); . . . . . . . . . . . hpen = CreatePen(PS_SOLID, 50, rgb);

                      E Offline
                      E Offline
                      Eugen Podsypalnikov
                      wrote on last edited by
                      #14

                      OK, could you try with 300 only, please ? :)

                      virtual void BeHappy() = 0;

                      A 1 Reply Last reply
                      0
                      • C Code o mat

                        Place a breakpoint on the beginning of your paint_line method and once it gets hit, check the thickness parameter's value to see if it really is not 0 or 1.

                        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

                        A Offline
                        A Offline
                        arun_pk
                        wrote on last edited by
                        #15

                        inside paint line this is the portion where i create a pen hpen = CreatePen(PS_SOLID, thickness, rgb); i have tried like giving hpen = CreatePen(PS_SOLID, 0, rgb); . . . . . . . . . . . hpen = CreatePen(PS_SOLID, 50, rgb);

                        1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          Your code is fine, I called it this way:

                          case WM_PAINT:
                          hdc = BeginPaint(hWnd, &ps);
                          paint_line(hWnd, hdc, 0, 0, 400, 400, 5, RGB(255,0,0));
                          EndPaint(hWnd, &ps);
                          break;

                          and got a beautiful red thick line in my window. :)

                          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]

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

                          thanks pallini it worked when i gave thickness as 300 thanks a lot for spending time for me...

                          1 Reply Last reply
                          0
                          • E Eugen Podsypalnikov

                            OK, could you try with 300 only, please ? :)

                            virtual void BeHappy() = 0;

                            A Offline
                            A Offline
                            arun_pk
                            wrote on last edited by
                            #17

                            thanks Eugen its working fine thanks a lot why is it so ???

                            E 1 Reply Last reply
                            0
                            • C Code o mat

                              Place a breakpoint on the beginning of your paint_line method and once it gets hit, check the thickness parameter's value to see if it really is not 0 or 1.

                              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

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

                              it worked when i gave thickness as 300 thanks a lot for spending time for me...

                              C 1 Reply Last reply
                              0
                              • A arun_pk

                                it worked when i gave thickness as 300 thanks a lot for spending time for me...

                                C Offline
                                C Offline
                                Code o mat
                                wrote on last edited by
                                #19

                                No probs, here[^] you can find info about the mapping modes as mentioned by someone, try setting the MM_TEXT mapping mode before drawing your line and see what results that produces.

                                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

                                A 1 Reply Last reply
                                0
                                • A arun_pk

                                  thanks Eugen its working fine thanks a lot why is it so ???

                                  E Offline
                                  E Offline
                                  Eugen Podsypalnikov
                                  wrote on last edited by
                                  #20

                                  Probably a special DC Mapping Mode[^] was set in the calling context... :) (For example: Carlo Pallini has given his calling context - there are no modifications of the DC Mapping Mode there, so it is possible to "feel" the arguments by 2 or 5 too :) )

                                  virtual void BeHappy() = 0;

                                  A 1 Reply Last reply
                                  0
                                  • E Eugen Podsypalnikov

                                    Probably a special DC Mapping Mode[^] was set in the calling context... :) (For example: Carlo Pallini has given his calling context - there are no modifications of the DC Mapping Mode there, so it is possible to "feel" the arguments by 2 or 5 too :) )

                                    virtual void BeHappy() = 0;

                                    A Offline
                                    A Offline
                                    arun_pk
                                    wrote on last edited by
                                    #21

                                    Eugon I think i need to learn About setting Modes its my pleasure to talk with you thanks a lot it really helped me arun

                                    E 1 Reply Last reply
                                    0
                                    • C Code o mat

                                      No probs, here[^] you can find info about the mapping modes as mentioned by someone, try setting the MM_TEXT mapping mode before drawing your line and see what results that produces.

                                      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

                                      A Offline
                                      A Offline
                                      arun_pk
                                      wrote on last edited by
                                      #22

                                      i m goign through the article thanks a lot

                                      1 Reply Last reply
                                      0
                                      • A arun_pk

                                        Eugon I think i need to learn About setting Modes its my pleasure to talk with you thanks a lot it really helped me arun

                                        E Offline
                                        E Offline
                                        Eugen Podsypalnikov
                                        wrote on last edited by
                                        #23

                                        You are welcome, Arun ! :) (please observe the function that does call paint_line(..) - maybe, there is some variable like float fZoomingFactor there, so you could call the function like paint_line(.., thickness * fZoomingFactor, ..) :) )

                                        virtual void BeHappy() = 0;

                                        A 1 Reply Last reply
                                        0
                                        • E Eugen Podsypalnikov

                                          You are welcome, Arun ! :) (please observe the function that does call paint_line(..) - maybe, there is some variable like float fZoomingFactor there, so you could call the function like paint_line(.., thickness * fZoomingFactor, ..) :) )

                                          virtual void BeHappy() = 0;

                                          A Offline
                                          A Offline
                                          arun_pk
                                          wrote on last edited by
                                          #24

                                          yup Eugen Zooming factor is existing i am adjusting my code according to that ...

                                          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