• Advertisement
Sign in to follow this  

Win32 problem

This topic is 3956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello allz wasnt sure where to post this so i figured here would be good! Im creating a networked piece of game software and for the life of me i cant remmber how some of the windows api works since iv been doing for directX for awhile now. i just need to know how to handel button clicked flags int he message proc. under the WM_COMMAND !

Share this post


Link to post
Share on other sites
Advertisement
Have you tried looking through MSDN? It's an excellent resource for anything to do with windows development.

Share this post


Link to post
Share on other sites
Yes but all they have is stuff to do with Dialog boxs where as i am not using them !

Share this post


Link to post
Share on other sites
the same should be done i think.But the ideal is that you switch through the id of the controls and when id is pressed handle the action..


will give more details if needed.

Share this post


Link to post
Share on other sites

i just cant seem to remmber how to switch for the actual control being used !
say the handle to the control that was clicked was HWND Send;


case WM_COMMAND:
switch(LOWORD(wParam)) // This switch identifies the control
{

switch(HIWORD(wParam)) // Find out what message it was
{
case BN_CLICKED: // This means that the list is about to display
MessageBox(hwnd,"Test",NULL,MB_OK);
break;
}
break;
}
break;

Share this post


Link to post
Share on other sites
try this

case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDM_FILE_SAVE:
break;
case IDM_FILE_CLOSE:
break;
}

where case xxx is the value of the button when created. The resouce identifier I beleive it is called. Should do what you want but have not tested it. The "Control notification message" is stored in HIGHWORK(wParam) it is specific to control and as said above i think you would put an extra case with value BN_CLICKED

MSDN http://msdn2.microsoft.com/en-us/library/ms647591.aspx

Share this post


Link to post
Share on other sites
You see im not useing a resource editor! im useing Visaul C++ express edition that dosent have a resource editor!

Share this post


Link to post
Share on other sites
MSDN says WM_COMMAND's lparam for a control holds the handle to the control winodw in this case a handle to the button.

Share this post


Link to post
Share on other sites
When i try using the windows handle in the case i get this error

error C2051: case expression not constant

i created the button using CreateWindowEx

Share this post


Link to post
Share on other sites
you could also set the id like so.


The following code example shows how to create several buttons.

#define BUTTONCLASS L"button"

#define BUTTONWIDTH 22 * cxAveChar
#define BUTTONHEIGHT 7 * cyAveChar / 4
#define BUTTONOFFSETLEFT 1
#define BUTTONOFFSETTOP 2 * cyAveChar

#define ID_BUTTON1 0x8801
#define ID_BUTTON2 0x8802
#define ID_BUTTON3 0x8803
#define ID_BUTTON4 0x8804
#define ID_BUTTON5 0x8805
#define ID_BUTTON6 0x8806
#define ID_BUTTON7 0x8807
#define ID_BUTTON8 0x8808

HWND hwndG1B1, hwndG1B2;
HWND hwndG2B1, hwndG2B2, hwndG2B3, hwndG2B4;
HWND hwndG3B1, hwndG3B2;

int cxAveChar, cyAveChar;

HINSTANCE hInst; // The current instance
HWND hwndCB; // The command bar handle

// Create a command bar.
hwndCB = CommandBar_Create(hInst, hWnd, 1);
CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
CommandBar_AddAdornments(hwndCB, 0, 0);

UINT nCmdBarHeight = CommandBar_Height(hwndCB);

// Create various buttons.
hdc = GetDC( hWnd );
TEXTMETRIC tm;
GetTextMetrics( hdc, &tm );
cxAveChar = tm.tmAveCharWidth;
cyAveChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC( hWnd, hdc );

// Create a push button.
hwndG1B1 = CreateWindow( BUTTONCLASS, L"Push Button",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
BUTTONOFFSETLEFT, nCmdBarHeight, BUTTONWIDTH,
BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON1, // 0x8801
hInst, NULL );

// Create a default push button.
hwndG1B2 = CreateWindow( BUTTONCLASS, L"Def Push Button",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
BUTTONOFFSETLEFT ,
BUTTONOFFSETTOP + nCmdBarHeight , BUTTONWIDTH,
BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON2, // 0x8802
hInst, NULL );

// Create a default radio button.
hwndG3B1 = CreateWindow( BUTTONCLASS, L"Radio Button",
WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON,
BUTTONOFFSETLEFT,
BUTTONOFFSETTOP + nCmdBarHeight * 2,
BUTTONWIDTH, BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON7, // 0x8807
hInst, NULL );

// Create a default auto radio button.
hwndG3B2 = CreateWindow( BUTTONCLASS, L"Auto Radio Button",
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
BUTTONOFFSETLEFT,
BUTTONOFFSETTOP + nCmdBarHeight * 3,
BUTTONWIDTH, BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON8, // 0x8808
hInst, NULL );

// Create a default check box.
hwndG2B1 = CreateWindow( BUTTONCLASS, L"Check Box",
WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
BUTTONOFFSETLEFT + 120, nCmdBarHeight,
BUTTONWIDTH, BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON3, // 0x8803
hInst, NULL );

// Create a default auto check box.
hwndG2B2 = CreateWindow( BUTTONCLASS, L"Auto Check Box",
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
BUTTONOFFSETLEFT + 120,
BUTTONOFFSETTOP + nCmdBarHeight,
BUTTONWIDTH, BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON4, // 0x8804
hInst, NULL );

// Create a default three-state button.
hwndG1B1 = CreateWindow( BUTTONCLASS, L"Three State",
WS_CHILD | WS_VISIBLE | BS_3STATE,
BUTTONOFFSETLEFT + 120,
BUTTONOFFSETTOP + nCmdBarHeight * 2,
BUTTONWIDTH, BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON5, // 0x8805
hInst, NULL );

// Create a default auto three-state button.
hwndG2B3 = CreateWindow( BUTTONCLASS, L"Auto 3 State",
WS_CHILD | WS_VISIBLE | BS_AUTO3STATE,
BUTTONOFFSETLEFT + 120,
BUTTONOFFSETTOP + nCmdBarHeight * 3,
BUTTONWIDTH, BUTTONHEIGHT, hWnd,
(HMENU) ID_BUTTON6, // 0x8806
hInst, NULL );

Share this post


Link to post
Share on other sites
Ok thanks that worked id dont remmber doing that awhile back or at least not having to but that helps thanks alot -.^

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement