Button Create
-
Hi, The codes below are used to create button and activate some function, when I compile it, it shows some error message as below. could some of you tell me how to solve it! Thanks! RunButton ( HWND hwnd ) { CreateWindow( "BUTTON", "Run", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles 380, 40, 60, 25, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL); return 1; } . . . case WM_COMMAND: switch HIWORD(wParam) { case BN_CLICKED: switch (lParam) { case RunButton: <--- error C2051: case expression not constant CetCapConnect( hwnd ); break; } <--- warning C4060: switch statement contains no 'case' or 'default' labels break;
-
Hi, The codes below are used to create button and activate some function, when I compile it, it shows some error message as below. could some of you tell me how to solve it! Thanks! RunButton ( HWND hwnd ) { CreateWindow( "BUTTON", "Run", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles 380, 40, 60, 25, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL); return 1; } . . . case WM_COMMAND: switch HIWORD(wParam) { case BN_CLICKED: switch (lParam) { case RunButton: <--- error C2051: case expression not constant CetCapConnect( hwnd ); break; } <--- warning C4060: switch statement contains no 'case' or 'default' labels break;
Francis Chau wrote: RunButton ( HWND hwnd ) { CreateWindow( "BUTTON", "Run", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles 380, 40, 60, 25, hwnd, NULL, This last NULL should be the ID of your button. This will be the value passed in the loword of the wparam parameter in the BN_CLICKED notification. Francis Chau wrote: case WM_COMMAND: switch HIWORD(wParam) { case BN_CLICKED: switch (lParam) { case RunButton: The lParam parameter contains the HWND of your button, which is the return value of the CreateWindow() function. Also the case expression has to be a constant value, the compiler has to know what the value is when it compiles the code, it can not be a value that is generated when the code is run. If you want to switch on a variable then you have to use the if...else if construct. This is how I would do it, but I would also add some error checking to make sure that CreateWindow() actually was able to create the button.
#define ID_RUNBUTTON 1001
.
.
.
RunButton ( HWND hwnd )
{
CreateWindow(
"BUTTON",
"Run",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
380,
40,
60,
25,
hwnd,
ID_RUNBUTTON,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
return 1;
}
.
.
.
case WM_COMMAND:
switch HIWORD(wParam)
{
case BN_CLICKED:
switch (LOWORD(wParam))
{
case ID_RUNBUTTON:
CetCapConnect( hwnd );
break;
}
break;
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
Francis Chau wrote: RunButton ( HWND hwnd ) { CreateWindow( "BUTTON", "Run", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles 380, 40, 60, 25, hwnd, NULL, This last NULL should be the ID of your button. This will be the value passed in the loword of the wparam parameter in the BN_CLICKED notification. Francis Chau wrote: case WM_COMMAND: switch HIWORD(wParam) { case BN_CLICKED: switch (lParam) { case RunButton: The lParam parameter contains the HWND of your button, which is the return value of the CreateWindow() function. Also the case expression has to be a constant value, the compiler has to know what the value is when it compiles the code, it can not be a value that is generated when the code is run. If you want to switch on a variable then you have to use the if...else if construct. This is how I would do it, but I would also add some error checking to make sure that CreateWindow() actually was able to create the button.
#define ID_RUNBUTTON 1001
.
.
.
RunButton ( HWND hwnd )
{
CreateWindow(
"BUTTON",
"Run",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
380,
40,
60,
25,
hwnd,
ID_RUNBUTTON,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
return 1;
}
.
.
.
case WM_COMMAND:
switch HIWORD(wParam)
{
case BN_CLICKED:
switch (LOWORD(wParam))
{
case ID_RUNBUTTON:
CetCapConnect( hwnd );
break;
}
break;
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
Thanks!