944,181 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4380
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 1st, 2006
0

MFC art program

Expand Post »
Hello, I'm wanting to print a circle to a screen, or should I say on a form. Any ideas?

Thanks
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Feb 1st, 2006
0

Re: MFC art program

Quote 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
Here
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Feb 2nd, 2006
0

Re: MFC art program

Quote originally posted by WolfPack ...
Here
Or betta still use c# or java, it takes away most of the pain of using MFC. :mrgreen:
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 2nd, 2006
0

Re: MFC art program

I get this error when trying to call a premade function:

Quote ...
g:\University work\Year 2\GUI\Hangman\HangmanDlg.cpp(98): error C2373: 'Ellipse' : redefinition; different type modifiers
Whilst I'm not understanding the code very well, I've gone away and implemented a print function:

C++ Syntax (Toggle Plain Text)
  1. void classname::print()
  2. {
  3. BOOL Ellipse(
  4. HDC hdc, // handle to DC
  5. int nLeftRect, // x-coord of upper-left corner of rectangle
  6. int nTopRect, // y-coord of upper-left corner of rectangle
  7. int nRightRect, // x-coord of lower-right corner of rectangle
  8. int nBottomRect // y-coord of lower-right corner of rectangle
  9. }
  10. ...
  11.  
  12. print();
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Feb 2nd, 2006
0

Re: MFC art program

Looks like you are trying to call the Ellipse function provided by the Windows API. Then you dont have to redefine it inside the
C++ Syntax (Toggle Plain Text)
  1. void classname::print()
function. Just call it like this.
C++ Syntax (Toggle Plain Text)
  1. void classname::print
  2. (
  3. HDC hdc, // handle to DC
  4. int nLeftRect, // x-coord of upper-left corner of rectangle
  5. int nTopRect, // y-coord of upper-left corner of rectangle
  6. int nRightRect, // x-coord of lower-right corner of rectangle
  7. int nBottomRect // y-coord of lower-right corner of rectangle
  8. )
  9. {
  10. Ellipse( hdc, nLeftRect, nTopRect, nRightRect, nBottomRect );
  11. // Do other stuff you want inside the print function
  12. //...
  13. }

Then call it like this
C++ Syntax (Toggle Plain Text)
  1. classname classobject;
  2. classobject::print( hdc, 10, 100, 30, 140 );

If you get errors, better post the code.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Feb 2nd, 2006
0

Re: MFC art program

I get one more error:

Quote ...
g:\University work\Year 2\GUI\Hangman\HangmanDlg.cpp(93): error C2065: 'hdc' : undeclared identifier
I've edited the following:

the print protoypte now reads:

C++ Syntax (Toggle Plain Text)
  1. void print(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);

implemenation now reads:

C++ Syntax (Toggle Plain Text)
  1. void CHangmanDlg::print
  2. (
  3. HDC hdc, // handle to DC
  4. int nLeftRect, // x-coord of upper-left corner of rectangle
  5. int nTopRect, // y-coord of upper-left corner of rectangle
  6. int nRightRect, // x-coord of lower-right corner of rectangle
  7. int nBottomRect // y-coord of lower-right corner of rectangle
  8. )
  9. {
  10. Ellipse( hdc, nLeftRect, nTopRect, nRightRect, nBottomRect );
  11. }

whilst calling it inside a button which is:

C++ Syntax (Toggle Plain Text)
  1. void CHangmanDlg::OnBnClickedCancel()
  2. {
  3. CHangmanDlg::print(hdc, 10, 100, 30, 140 );
  4.  
  5. OptionsDlg dlg;
  6. dlg.DoModal();
  7. }


Hmm any ideas?

cheers for your assistnce so far
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Feb 2nd, 2006
0

Re: MFC art program

Just do this.

C++ Syntax (Toggle Plain Text)
  1. void CHangmanDlg::print
  2. (
  3. int nLeftRect, // x-coord of upper-left corner of rectangle
  4. int nTopRect, // y-coord of upper-left corner of rectangle
  5. int nRightRect, // x-coord of lower-right corner of rectangle
  6. int nBottomRect // y-coord of lower-right corner of rectangle
  7. )
  8. {
  9. CDC* pcdc = this->GetDC();
  10. if ( pcdc)
  11. {
  12. pcdc->Ellipse( nLeftRect, nTopRect, nRightRect, nBottomRect );
  13. if ( this->ReleaseDC( pcdc ) > 0 )
  14. {
  15. // Successfully Released
  16. }
  17. else
  18. {
  19. // Error in Releasing Device Context
  20. }
  21. }
  22. }

C++ Syntax (Toggle Plain Text)
  1. void CHangmanDlg::OnBnClickedCancel()
  2. {
  3. CHangmanDlg::print(10, 100, 30, 140 );
  4. OptionsDlg dlg;
  5. dlg.DoModal();
  6. }
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Feb 2nd, 2006
0

Re: MFC art program

Quote originally posted by WolfPack ...
Just do this.

C++ Syntax (Toggle Plain Text)
  1. void CHangmanDlg::print
  2. (
  3. int nLeftRect, // x-coord of upper-left corner of rectangle
  4. int nTopRect, // y-coord of upper-left corner of rectangle
  5. int nRightRect, // x-coord of lower-right corner of rectangle
  6. int nBottomRect // y-coord of lower-right corner of rectangle
  7. )
  8. {
  9. CDC* pcdc = this->GetDC();
  10. if ( pcdc)
  11. {
  12. pcdc->Ellipse( nLeftRect, nTopRect, nRightRect, nBottomRect );
  13. if ( this->ReleaseDC( pcdc ) > 0 )
  14. {
  15. // Successfully Released
  16. }
  17. else
  18. {
  19. // Error in Releasing Device Context
  20. }
  21. }
  22. }

C++ Syntax (Toggle Plain Text)
  1. void CHangmanDlg::OnBnClickedCancel()
  2. {
  3. CHangmanDlg::print(10, 100, 30, 140 );
  4. OptionsDlg dlg;
  5. dlg.DoModal();
  6. }
Thanks for the reply, it seems to have done the trick, 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

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
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Feb 2nd, 2006
0

Re: MFC art program

Quote ...
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()
Quote ...
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.
Quote ...
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:etBkColor() method. You will have to search for the COLORREF datatype also.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Feb 2nd, 2006
0

Re: MFC art program

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:

C++ Syntax (Toggle Plain Text)
  1.  
  2. //optionDlg.cpp file
  3.  
  4. static COLORREF i = 0x2555555;
  5.  
  6. ..
  7. ..
  8. ..
  9. COLORREF OptionsDlg::SetBkColor(COLORREF crColor )
  10. {
  11. return crColor;
  12. }

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!
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Arrays
Next Thread in C++ Forum Timeline: Building a Shell. I'm in Hell





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC