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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need help on drawing a line

Need help on drawing a line

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
13 Posts 5 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.
  • J Offline
    J Offline
    John502
    wrote on last edited by
    #1

    Hi, I need some help on drawing a line, i am able to draw vertical line on dialog box, But whenever i have opened othe application on the dialog box, the line is getting erasing.... I am using below code snippet for drawing line.. dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(old_x1,old_y1); dc.LineTo(old_x2,old_y2); dc.MoveTo(start); dc.LineTo(end); Can any one help me regrading why the line is getting erasing..? as it is very urgent requirement for me..

    _ H _ CPalliniC 4 Replies Last reply
    0
    • J John502

      Hi, I need some help on drawing a line, i am able to draw vertical line on dialog box, But whenever i have opened othe application on the dialog box, the line is getting erasing.... I am using below code snippet for drawing line.. dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(old_x1,old_y1); dc.LineTo(old_x2,old_y2); dc.MoveTo(start); dc.LineTo(end); Can any one help me regrading why the line is getting erasing..? as it is very urgent requirement for me..

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Put those lines in the OnPaint method of the dialog.

      «_Superman_» I love work. It gives me something to do between weekends.

      J 1 Reply Last reply
      0
      • J John502

        Hi, I need some help on drawing a line, i am able to draw vertical line on dialog box, But whenever i have opened othe application on the dialog box, the line is getting erasing.... I am using below code snippet for drawing line.. dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(old_x1,old_y1); dc.LineTo(old_x2,old_y2); dc.MoveTo(start); dc.LineTo(end); Can any one help me regrading why the line is getting erasing..? as it is very urgent requirement for me..

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

        Where do you use of this code? WM_PAINT

        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 )

        J 1 Reply Last reply
        0
        • J John502

          Hi, I need some help on drawing a line, i am able to draw vertical line on dialog box, But whenever i have opened othe application on the dialog box, the line is getting erasing.... I am using below code snippet for drawing line.. dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(old_x1,old_y1); dc.LineTo(old_x2,old_y2); dc.MoveTo(start); dc.LineTo(end); Can any one help me regrading why the line is getting erasing..? as it is very urgent requirement for me..

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          in which function do you try to do this?

          You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

          J 1 Reply Last reply
          0
          • J John502

            Hi, I need some help on drawing a line, i am able to draw vertical line on dialog box, But whenever i have opened othe application on the dialog box, the line is getting erasing.... I am using below code snippet for drawing line.. dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(old_x1,old_y1); dc.LineTo(old_x2,old_y2); dc.MoveTo(start); dc.LineTo(end); Can any one help me regrading why the line is getting erasing..? as it is very urgent requirement for me..

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

            Windows is event driven (well, message driven...): drawing should happen inside the WM_PAINT message handler, that is CDialog::OnPaint method for an MFC application. :)

            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
            • _ _Superman_

              Put those lines in the OnPaint method of the dialog.

              «_Superman_» I love work. It gives me something to do between weekends.

              J Offline
              J Offline
              John502
              wrote on last edited by
              #6

              Yes, I have written that code snippet in OnPaint function only...

              1 Reply Last reply
              0
              • H Hamid Taebi

                Where do you use of this code? WM_PAINT

                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 )

                J Offline
                J Offline
                John502
                wrote on last edited by
                #7

                I have written that code snippet in OnPaint function only...

                H 1 Reply Last reply
                0
                • _ _AnsHUMAN_

                  in which function do you try to do this?

                  You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

                  J Offline
                  J Offline
                  John502
                  wrote on last edited by
                  #8

                  In OnPaint function... , I have already done with google, but i don't get any correct help... So Could you please help me regarding this...?

                  _ 1 Reply Last reply
                  0
                  • J John502

                    In OnPaint function... , I have already done with google, but i don't get any correct help... So Could you please help me regarding this...?

                    _ Offline
                    _ Offline
                    _AnsHUMAN_
                    wrote on last edited by
                    #9

                    did you debug to check if variables contain the same values as they did before other window was moved over your dialog.

                    You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

                    J 1 Reply Last reply
                    0
                    • _ _AnsHUMAN_

                      did you debug to check if variables contain the same values as they did before other window was moved over your dialog.

                      You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

                      J Offline
                      J Offline
                      John502
                      wrote on last edited by
                      #10

                      yes i have debugged, iam getting all the variables are in correct manner.

                      1 Reply Last reply
                      0
                      • J John502

                        I have written that code snippet in OnPaint function only...

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

                        Does your code like this? void CTestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); // device context for painting dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(100,100); dc.LineTo(100,200); dc.MoveTo(200,205); dc.LineTo(200,305); CDialog::OnPaint(); } }

                        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 )

                        J 1 Reply Last reply
                        0
                        • H Hamid Taebi

                          Does your code like this? void CTestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); // device context for painting dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(100,100); dc.LineTo(100,200); dc.MoveTo(200,205); dc.LineTo(200,305); CDialog::OnPaint(); } }

                          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 )

                          J Offline
                          J Offline
                          John502
                          wrote on last edited by
                          #12

                          Hi Saadi, Thanks for your help on this.., I am able to draw the constant line if i have opened other window on dialog box, but here in my application the line will move from left to right in between two sliders along with the slider positions. while the line is moving, if i have opened any window on dialog box, the previous line is not getting erasing. I thought of it is losting the previous line pixels information.. Can you please tell me how i have to achive this..? thanks in advance..

                          H 1 Reply Last reply
                          0
                          • J John502

                            Hi Saadi, Thanks for your help on this.., I am able to draw the constant line if i have opened other window on dialog box, but here in my application the line will move from left to right in between two sliders along with the slider positions. while the line is moving, if i have opened any window on dialog box, the previous line is not getting erasing. I thought of it is losting the previous line pixels information.. Can you please tell me how i have to achive this..? thanks in advance..

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

                            Hi John Well Im not Saadi (poet)[^]. Your answer is easy if you want to clear previous lines you can draw on it again for example you have this code: dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(100,100); dc.LineTo(100,200); dc.MoveTo(200,205); dc.LineTo(200,305); if you use of this code again you clear previous line. dc.SetROP2(R2_NOTXORPEN); dc.MoveTo(100,100); dc.LineTo(100,200); dc.MoveTo(200,205); dc.LineTo(200,305);

                            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
                            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