How To Call A User-defined Class in Win32 Application?

This is a discussion on How To Call A User-defined Class in Win32 Application? within the Windows Programming forums, part of the Platform Specific Boards category; Bonjour ! Let say I have defined a class myself, called "Test". Then if I click on a button called ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Smile How To Call A User-defined Class in Win32 Application?

    Bonjour !

    Let say I have defined a class myself, called "Test". Then if I click on a button called "BOK", it will trigger the functions of the instances of Test to have some events to occur.

    To have the functions working when I click the button, I need to create the instaces of Test first, right ?

    Where should I place the code like "Test A" to create the instances ?

    I cannot put under the OnBOK() right ? If not the program will keep creating the instances of Test every time I click the button.

    So where should I create the instances to make sure OnBOK() can access the instances and execute the functions properly ?

    Thanks a lot !

    P/S : Seems like my nick name appear quite frequently this few days

  2. #2
    Registered User Ward's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    39
    If I where you I would declare a global pointer of your new class.

    In the InitDialog (or something like that) or even in the OnOk() you create the instance and you can call all the public functions of your own class using the created instance.


    MyClass * g_myPointer;

    //...

    int OnOk()
    {
    g_myPointer = new MyClass;
    g_myPointer->funcA();
    g_myPointer->FuncB();
    delete g_myPointer;
    }

    If you don't want to create the instance everytime you've pressed the OK button, you can create the instance in another procedure that is earlier called in the program.

    MyClass * g_myPointer;

    //...

    int OnInitDialog()
    {
    g_myPointer = new MyClass;
    }

    int OnOk()
    {
    g_myPointer->funcA();
    g_myPointer->FuncB();
    }

    int OnCloseDialog()
    {
    delete g_myPointer;
    }


    Of course you will need to check for NULL values in your final version.
    Greetings.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Smile Thanks A Lot !

    Good day !

    A thousand thanks !

    I have figured out how to do already !

    Thanks again !

    Sonic WAve

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. Multiple types in lists, vectors or arrays.
    By megatron09 in forum C++ Programming
    Replies: 20
    Last Post: 08-31-2006, 01:54 PM
  4. Class won't call
    By Aalmaron in forum C++ Programming
    Replies: 3
    Last Post: 04-13-2006, 04:57 PM
  5. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 06:57 AM

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