Thread: Programming Win32 using Classes

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Programming Win32 using Classes

    Ive been looking everywhere to find an example to set up my program using a class for my window but cant find any, someone please point me to a link or give me an example.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    The WinAPI has no classes (its "window classes" have nothing to do with C++ classes or OOP).

    You can use libraries like MFC or OWL to encapsulate windows as objects. MFC is included in Visual C++, OWL is included in Borland C++ (and I think it has some MFC support as well).

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Im know the Win32 API has nothing to do with classes! I want to create a class like CWindow in MFC but i cant find any tutorials on the subject.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    342
    Learn C++, OOP, and the Win32 API, then you will have no problem. It's the only way.

    Begin read MSDN to learn Win32. And buy a book.

    Search for "C++ tutorials" on the internet. And buy a book.

  5. #5
    Back! ^.^ *Michelle*'s Avatar
    Join Date
    Oct 2001
    Posts
    568
    That's wonderful advice, series! I don't think xds4lx need help on buying books..
    Michelle (o^.^o)
    *Unique*
    Kaomoji House

  6. #6
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Angry

    I KNOW C++ AND I KNOW Win32! but when I make a class for creating my window it doesnt work so thats why im looking for a tutorial!
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    Ok
    The Windows API to register a new window class is:
    Code:
    ATOM RegisterClass(
      CONST WNDCLASS *lpWndClass  // class data
    );
    browse the WNDCLASS structure and you will find its member:
    Code:
    ...
    LPCTSTR    lpszClassName
    give it an unique, for the whole system, name.

    if you planing to develop whole new window class hierarchy you will need to 'tie' it with the OS.

    So you will need an WndProc, in terms of the Windows API, where you will try to route every incoming system event to the particular instance of class (object), derived from your base CWindow.

    I can suggest you to use an single WndProc for all instances of your classes, you also will need an way to distinguish between all the instances using the window Handle only(hWnd).

    One way is to use the object's 'this' and to put it in some extra window long position(use this member od the WNDCLASS struct):
    Code:
    int        cbWndExtra
    or to use an global map to keep the relation between them.

    you shoud put that WndProc in the WINDOWCLASS structure:
    Code:
    WNDPROC    lpfnWndProc
    when you registering your main class(in terms of the windows API)
    So it is not a simple task and there are many ways to archieve it.

    Damyan

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    342
    xds3lx
    I KNOW C++ AND I KNOW Win32!
    No, you don't, not good enough. Because:

    but when I make a class for creating my window it doesnt work so thats why im looking for a tutorial!
    And if you can't find a tutorial, then it's not a question for this board. The problem with your question is that you have no details at all about your problem, basicly you're just saying: "I have a problem creating a window". We are not here to find tutorials for people, or to make a guess for a possible answer, we're here to help with questions about Win32 programming. You don't even know what the problem is.

    *Michelle*
    That's wonderful advice, series! I don't think xds4lx need help on buying books..
    That's exactly what he needs.

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Series, please keep your negative comments to yourself.


    xds4lx, can you give an example of what you tried and
    what exactly failed to produce the desired results ?
    Your post is indeed very general, and I don't know where
    to start to help you.

    Keep cool people.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  10. #10
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Ok, first of FU series! Ive been coding in C++ for 6 years. And i dont need to know what funtion to call to register a damn window! Ive been programming Win32 for a year ok. My problem is that im trying encapsulate the window creating and it keeps failing. Im basicly trying to create a class that works like CWindow, but I have no idea how to go about this because every idea I have has failed so far.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Wrapping Win32 in classes
    By mrafcho001 in forum Windows Programming
    Replies: 7
    Last Post: 03-02-2006, 06:56 PM
  3. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. win32 and user defined classes
    By paulf in forum Windows Programming
    Replies: 4
    Last Post: 04-16-2002, 06:12 PM