|
-
May 21st, 2003, 03:35 AM
#1
Thread Starter
Fanatic Member
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);
}
-
May 21st, 2003, 09:33 AM
#2
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.
-
May 21st, 2003, 10:24 AM
#3
Thread Starter
Fanatic Member
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..
-
May 21st, 2003, 03:54 PM
#4
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.
-
May 21st, 2003, 11:13 PM
#5
Thread Starter
Fanatic Member
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..?..
-
May 22nd, 2003, 01:45 AM
#6
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.
-
May 22nd, 2003, 01:49 AM
#7
Thread Starter
Fanatic Member
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..
-
May 22nd, 2003, 02:10 AM
#8
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.
-
May 22nd, 2003, 02:17 AM
#9
Thread Starter
Fanatic Member
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..
-
May 22nd, 2003, 03:04 AM
#10
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.
-
May 22nd, 2003, 03:06 AM
#11
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.
-
May 22nd, 2003, 03:13 AM
#12
Thread Starter
Fanatic Member
-
May 22nd, 2003, 03:17 AM
#13
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.
-
May 22nd, 2003, 03:22 AM
#14
Thread Starter
Fanatic Member
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|