Adding functions to a program

This is a discussion on Adding functions to a program within the Windows Programming forums, part of the Platform Specific Boards category; I've made a window with a few buttons in it. When you click on the buttons, they don't work if ...

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    Question Adding functions to a program

    I've made a window with a few buttons in it. When you click on the buttons, they don't work if I do what is shown below. I have no idea why it doesn't quite work, and was hoping that some1 could help me out.
    Code:
    if(LOWORD(wParam) == 5){
                                 if(HIWORD(wParam) == BN_CLICKED){
                                                   HostSession();
                                                   }
               }
    The function HostSession is used as below. I'm probably wrong, but I think it might be the void, anyway, hope some1 can help.
    Code:
    void HostSession()
    {
         MessageBox(NULL, "Only testing if the function works", "Testing", MB_OK);
    };

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Hmm, can't see anything wrong with your code. Show us the rest.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,261
    Are you handling the WM_COMMAND message? Is 5 the correct button identifier?

  4. #4
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    yer, the "5" button (or window) identifier, I compile and try all the buttons and nothing gives a message box. I'm using the WM_COMMAND message to get the buttons to work.

  5. #5
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Can you post the whole code?

  6. #6
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    ok, I'll post the code when I get home. I might have come up with a solution. I might be able to use an inline function instead. It might work, I'm not sure yet

  7. #7
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    Here is all the relavent code that I have written so far...

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,261
    Code:
    HINSTANCE g_hinst;
    I think you meant to declare g_hinst as a global variable. As it stands now, g_hinst is never initialized before it is used. Declare the variable as global, and then in your WinMain() function put the following:
    Code:
    g_hinst = hThisInstance;
    Also, it is a good idea to check the return values of CreateWindowEx() to make sure there are no errors.

  9. #9
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    Thanks for the advice, I'll take it onboard

  10. #10
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    I've figuared out what was wrong, I got a bit mixed up with the bracket things (not sure about the terminology) with one of the IF statements in the WM_COMMAND part of the program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Please adding a counter to my Program
    By John_Fev in forum C++ Programming
    Replies: 1
    Last Post: 04-02-2009, 10:29 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Newbie- having trouble with functions
    By bnmwad in forum C Programming
    Replies: 7
    Last Post: 02-22-2005, 04:41 PM
  4. Replies: 3
    Last Post: 01-14-2003, 10:34 PM
  5. Syntax for adding a program to autoexec.bat...
    By Sebastiani in forum C Programming
    Replies: 5
    Last Post: 06-18-2002, 01:38 AM

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