Results 1 to 14 of 14

Thread: How to draw lines in a Dialog Box using MFC

  1. #1

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    How to draw lines in a Dialog Box using MFC

    Hi,

    How to draw lines or any other on a Dialog Box.

    I want to draw lines when I move my mouse...

    How can I do it.. I am Using VC++ 6.0.


    I have already tried using .. But no good..

    Help me out....

    Code:
    void CPaintBDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    static CPoint p;	
    CPaintDC dc(this);
    	
    CPen * myPen = new CPen(PS_SOLID,2,RGB(255,0,0));
    	
    dc.SelectObject(myPen);
    
    dc.MoveTo(p.x,p.y);
    dc.LineTo(point.x,point.y);
    p.x=point.x;
    p.y=point.y;
    delete myPen;	
    
    CDialog::OnLButtonDown(nFlags, point);
    }
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Should the line be persistent (i.e. should they remain after redrawing)?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Persistent.... Not required...

    Can I use double buffering to make it persistent...

    Any way as of now I just wana draw on a Dialog Box Created using VB 6.0 MFC..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    using VB 6.0 MFC..
    Watch your typing. Most typos are harmless, but some can be confusing.

    Anyway, double-buffering a dialog is probably a bad idea - too much code for too little gain. Easier to create a CLine class and store a list of them. Then go through the list and draw each.

    As for the other thing, usual line drawing algorithm looks like this:
    Code:
    // MouseDown event:
    {
      SetCapture();
      m_bIsDragging = true;
      m_ptStart = m_ptEnd = clickedPoint;
      DrawTempLine(m_ptStart, m_ptEnd);
    }
    
    // MouseMove event:
    {
      if(m_bIsDragging) {
        EraseTempLine(m_ptStart, m_ptEnd);
        m_ptEnd = mousePos;
        DrawTempLine(m_ptrStart, m_ptEnd);
      }
    }
    
    // MouseUp event:
    {
      if(m_bIsDragging) {
        EraseTempLine(m_ptStart, m_ptEnd);
        m_ptEnd = clickedPoint;
        DrawFinalLine(m_ptStart, m_ptEnd);
        AddLineToStore(m_ptStart, m_ptEnd);
        ReleaseCapture();
        m_bIsDragging = false;
      }
    }
    
    // Paint event:
    {
      for each line in store {
        DrawFinalLine(line);
      }
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    hi,

    I dont wana draw in paint method.. I wana draw in the Mouse move event..

    As far as drawing lines are concerned I agree that double buffering is not a good idea.. But when it comes to bmp's then there is no better way... wat do ya say..?..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Uhhh...


    You mean drawing bitmaps?

    Double buffering is always a bad idea when it's about a whole dialog.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Cornedbee...

    how to draw bmp in a dialogbox..

    I think that I can load the bmp to hdc...

    But when I do that nothing appears..

    even when I dram line nothing appeares..

    It appeares only if i put it under the OnPaint method.. Which I dont wana do...

    Is there a simple method like say.. I press Button 1 and few lines are drawn then I press second button and few circles or rectangles are drawn.. similarly BMP's..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It seems like the dialog prefers to draw itself.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Whatever you think..

    But do let me know...

    For a moment I thought that doing all this in a Dialog box dint sound good..
    I thought why not on a Window.. (CreateWindow())....

    There I will have no problem in drawing..

    Let me know....what would be better..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Not sure, what pros has a dialog? Do you have many controls?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What about adding a child window to your dialog and drawing in there?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Hello Cornedbee....

    Well I just want to dram some things on a window.. ...
    No Dialog tree or plant .. Just draw

    (VB was lot better for these stuffs...)...

    Any way.. I wana draw .....

    I just need some simple examples ..

    I am familar with Windows Programming and I am moving towards MFC... (Project Requirement.. you see..)..

    But the examples given in the book are completely different than what i see in the IDE.. ...
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Then use a normal window. A dialog is not intended for drawing.

    And I don't believe that VB is better for pure drawing.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    ...

    May be VB is not better.. But it is indeed Simpler....

    For mere drawing lines.. If I have to break my Head in VC++.. in VB its just drag and drop Lines..

    Any way Thanks for your reply..

    ....

    I will post my other questions.. here.. when i go to the other chapters...
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width