Object Oriented GUI Windows Programming?

This is a discussion on Object Oriented GUI Windows Programming? within the C++ Programming forums, part of the General Programming Boards category; I am learning about object oriented programming with c++ and I was wondering how you guys write your windows gui ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    167

    Object Oriented GUI Windows Programming?

    I am learning about object oriented programming with c++ and I was wondering how you guys write your windows gui programs. Do you create classes that encapsulate the windows api or do you write the windows code in C programming style? Anybody willing to share any code?
    silk.odyssey

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I create classes that encapsulate a whole application. That includes a separate thread to run the message loop, a basic window, and a window procedure. I'll attach the source so you can see how it works.
    Attached Files Attached Files
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    Interesting example bennyandthejets but I think I have to learn a lot more about C++ and OOP before I can digest the example. Is there anything wrong with programming windows user interfaces with the C non OOP style?
    silk.odyssey

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I believe that's how Windows API is written.

  5. #5
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    In other words, no.
    Do not make direct eye contact with me.

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    Well I asked because if I am going to write C like code then why am I using C++? Is it justifiable to do interfaces with C like code but still use OOP for the other parts of a program or is that bad software design or something?
    silk.odyssey

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I've done a great deal of windows API code in C++. I find it to be much better because windows code can be ugly and difficult to maintain. OOP is the best way I know of to keep it clean.

    I take the approach that code can read like english. A class is a noun, a method is a verb, etc.. Therefore it is common sense that a window is an object and lets say resize, move, show, etc are verbs or methods on that class. Inherit them from a common Window class that does things that all windows do and you've got yourself a good starting point.

    If you choose this direction you'll want to look up:
    SetWindowLong() and GetWindowLong() with the GWL_USERDATA flag. This is the best place to store a pointer to the window's class instance. You'll need this to get access to the thing in the window callback. Have fun.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    You can take a gander at MFC, which is Win32 in OOP style. That can give you ideas how to set it up yourself.

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    >> I am learning about object oriented programming with c++ ...
    So now isn't the time to come up with you own OOP GUI framework of the Win32 API.
    I know that isn't what you were asking....

    >> Is there anything wrong with programming windows user interfaces with the C non OOP style?
    There is nothing wrong with what you do in your own process of learning.
    An OOP GUI framework might be on the advanced side of things for now, but there are many other things in the Win32 API that lend themselves easily to OOP.
    For example, here's my version of C++ thread encapsulation in Win32.

    It only takes a little bit of C++ know-how (and Win32 API experience) to start thinking about an OOP framework on Win32 GUI programming. Once you're ready (maybe tonight), come back and digest bennyandthejets's example code and then read this thread.

    Learning MFC is great way to study examples of slap'n C++ onto Win32 programming.

    gg

  10. #10
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    codeplug,

    You're probably right that im not ready to think about and OOP framework for the win32 api because right not im just learning about classes and operator overloading and still have inheritance and polymorphism to cover.
    silk.odyssey

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    I learned how to read by learning how to talk, I learned how to write by reading.

    Just start coding Windows applications in C++ right now, the details will become clear later.
    Last edited by DarkStar; 05-01-2004 at 08:40 PM.

  12. #12
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    Not ready for writing windows GUI applications as yet. Right not I'm focusing on learning c++ and thinking in an object oriented way. When I can do that I think it would be easier to code an object oriented framework for the win32 api.
    silk.odyssey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open an excel file from a windows service under Windows Vista
    By AdrianaLuby in forum C# Programming
    Replies: 1
    Last Post: 06-05-2007, 03:55 AM
  2. Object Oriented Programming
    By eric123 in forum C++ Programming
    Replies: 6
    Last Post: 11-30-2005, 03:56 AM
  3. Object Oriented Presentaion help
    By vanella*Flavor in forum C++ Programming
    Replies: 9
    Last Post: 11-16-2005, 06:55 PM
  4. object oriented C
    By FlatLost in forum C Programming
    Replies: 4
    Last Post: 11-08-2005, 05:22 AM
  5. How to move a sprite around inside a windows GUI
    By BuezaWebDev in forum C++ Programming
    Replies: 5
    Last Post: 04-07-2005, 09:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21