CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Drawing from Object

    Quote Originally Posted by gareth.h.rees View Post
    Okay - I can see I haven't actually assigned anything to m_pWnd. I thought it was just a built in variable.?
    Where in the book did you EVER see the term "built in variable"???
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  2. #17
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    Quote Originally Posted by TheCPUWizard View Post
    Where in the book did you EVER see the term "built in variable"???
    "Member Variable" was probably what I meant to say - ie, one that is pre-defined for you?

  3. #18
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Drawing from Object

    Quote Originally Posted by gareth.h.rees View Post
    "Member Variable" was probably what I meant to say - ie, one that is pre-defined for you?
    Nothing is "PRE-DEFINED", you can easily see that it is EXPLICITLY declared in the heater file as a completely uninitialized pointer!!!

    Where does the INITIALIZATION come from??????
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #19
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    Quote Originally Posted by TheCPUWizard View Post
    Nothing is "PRE-DEFINED", you can easily see that it is EXPLICITLY declared in the heater file as a completely uninitialized pointer!!!

    Where does the INITIALIZATION come from??????
    I tried to use this to base my object on :

    http://www.codeguru.com/forum/archiv.../t-262641.html

    I thought that I was declaring a pointer to the Window of where the object was called from (ie, my View class).


    Quote Originally Posted by TheCPUWizard View Post
    Where does the INITIALIZATION come from??????
    Do you mean where was m_pWnd first defined? That, I do not know.

    Would it be better for me to use ::GetDC as mentioned before?

  5. #20
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Drawing from Object

    Quote Originally Posted by gareth.h.rees View Post
    Do you mean where was m_pWnd first defined? That, I do not know.
    No, I mean show me the line of code where a value is WRITTEN into m_pWnd to initialize it.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #21
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    Quote Originally Posted by TheCPUWizard View Post
    No, I mean show me the line of code where a value is WRITTEN into m_pWnd to initialize it.
    Okay - I've got that bit wrong.

    There isnt.

  7. #22
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Drawing from Object

    Quote Originally Posted by gareth.h.rees View Post
    I tried to use this to base my object on :

    http://www.codeguru.com/forum/archiv.../t-262641.html

    I thought that I was declaring a pointer to the Window of where the object was called from (ie, my View class).
    I hate to break this to you, but you can't get a C++ project done with this type of attempt of learning both the C++ language and Windows programming. Regardless of what it seems, the type of program you're attempting to write assumes you know C++ already to the point of understanding fully or (close to fully) classes, pointers, objects, etc.

    As TheCPUWizard pointed out, a lack of understand of C++ (forget about graphics) is the issue. All member variables, whether they are pointers to CWnd, pointers to doubles, or pointers to anything you want, must be initialized before using them (i.e. dereferencing them).
    Do you mean where was m_pWnd first defined? That, I do not know.
    Not knowing what your own program is doing doesn't bode too well for your assignment...
    Would it be better for me to use ::GetDC as mentioned before?
    And what is the window handle (HWND) you will be using as the argument to this function?

    Regards,

    Paul McKenzie

  8. #23
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    Yeah - tell me about it hah! When I started this project I assumed my supervisor would be able to guide me in learning C++ while I do this project. I've done a little in a module, but we've mostly been taught Java.

    I appreciate that my whole approach is wrong, but theres not much I can do about it now really - I *have* to make some attempt at getting this done.

    The main part of my project is moving shapes around - I've done this with the help of the "tracker" example, but I want to be able to create more than one shape to move around so I thought the best way would be to use objects.

    Once I figure out the drawing stuff I should be able to progress a little - though no doubt find a whole new bunch of problems.

    Like I said, I know its a rubbish way of going about it, but not even my project supervisor.. who is a lecturer in the University and set the project!!!! knows how to do this..

    Gareth

  9. #24
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    hmm anyone?

  10. #25
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Drawing from Object

    You might want to check out the DRAWCLI sample from MSDN. It uses drawing objects with their own drawing routines and has tracker rects for selecting and moving, bu it is a pretty complicated project.

    http://msdn.microsoft.com/en-us/library/9t94971d.aspx

  11. #26
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    Quote Originally Posted by hoxsiew View Post
    You might want to check out the DRAWCLI sample from MSDN. It uses drawing objects with their own drawing routines and has tracker rects for selecting and moving, bu it is a pretty complicated project.

    http://msdn.microsoft.com/en-us/library/9t94971d.aspx
    Thanks for that. I have had a look at it previously but couldn't make much sense of it, but will look again now I understand the tracker better.

    Perhaps if someone could explain in English what I need to do, I'll be able to code it myself..?

    Cheers
    Gareth

  12. #27
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Drawing from Object

    Quote Originally Posted by gareth.h.rees View Post
    Perhaps if someone could explain in English what I need to do, I'll be able to code it myself..?
    To draw on a window, you need the windows device context, which means you must have a valid HWND that represents that window to get the device context. A CWnd is nothing more than an MFC class that wraps an HWND.

    Your original code created a class that has no relationship at all with anything to do with a window or an HWND, but you tried to make it a CWnd by casting. In effect, you were trying to turn an concrete block into gold. Given this, the obvious explanation that is brief enough is to make sure you have a window handle so that you can get its device context.

    Other than that, no message board is going to give you an in-depth explanation of MFC, Windows, HWND's or CWnd's. That is in the realm of books and sample programs.

    Regards,

    Paul McKenzie

  13. #28
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Drawing from Object

    Quote Originally Posted by gareth.h.rees View Post
    Perhaps if someone could explain in English what I need to do, I'll be able to code it myself..?

    Cheers
    Gareth
    A choice....

    1) Spend a few weeks/months properly learning what you need to know.
    2) Pay someone who has invested the requisite time.

    Since this is (I believe) a school assignment, option #2 would be considered cheating.

    A final alternative would be to ask the instructor (in writing) to provide (again in writing) references to the material that was covered in the class [or is documented as a pre-requisite for the class] that would provide you with sufficient information to know how to properly program with MFC classes (or even Win32 API calls) ....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  14. #29
    Join Date
    Dec 2008
    Posts
    27

    Re: Drawing from Object

    Quote Originally Posted by Paul McKenzie View Post
    Other than that, no message board is going to give you an in-depth explanation of MFC, Windows, HWND's or CWnd's. That is in the realm of books and sample programs.
    Thanks for the help so far Paul - even though I'm not really getting anywhere I do feel I'm beginning to understand a little more.

    I appreciate that its probably not "the done thing" to code things for people, but all I was after was a quick and rough example of how to draw from a separate object - not an in depth tutorial.

    I'd love to actually understand what I'm doing a lot more... but alas - that won't actually go that far to help me pass my degree. Counter-intuitive, I know!

    Cheers
    Gareth

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured