Using functions in Windows

This is a discussion on Using functions in Windows within the Windows Programming forums, part of the Platform Specific Boards category; I'm confused as on how to use functions in Windows other than the main wndproc. In the previous message I ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    Using functions in Windows

    I'm confused as on how to use functions in Windows other than the main wndproc. In the previous message I posted the code was to display a high score table. Now that I have added a menu to my window how do I add extra functions? e.x. new game, view scores, view credits, exit.

    In the code below I want to move the *_highscore functions into the show_highscore function. This is where my confusion is.

    Code:
    case WM_PAINT:
       {
           struct list high_score[MAX_SCORES] = {{{0}}};
           RECT rcClient;
           PAINTSTRUCT ps;
           HDC hdc = BeginPaint(hwnd,&ps);
           GetClientRect(hwnd, &rcClient);
    /*    load_highscore("hiscore.dat", high_score);
           display_highscore(hwnd,hdc, &rcClient, high_score);
           save_highscore("hiscore.dat", high_score);*/
           EndPaint(hwnd, &ps);
       }
    break;
    	
    void show_highscores(void)
    {
    
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I'm not exactly sure what you are asking but I think I understand. If you want to add a menu (or any other type of window) via the CreateWindow() function just use the HWND of the parent window for the hWndParent parameter. If you are asking how to make a function that is also capable of drawing to the screen you need to pass the HDC as one of its parameters:

    Example
    Code:
    int show_scores(HDC hdc) {
      // do stuff that draws to the hdc
    }

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    I assume you mean that you want to access these functions from a menu. Assign a command ID for each menu item in the resource file, and process them with the WM_COMMAND message:

    Code:
    case WM_COMMAND:
      switch(LOWORD(wParam)){
       case 1: // first command
        //....
        break;
       case 2: // second command
        //....
        break;
       default:
        break;
      }
      break;
    Make sure the command IDs do not conflict with the IDs for any child windows that the window may have.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 06:05 PM
  2. Replies: 7
    Last Post: 11-17-2008, 12:00 PM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 03:44 AM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM

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