Thread: Need help creating window class

  1. #1
    Registered User
    Join Date
    Jul 2010

    Need help creating window class

    I want to create a class like this:

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

    int main()
        MyWindow *win = new MyWindow;
    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
    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-15-2009, 11:21 PM
  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, 04: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