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. drawline for VC++

drawline for VC++

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
21 Posts 7 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 Offline
    M Offline
    mercenary01
    wrote on last edited by
    #1

    What is the simplest method I can use to get lines drawn on dialog boxes? Thanks

    N I N D M 5 Replies Last reply
    0
    • M mercenary01

      What is the simplest method I can use to get lines drawn on dialog boxes? Thanks

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      pDC->MoveTo (x1, y1); pDC->LineTo (x2, y2); Simple enough?

      Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

      M 1 Reply Last reply
      0
      • N Nelek

        pDC->MoveTo (x1, y1); pDC->LineTo (x2, y2); Simple enough?

        Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

        M Offline
        M Offline
        mercenary01
        wrote on last edited by
        #3

        thanks, it compiles but... I keep getting into "Debug Assertion Failed!" can you advise me what is wrong with my code? CDC* pDC; pDC = new CDC(); pDC->MoveTo (0, 0); pDC->LineTo (100, 100);

        N C 2 Replies Last reply
        0
        • M mercenary01

          What is the simplest method I can use to get lines drawn on dialog boxes? Thanks

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          Create a really narrow static box? That's what I do to put a line in between sections on my dialog boxes. Using Draw Line needs a DC - which needs to be associated with a window. So you need to create one, and when do you do it? Lot's of little things to know - and by the level of your question, your knowledge isn't at that point yet. (It will be!) Iain.

          N 1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            Create a really narrow static box? That's what I do to put a line in between sections on my dialog boxes. Using Draw Line needs a DC - which needs to be associated with a window. So you need to create one, and when do you do it? Lot's of little things to know - and by the level of your question, your knowledge isn't at that point yet. (It will be!) Iain.

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            Iain Clarke wrote:

            Lot's of little things to know - and by the level of your question, your knowledge isn't at that point yet.

            But if he need to color the static, then? :)

            - NS - [ODBaseBtn]

            1 Reply Last reply
            0
            • M mercenary01

              What is the simplest method I can use to get lines drawn on dialog boxes? Thanks

              N Offline
              N Offline
              Nishad S
              wrote on last edited by
              #6

              void CMyDlg::OnPaint() { CPaintDC dc( this ); dc.FillSolidRect( 10, 10, 100, 1, RGB( 255, 0, 0 )); // Draw a red colored line }

              - NS - [ODBaseBtn]

              M 1 Reply Last reply
              0
              • N Nishad S

                void CMyDlg::OnPaint() { CPaintDC dc( this ); dc.FillSolidRect( 10, 10, 100, 1, RGB( 255, 0, 0 )); // Draw a red colored line }

                - NS - [ODBaseBtn]

                M Offline
                M Offline
                mercenary01
                wrote on last edited by
                #7

                this is nuts, it looks like it should work...but its not working. Is there a way to put just a pixel on the dialog box?

                N 1 Reply Last reply
                0
                • M mercenary01

                  thanks, it compiles but... I keep getting into "Debug Assertion Failed!" can you advise me what is wrong with my code? CDC* pDC; pDC = new CDC(); pDC->MoveTo (0, 0); pDC->LineTo (100, 100);

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

                  You didnt associate the DC to a window. If you are in a dialog... one way to do it is:

                  void CMyDialog::OnPaint()
                  { CPaintDC dc(this); // device context for painting

                  pDC->MoveTo (0, 0);
                  pDC->LineTo (100, 100); 	
                  
                  return;
                  

                  }

                  OnPaint is a message of the dialog, to get it go to assistant and look for it.

                  Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

                  C 1 Reply Last reply
                  0
                  • M mercenary01

                    this is nuts, it looks like it should work...but its not working. Is there a way to put just a pixel on the dialog box?

                    N Offline
                    N Offline
                    Nelek
                    wrote on last edited by
                    #9

                    it should work... no. It DOES work. If you dont get anything is because you are doing something wrong. And I guess you just copied the text and declare it as a normal function. But the OnPaint is not a normal function, is a dialog message. So you have to declare it in a speciall way, or go to the assistant "CTRL + W" and look for the OnPaint in the ListBox. BTW it won't be bad if you read a basic manual as well, just to get the basic concepts.

                    Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

                    M 1 Reply Last reply
                    0
                    • M mercenary01

                      thanks, it compiles but... I keep getting into "Debug Assertion Failed!" can you advise me what is wrong with my code? CDC* pDC; pDC = new CDC(); pDC->MoveTo (0, 0); pDC->LineTo (100, 100);

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #10

                      mercenary01 wrote:

                      CDC* pDC; pDC = new CDC(); pDC->MoveTo (0, 0); pDC->LineTo (100, 100);

                      You cannot do that: You have to request a device context to GDI. That is usually done while handling the WM_PAINT message (you need to override the OnPaint method of your dialog), for instance:

                      void CMyDlg::OnPaint()
                      {
                      CPaintDC dc( this );
                      dc.MoveTo(0, 0);
                      dc.LineTo (100, 100);
                      }

                      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.

                      1 Reply Last reply
                      0
                      • N Nelek

                        You didnt associate the DC to a window. If you are in a dialog... one way to do it is:

                        void CMyDialog::OnPaint()
                        { CPaintDC dc(this); // device context for painting

                        pDC->MoveTo (0, 0);
                        pDC->LineTo (100, 100); 	
                        
                        return;
                        

                        }

                        OnPaint is a message of the dialog, to get it go to assistant and look for it.

                        Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

                        C Offline
                        C Offline
                        CPallini
                        wrote on last edited by
                        #11

                        Nelek wrote:

                        void CMyDialog::OnPaint() { CPaintDC dc(this); // device context for painting pDC->MoveTo (0, 0); pDC->LineTo (100, 100); return; }

                        you have to replace -> with . and pDC with dc to make it all work! ;P :-D

                        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.

                        N 1 Reply Last reply
                        0
                        • N Nelek

                          it should work... no. It DOES work. If you dont get anything is because you are doing something wrong. And I guess you just copied the text and declare it as a normal function. But the OnPaint is not a normal function, is a dialog message. So you have to declare it in a speciall way, or go to the assistant "CTRL + W" and look for the OnPaint in the ListBox. BTW it won't be bad if you read a basic manual as well, just to get the basic concepts.

                          Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

                          M Offline
                          M Offline
                          mercenary01
                          wrote on last edited by
                          #12

                          well its not like I just jumped onto this forum to ask for help, I did spend time on studying he example code and got the drawline working for GDI by modifying the sample codes. I spent more than the better half of 2 days and I don't appreciate you asking me to RTFM. If you don't want to give any positive input why bother giving any input?

                          D C N 3 Replies Last reply
                          0
                          • M mercenary01

                            What is the simplest method I can use to get lines drawn on dialog boxes? Thanks

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

                            While it is possible, you typically don't draw directly on dialog boxes. What exactly are you trying to do?

                            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            1 Reply Last reply
                            0
                            • M mercenary01

                              well its not like I just jumped onto this forum to ask for help, I did spend time on studying he example code and got the drawline working for GDI by modifying the sample codes. I spent more than the better half of 2 days and I don't appreciate you asking me to RTFM. If you don't want to give any positive input why bother giving any input?

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

                              mercenary01 wrote:

                              I did spend time on studying he example code and got the drawline working for GDI by modifying the sample codes.

                              And you are the only one that knows this. How are we to know what you've already tried?

                              mercenary01 wrote:

                              If you don't want to give any positive input why bother giving any input?

                              Because the majority of the questions that get asked on this forum are from those who don't want to bother doing any of the work themselves. If that presumption does not apply to you, a simple "Thanks for the suggestion, but I already did that." is all that's necessary.

                              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                              M 1 Reply Last reply
                              0
                              • M mercenary01

                                well its not like I just jumped onto this forum to ask for help, I did spend time on studying he example code and got the drawline working for GDI by modifying the sample codes. I spent more than the better half of 2 days and I don't appreciate you asking me to RTFM. If you don't want to give any positive input why bother giving any input?

                                C Offline
                                C Offline
                                CPallini
                                wrote on last edited by
                                #15

                                mercenary01 wrote:

                                well its not like I just jumped onto this forum to ask for help, I did spend time on studying he example code and got the drawline working for GDI by modifying the sample codes. I spent more than the better half of 2 days

                                Maybe an hint for a major career change... Just kidding :rose: :)

                                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.

                                1 Reply Last reply
                                0
                                • D David Crow

                                  mercenary01 wrote:

                                  I did spend time on studying he example code and got the drawline working for GDI by modifying the sample codes.

                                  And you are the only one that knows this. How are we to know what you've already tried?

                                  mercenary01 wrote:

                                  If you don't want to give any positive input why bother giving any input?

                                  Because the majority of the questions that get asked on this forum are from those who don't want to bother doing any of the work themselves. If that presumption does not apply to you, a simple "Thanks for the suggestion, but I already did that." is all that's necessary.

                                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                  M Offline
                                  M Offline
                                  mercenary01
                                  wrote on last edited by
                                  #16

                                  Hey please don't get me wrong I am not mad at everyone in this forum, I have had good answers that did help me in my projects from this forum and I really do appreciate all of it. Honestly I am an embedded programmer and would help anyone just like most people that I have encountered in this forum have helped me. Just like to state, that I don't go around telling people how hard I worked or tired my hand on something. So I did not see the need to tell everyone this in the beginning so I am not sure maybe it should be protocol? But seriously I don't want anyone to get me wrong I appreciate the answers to question in past and even now.

                                  D 1 Reply Last reply
                                  0
                                  • M mercenary01

                                    Hey please don't get me wrong I am not mad at everyone in this forum, I have had good answers that did help me in my projects from this forum and I really do appreciate all of it. Honestly I am an embedded programmer and would help anyone just like most people that I have encountered in this forum have helped me. Just like to state, that I don't go around telling people how hard I worked or tired my hand on something. So I did not see the need to tell everyone this in the beginning so I am not sure maybe it should be protocol? But seriously I don't want anyone to get me wrong I appreciate the answers to question in past and even now.

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

                                    mercenary01 wrote:

                                    Just like to state, that I don't go around telling people how hard I worked or tired my hand on something. So I did not see the need to tell everyone this in the beginning so I am not sure maybe it should be protocol?

                                    See the Content section here.

                                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                    1 Reply Last reply
                                    0
                                    • M mercenary01

                                      What is the simplest method I can use to get lines drawn on dialog boxes? Thanks

                                      M Offline
                                      M Offline
                                      Mark Salsbery
                                      wrote on last edited by
                                      #18

                                      So....did you ever get this working? Are you using MFC or straight Win32 APIs?

                                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                                      M 1 Reply Last reply
                                      0
                                      • M Mark Salsbery

                                        So....did you ever get this working? Are you using MFC or straight Win32 APIs?

                                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                                        M Offline
                                        M Offline
                                        mercenary01
                                        wrote on last edited by
                                        #19

                                        ya I got it to work :) got a piece of code from another forum and modified it to fit the project. Thanks for asking.

                                        1 Reply Last reply
                                        0
                                        • C CPallini

                                          Nelek wrote:

                                          void CMyDialog::OnPaint() { CPaintDC dc(this); // device context for painting pDC->MoveTo (0, 0); pDC->LineTo (100, 100); return; }

                                          you have to replace -> with . and pDC with dc to make it all work! ;P :-D

                                          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.

                                          N Offline
                                          N Offline
                                          Nelek
                                          wrote on last edited by
                                          #20

                                          :doh: :doh: :omg: you are totally right. I was about to go home at the end of the day and I didn't realize.

                                          Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

                                          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