Results 1 to 16 of 16

Thread: Combining Win32 API with OOP

  1. #1
    Sc0rp
    Guest

    Talking Combining Win32 API with OOP

    Hi, I'm currently reading a book about creating Windows based applications using API with C++.

    And since it's API, it's mainly C, and less C++.
    I'd like to build my applications using OOP, but without using MFC.

    Where do I start?
    Can you give me examples of basic classes used for Windows programming?


    Thanks.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, you'd have to come up with a basic concept: Do you want to make wrappers around the API (like MFC does), or do you only want some functional object that hide more of the API (a little bit like VB does).

    Whatever you do, remember that CALLBACK functions can't be class member functions unless they are static.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Welcome to the bandwagon Me and Kedaman are working on something similar This is what the new Windows headers look like (I'm regenerating them with templates):
    Code:
    namespace Win32 {
        // Constants
        const int WS_OVERLAPPED = 0x00000000L;
        const int WS_POPUP = 0x80000000L;
        const int WS_CHILD = 0x40000000L;
        const int WS_MINIMIZE = 0x20000000L;
        const int WS_VISIBLE = 0x10000000L;
        const int WS_DISABLED = 0x08000000L;
        const int WS_CLIPSIBLINGS = 0x04000000L;
    
        extern "C" long __stdcall SetWindowLongA(HWND hWnd, int nIndex, long dwNewLong);
        extern "C" long __stdcall SetWindowLongW(HWND hWnd, int nIndex, long dwNewLong);
        template<class chrtyp> inline long __stdcall SetWindowLong(HWND hWnd, int nIndex, long dwNewLong);
        inline long __stdcall SetWindowLong<char>(HWND hWnd, int nIndex, long dwNewLong)
            { return SetWindowLongA(hWnd, nIndex, dwNewLong); }
        inline long __stdcall SetWindowLong<wchar_t>(HWND hWnd, int nIndex, long dwNewLong)
            { return SetWindowLongW(hWnd, nIndex, dwNewLong); }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    parksie: how about splitting it up into several namespaces, like
    namespace Win32Window
    {
    CreateWindowA...
    ...
    }
    namespace Win32Thread
    {
    CreateThread...
    ...
    }

    You would need to come up with good seperations, but I think it wouldn't be bad.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well this is only there to prevent it polluting the :: namespace. These functions won't be used by any programs, since they'd use the abstraction layer (ask Ked, not me, he's the one with the bright idea )
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, if you'd ever need a bigger team, I'd work with you.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Zaei
    Guest
    As would I. I cant stand having some random #define changing my custom DLL DrawText Call into DrawTextA....and then it wonders why it cant find a function with the parameters I am passing.

    Z.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The idea is to use 1) Object Oriented Programming and 2) Generic Programming to build up layers for use in developing device independent applications.
    Parksie is working on the mostly functional and parameterized namespace, which I will be building up several interfaces in a parameterized nested class hierarchy for use as "pseudo-polymorphism" in device independent programming.
    All layers will be fully object oriented, so there will be no global functions nor handles floating around, typically you will be performing a bitblt like this:
    TargetDC.Rect(10,10,50,50).Do( bitblt(srccopy) << SourceDC.Rect(10,10,50,50));
    among other alternatives:
    (TargetDC<<Myrect).Do<bitblt(srccopy) >(SourceDCrect);
    The GDI object will provide access for the win32 environment with easy moves:
    Window x=GDI.Window<caption>("My app");
    x.minimize();
    GDI.Window<top>().Destroy();
    Window y=GDI.CreateWindow(wndclass,"my window",somepos);
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Zaei
    Guest
    That is quite a project! I cant wait to see how everything turns out.

    Z.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yeah, it's not going to be an overnight project, but rather slowly growing one
    btw nice avatari
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    Zaei
    Guest
    Thanks =). I thought it could go in for a change.

    Z.

  12. #12
    Sc0rp
    Guest
    Hey, sorry for not replying; Just got back from a 3-day trip.

    Anyway, I was looking for something more basic.
    I'm just starting with C++ Windows programming, so I just want basic guidelines.
    Primarily on the approach.

    I have no idea where to start.

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    my recommendation is Sams teach yourself C++ in 21 days
    http://newdata.box.sk/bx/c/
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Sc0rp
    Guest
    kedaman:

    That's the book I used to learn C++.
    What I would like are guidelines on how to apply the OOP techniques I learned there on Win32 programming.

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I'm not sure if there is such kind of things, win32api programming has been more or less functional with exception for MFC and GDI+ i guess but that's what I'm going to change in the nearest years
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Sc0rp
    Guest
    OK, thanks for your time everybody.

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