Need help creating window class

This is a discussion on Need help creating window class within the Windows Programming forums, part of the Platform Specific Boards category; I want to create a class like this: Code: class MyWindow { public: void CreateWindow(...); void WndProc(...); bool MainLoop(); ................ ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    27

    Need help creating window class

    I want to create a class like this:

    Code:
    class MyWindow
    {
        public:
           void CreateWindow(...);
           void WndProc(...);
           
           bool MainLoop();
           
           ................
    };
    The class will be used as shown below:

    Code:
    int main()
    {
        MyWindow *win = new MyWindow;
    
        win->CreateWindow();
    
        while(win->MainLoop())
            ;
    Unfortunately, C++ won't let me define as message callback the WndProc() function of each class.

    So, what to do next?

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    23
    you cannot define a callback in a 'MyWindow' class and use it with a windows system because the callback is a function of type 'MyWindow::WndProc' and windows has no way of knowing what the 'MyWindow' class is. non-static member functions use a calling convention that implicitly passes the objects pointer to the function. This allows you to use the 'this' pointer. a work around is to have one window procedure that can dispatch the messages to the appropriate class window procedure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating an object of a class inside another class - possible?
    By Programmer_P in forum C++ Programming
    Replies: 34
    Last Post: 08-16-2009, 12:21 AM
  2. Creating a Window Class
    By Dark_Phoenix in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2008, 07:45 PM
  3. Creating a child window in a parent window
    By vopo in forum Windows Programming
    Replies: 8
    Last Post: 10-06-2007, 05:15 PM
  4. Creating a New Window
    By tyouk in forum Windows Programming
    Replies: 3
    Last Post: 01-02-2005, 09:39 PM
  5. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM

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