Hello, I'm wanting to print a circle to a screen, or should I say on a form. Any ideas?
Thanks
Here
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Here
Or betta still use c# or java, it takes away most of the pain of using MFC. :mrgreen:
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Looks like you are trying to call the Ellipse function provided by the Windows API. Then you dont have to redefine it inside the
void classname::print()
function. Just call it like this.
void classname::print
(
HDC hdc, // handle to DC
int nLeftRect, // x-coord of upper-left corner of rectangle
int nTopRect, // y-coord of upper-left corner of rectangle
int nRightRect, // x-coord of lower-right corner of rectangle
int nBottomRect // y-coord of lower-right corner of rectangle
)
{
Ellipse( hdc, nLeftRect, nTopRect, nRightRect, nBottomRect );
// Do other stuff you want inside the print function
//...
}
Then call it like this
classname classobject;
classobject::print( hdc, 10, 100, 30, 140 );
If you get errors, better post the code.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Just do this.
void CHangmanDlg::print
(
int nLeftRect, // x-coord of upper-left corner of rectangle
int nTopRect, // y-coord of upper-left corner of rectangle
int nRightRect, // x-coord of lower-right corner of rectangle
int nBottomRect // y-coord of lower-right corner of rectangle
)
{
CDC* pcdc = this->GetDC();
if ( pcdc)
{
pcdc->Ellipse( nLeftRect, nTopRect, nRightRect, nBottomRect );
if ( this->ReleaseDC( pcdc ) > 0 )
{
// Successfully Released
}
else
{
// Error in Releasing Device Context
}
}
}
void CHangmanDlg::OnBnClickedCancel()
{
CHangmanDlg::print(10, 100, 30, 140 );
OptionsDlg dlg;
dlg.DoModal();
}
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
is they a way of getting a set of co-ordinates on the screen? I want it the fursthers right but a very small cirlce. I've been filling it with some radmon but logical numbers and not getting very far
Sorry but I dont know what you mean. What were the values you used and what do you mean by you didnt get very far? Maybe a problem with the mapping mode. Look for CDC::MapMode()Can I chose not to fill the circle? so its just an outline? Also can I draw lines with this code? or is that something to do with the paintbrush?
Yes you can. And yes, it has to do with the paintbrush. And I think also with the CPen Object you select. Go through the documentation for CPen and CBrush in MSDN.Also can I change the background colour of the entire mfc window? I can't find that in the properities of the dlg box anywhere.
Maybe not in Visual C++ 6.0. But I think it was possible in Visual Studio .NET. Anyway do it programmatically. You could probably do it by using the CDC::SetBkColor() method. You will have to search for the COLORREF datatype also.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
To Change the Background color do this.
Add a protected variable of type CBrush to the Dialog.
e.g.
protected:
HICON m_hIcon;
CBrush *brush;
In your Dialog's OnInitDialog function do this intialization.
// TODO: Add extra initialization here
brush = new CBrush(RGB(0,0,0));
Add a new Handler for the WM_CTLCOLOR event of the Dialog box.
Right click the dialog.
Select Events.
Double CLick WM_CTLCOLOR in the "New Windows Messages/Events" WIndow and select Add Handler and Edit.
At the OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) Function do this.
HBRUSH CBKColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
pDC->SetBkColor(RGB(255, 0, 0));
return (HBRUSH)(brush->GetSafeHandle());
}
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Modify your WM_CTLCOLOR Handler as below.
HBRUSH CBKColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
pDC->SetBkMode( TRANSPARENT) ;
return (HBRUSH)(brush->GetSafeHandle());
}
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Pity that it didnt work for you. I just did a test and it worked for me. I edited the code after posting it the first time. Did you update it accordingly?
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115