Thread: Setting Control IDs

  1. #1
    Registered User
    Join Date
    Apr 2007
    Location
    In my house
    Posts
    29

    Setting Control IDs

    Hi guys, I am having trouble with my WM_COMMAND message, I want it to trap my menu items clicks, but I am not sure how to set my static controls ID so that I can trap the different IDs in the lParam of the WM_COMMAND message.

    Thanks in advance for any help

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    What your looking for isnt in the LPARAM, it's in the WPARAM.

    Are your menus resource created or function created?

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    In my house
    Posts
    29
    function created
    Last edited by Nurfina; 04-14-2007 at 03:35 PM.

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Assuming you use AppendMenu() to help create your menu...
    Code:
    AppendMenu( hSubMenu,   // Handle to the submenu.
                MF_STRING,   // The type of menu commponent
                ID_STUFF_GO,   // The id of your menu commponent.
                "&Go"   // The name of your commponent.
    );
    You would recive the command...
    Code:
    case WM_COMMAND:
    {
       switch( LOWORD( wParam ) )
       {
          case ID_STUFF_GO:
          {
             // Do your menu command here!
             MessageBox( hwnd, "\"Go\" was clicked!", "Woo Ho!", MB_OK );
          }
          break;
       }
       break;
    }

  5. #5
    Registered User
    Join Date
    Apr 2007
    Location
    In my house
    Posts
    29
    Is there any other way of doing it, my menu wont actually be a menu bar it is a GUI menu, using static controls for the main menu of a game that I am creating

    Sorry to be a pain
    Last edited by Nurfina; 04-14-2007 at 05:19 PM.

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Like a list box?

  7. #7
    Registered User
    Join Date
    Apr 2007
    Location
    In my house
    Posts
    29
    My button is setup like this :

    Code:
    void Setup_Button (Window* window, Button & button, char const * caption, int x, int y, int width, int height,  int bitmap, DWORD exStyle)
    {
    	button._style = WS_CHILD | WS_VISIBLE | SS_BITMAP | SS_NOTIFY;
    	button._caption = caption;
    	button._exStyle = exStyle;
    	button._x = x;														// horizontal position of Button
    	button._y = y;														// vertical position od Button
    	button._width = width;												// Button width
    	button._height = height;											// Button height
    	button._hWndParent = window->hWnd;									// handle to parent or owner Button
    	button._data = 0;													// pointer to Button-creation data
    
    	button.image = LoadBitmap(window->init.application->hInstance, (LPCSTR)bitmap);
    
    	Create_Button(window, button);
    }
    
    HWND Create_Button (Window* window, Button & button)
    {
    	button.hwnd = ::CreateWindowEx (
    		button._exStyle,
    		"STATIC",
    		button._caption,
    		button._style,
    		button._x,
    		button._y,
    		button._width,
    		button._height,
    		button._hWndParent,
    		NULL,
    		window->init.application->hInstance,
    		button._data);
    
    	if (button.hwnd == 0)
    		TerminateApplication(window);
    
    	LRESULT lResult = SendMessage(button.hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)button.image);
    
    	return button.hwnd;
    }
    and I need to be able to catch the click events of that so i need a way of giving it an ID or anything else that would mean I could catch it in WM_COMMAND

  8. #8
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Right... you see that NULL in the CreateWindowEx call above? Try changing that to the value of an ID you'd like to catch. You may need to cast it to HMENU.

  9. #9
    Registered User
    Join Date
    Apr 2007
    Location
    In my house
    Posts
    29
    Ah thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  2. Setting a control to have startup focus
    By bennyandthejets in forum C# Programming
    Replies: 1
    Last Post: 09-19-2004, 09:14 PM
  3. Control ID's
    By pinkcheese in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2002, 12:34 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. setting focus on a dialog box control
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 05-14-2002, 04:11 PM