Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

WM_KEYDOWN error in c++

Status
Not open for further replies.

bhattaroshan

Member level 1
Joined
Sep 28, 2010
Messages
33
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,531
hi friends....
I have made simple keyboard controlled car.And the car can be controlled using arrow keys.I have used dev c++ to write the code.In The code i have also added four buttons to control the car.
I am able to control the car using both arrows keys and buttons. But once's i click any of the four buttons arrow keys does not work.
Here is my code.

LRESULT CALLBACK WinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
LoadUSBCom();
SetPortOutput(PORTC,255);
SetPortOutputState(PORTC,0xff);
CreateWindowExA(0,"button","^",WS_CHILD|WS_VISIBLE,100,100,50,50,hwnd,(HMENU)201,NULL,NULL);
CreateWindowExA(0,"button","<",WS_CHILD|WS_VISIBLE,50,150,50,50,hwnd,(HMENU)202,NULL,NULL);
CreateWindowExA(0,"button",">",WS_CHILD|WS_VISIBLE,150,150,50,50,hwnd,(HMENU)203,NULL,NULL);
CreateWindowExA(0,"button","\\/",WS_CHILD|WS_VISIBLE,100,200,50,50,hwnd,(HMENU)204,NULL,NULL);
CreateWindowExA(0,"button","reset",WS_CHILD|WS_VISIBLE,400,200,50,50,hwnd,(HMENU)205,NULL,NULL);
}
break;
case WM_KEYDOWN:
{
bool has=false;
SetPortOutputState(PORTC,0xff);
switch(wParam)
{
case VK_UP:
has=true;
SetPortOutputState(PORTC,0xfc);
Sleep(150);
break;
case VK_LEFT:
has=true;
SetPortOutputState(PORTC,0xfe);
Sleep(150);
break;
case VK_RIGHT:
has=true;
SetPortOutputState(PORTC,0xfd);
Sleep(150);
break;
case VK_DOWN:
has=true;
SetPortOutputState(PORTC,0xf3);
Sleep(150);
break;
}
if(has)
{
SetPortOutputState(PORTC,0xff);
}
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 201:
SetPortOutputState(PORTC,0xfc);
Sleep(200);
SetPortOutputState(PORTC,0xff);
break;
case 202:
SetPortOutputState(PORTC,0xfe);
Sleep(200);
SetPortOutputState(PORTC,0xff);
break;
case 203:
SetPortOutputState(PORTC,0xfd);
Sleep(200);
SetPortOutputState(PORTC,0xff);
break;
case 204:
SetPortOutputState(PORTC,0xf3);
Sleep(200);
SetPortOutputState(PORTC,0xff);
break;
case 205:
UnLoadUSBCom();
Sleep(200);
LoadUSBCom();
SetPortOutput(PORTC,255);
SetPortOutputState(PORTC,0xff);
break;
}
break;
case WM_DESTROY:
UnLoadUSBCom();
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

If any one knows please help me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top