-
Code needed
ok... iv made a program with a switch that has a char like this
PHP Code:
char k[128]// one byte
switch(k)
{
case "help":
{
//print something
}break;
default:
{
//do something
}break;
}
but i need to make it so that I can send a msg to a switch with out it being a char(as it only does int) and carry out a function kinder like the following code
PHP Code:
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
return(0);
}break;
case WM_PAINT:
{
// simply validate the window
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
// return success
return(0);
} break;
case WM_CHAR:
{
int ascii_code = wparam;
int Key_state =lparam;
#define ESC_STATE 0x10001
if(Key_state & ESC_STATE)
{
msg = WM_CLOSE;
}
}
case WM_DESTROY:
{
PostQuitMessage(0);//quiting the program
return(0);
}break;
return(DefWindowProc(hwnd, msg, wparam, lparam));
}
-
You can't use strings with a switch. And your array, yeah, that's not "one byte". switches work off integers. Anything integeral is allowed as a value for a switch.
Quzah.
-
my AIE instructer told me a array that was 128 long was = to one byte..... if u wanna know what the AIE is look here http://aie.act.edu.au/ but anyway. i know char's cant be used in a switch i just wanna know how in my second bit of code i can type msg = WM_CLOSE and it to work and what type the msg is or its struct of UINT. I just wanna know how i can type in help and for me to only type in the switch case help: if u get what i mean
-
if you mean you wanna send message to your window procedure,why not use "SendMessage()"
Code:
SendMessage(hwnd,MS_CHAR,WPARAM,LPARAM);
hope it is what you need.
-
You can use an STL map from strings to UINTs to accomplish what you want effectively (if I understand you).