|
As I guess that when you draw a circle ,earlier drawn figures are being erased.Right?
Have a look at SetROP2().
This method helps working with the Raster Operations performing XOR,AND etc operations on bits while drawing.
You can use the R2_XXX option for the drawing modes.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
hi _AnShUmAn_
i have tried with the setRop2();what u have guessed is true.but all parameters of this function for set the pen and brush colour.i havent find any thing which wil solve my problem.plz give me sample code.
|
|
|
|
|
Here's a sample code that I use in OnMouseMove
pDC->SetROP2(R2_NOTXORPEN);
pDC->MoveTo(pStart);
pDC->LineTo(pEnd);
pDC->SetROP2(R2_NOTXORPEN);
pDC->MoveTo(pStart);
pDC->LineTo(point);
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
i hope that u will get an idea by seeing my code.
void CNEWWINDOWView::OnLButtonDown(UINT nFlags, CPoint point)
{
if(nFlags==MK_LBUTTON ){
x1=point.x;
y1=point.y;
}
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
void CNEWWINDOWView::OnMouseMove(UINT nFlags, CPoint point)
{
if(nFlags==MK_LBUTTON ){
x2=point.x;
y2=point.y;
}
Invalidate();
CView::OnMouseMove(nFlags, point);
}
/* After the i have written in the on Draw method to draw Rectangle,circle ,Line by clicking on that buttons.*/
void CNEWWINDOWView::OnDraw(CDC* pDC)
{
if(m_Element==LINE)
{
pDC->MoveTo(x1,y1);
pDC->LineTo(x2,y2);
}
else if(m_Element==RECTANGLE)
{
CRect* rect=new CRect(x1,y1,x2,y2);
pDC->Rectangle(rect);
rect->NormalizeRect();
}
else if(m_Element==CIRCLE)
{
long radius =
static_cast<long>(sqrt(static_cast<double>((x2-x1)*(x2-x1-x1)+
(y2-y1)*(y2-y1))));
CRect m_EnclosingRect = CRect(x1 - radius, y1 - radius,
x1 + radius, y1 + radius);
pDC->Ellipse(m_EnclosingRect);
}
but it is not restore the privious draws.
|
|
|
|
|
Why are you drawing the shapes in OnDraw? Why not in OnMouseMove as I suggest?
and do not Invalidate()
What does Invalidate do:
Specifies whether the background within the update region is to be erased.
So that could also be one of the problems.
Let me know when you get this done.....
-- modified at 4:41 Wednesday 23rd August, 2006
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Thanx.i will try with ur way.
|
|
|
|
|
where you draw your shapes WM_PAINT
|
|
|
|
|
the problem is that when i draw a figure ,earlier drawn figures are being erased.No ,i am drawing in the ondraw method.
-- modified at 2:33 Wednesday 23rd August, 2006
|
|
|
|
|
|
I'm creating a custom control which creates a child header control to display column headings. I'm wondering how tall to make the header control. I looked at GetSystemMetrics(), but couldn't find one that seemed appropriate. Currently, I just defaulted to using the horizontal scroll bar height from GetSystemMetrics(), but was wondering if there was a more correct method.
Any ideas?
|
|
|
|
|
I would give it a default height to begin with, but make it self adjusting to fit the text size. For a default height I would set it to the same height as the default font. Infact to calculte it I would use the same method as creating a font size
int lfheight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
|
|
|
|
|
basing it on the font size sounds like a good approach. it should probably be a little larger than the font height, though, to allow for a little space and the borders drawn by the control.
Thanks!
|
|
|
|
|
Hi ,
I am facing a problem.
In my MFC application I have to check whether serial port is in Plugged/Unplugged status.
Any method for finding it?
any window message or event for knowing serial port status?
Thanx in advance
|
|
|
|
|
Hello.
There are status signals you can test, such as DSR (Data Set Ready) and CTS (Clear To Send) (Provided you did set RTS (Request To Send) high first).
If there are a device connectoed to the port, those staus signals should indicate the port is connected to a powered on device.
But in my experience, the status signals aren't 100% trustworthy when the serial port is unplugged. What's worse, it seems as their state depends on the hardware.
So the best way to find out, is to send some kind of status question to the device, then wait for an answer. If you get an answer, it's definately plugged in.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
hi, is there anybody who know let a CEdit control(child of CView) setfocus in a simple SDI program when program startup.
I define CEdit control in my CView(.h file) like "CEdit m_edtContent", then in my CView's cpp file's create function, call like m_endContent.Create(....).
But when the program startup, every time, i must click the CEdit first, then it will be focused, so can anybody tell me i don't need to click it, but let the program to setfocus my CEdit control.
thanks.
|
|
|
|
|
use SetFocus(...)
Good Luck.
Uday kiran
|
|
|
|
|
it's complex, only use SetFocus can't succeed
|
|
|
|
|
hwndEdit=CreateWindow ("EDIT","Anshuman",WS_CHILD|WS_VISIBL|WS_BORDER,10,10,80,20,hWnd,(HMENU)IDC_EDIT1,hInst,NULL);
SetFocus (hwndEdit); // Call at last to set the focus.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
tried this method several times at many different places, such as when created, when updated, or in InitInstance, can't success. don't know what's the problem
|
|
|
|
|
Call it immediatly before exiting your OnInit function. If that doesn't work look through your code for any other instances of SetFocus , maybe you are setting it but it is later being stolen.
|
|
|
|
|
On way is using CEdit::Setfocus in overridden OnActivateView()
|
|
|
|
|
|
I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.
|
|
|
|
|
its failing ? Is it giving some ASSERT or just not doing what its intended to do?
Have you suppressed its base class call ? You need to do that.
It would just look like this,
void CSDIView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
m_edtContent.SetFocus();
}
|
|
|
|