| | |
MFC art program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
Originally Posted by Acidburn
Hello, I'm wanting to print a circle to a screen, or should I say on a form. Any ideas?
Thanks
Or betta still use c# or java, it takes away most of the pain of using MFC. :mrgreen:
*Voted best profile in the world*
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
I get this error when trying to call a premade function:
Whilst I'm not understanding the code very well, I've gone away and implemented a print function:
•
•
•
•
g:\University work\Year 2\GUI\Hangman\HangmanDlg.cpp(98): error C2373: 'Ellipse' : redefinition; different type modifiers
C++ Syntax (Toggle Plain Text)
void classname::print() { BOOL Ellipse( 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 } ... print();
Looks like you are trying to call the Ellipse function provided by the Windows API. Then you dont have to redefine it inside the function. Just call it like this.
Then call it like this
If you get errors, better post the code.
C++ Syntax (Toggle Plain Text)
void classname::print()
C++ Syntax (Toggle Plain Text)
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
C++ Syntax (Toggle Plain Text)
classname classobject; classobject::print( hdc, 10, 100, 30, 140 );
If you get errors, better post the code.
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
I get one more error:
I've edited the following:
the print protoypte now reads:
implemenation now reads:
whilst calling it inside a button which is:
Hmm any ideas?
cheers for your assistnce so far
•
•
•
•
g:\University work\Year 2\GUI\Hangman\HangmanDlg.cpp(93): error C2065: 'hdc' : undeclared identifier
the print protoypte now reads:
C++ Syntax (Toggle Plain Text)
void print(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
implemenation now reads:
C++ Syntax (Toggle Plain Text)
void CHangmanDlg::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 ); }
whilst calling it inside a button which is:
C++ Syntax (Toggle Plain Text)
void CHangmanDlg::OnBnClickedCancel() { CHangmanDlg::print(hdc, 10, 100, 30, 140 ); OptionsDlg dlg; dlg.DoModal(); }
Hmm any ideas?
cheers for your assistnce so far
Just do this.
C++ Syntax (Toggle Plain Text)
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 } } }
C++ Syntax (Toggle Plain Text)
void CHangmanDlg::OnBnClickedCancel() { CHangmanDlg::print(10, 100, 30, 140 ); OptionsDlg dlg; dlg.DoModal(); }
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
•
•
•
•
Originally Posted by WolfPack
Just do this.
C++ Syntax (Toggle Plain Text)
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 } } }
C++ Syntax (Toggle Plain Text)
void CHangmanDlg::OnBnClickedCancel() { CHangmanDlg::print(10, 100, 30, 140 ); OptionsDlg dlg; dlg.DoModal(); }
I also have a few more questions. 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?
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.
Thanks
John
•
•
•
•
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
•
•
•
•
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?
•
•
•
•
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.
etBkColor() method. You will have to search for the COLORREF datatype also. •
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
As regards to question 1 I'm trying to put the circle at a set point on the screen. See here:
www.bsc-coding.com/temp/screenie.png
However I'm finding myself entering different co-ordinates and getting different shapes but none of the desired ones.
As for changing the background color I've located the function which is virtual so I've tried to include my own understanding of implementation which can be as followed:
but nothing changes I've edited the cancel button to display a message box and the call that SetBkColor but nothing happens... can anyone assist in this dept?
Thanks for your patience, it seems like the msdn is not very clear at explaing things at all!
www.bsc-coding.com/temp/screenie.png
However I'm finding myself entering different co-ordinates and getting different shapes but none of the desired ones.
As for changing the background color I've located the function which is virtual so I've tried to include my own understanding of implementation which can be as followed:
C++ Syntax (Toggle Plain Text)
//optionDlg.cpp file static COLORREF i = 0x2555555; .. .. .. COLORREF OptionsDlg::SetBkColor(COLORREF crColor ) { return crColor; }
but nothing changes I've edited the cancel button to display a message box and the call that SetBkColor but nothing happens... can anyone assist in this dept?
Thanks for your patience, it seems like the msdn is not very clear at explaing things at all!
![]() |
Other Threads in the C++ Forum
- Previous Thread: Arrays
- Next Thread: Building a Shell. I'm in Hell
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






