DirectX9 TextBox in c++

Started by
0 comments, last by jwezorek 12 years, 2 months ago
I'm making a TextBox class that uses WPARAM. Here's the code


void update(GameInput &input, GameInput &oldInput, GameCursor &cursor, LPDIRECT3DDEVICE9 &device, WPARAM wParam)
if((char)wParam != '\0')
{
int i = 0;
switch(wParam)
{
case VK_LEFT:
if(caretPos > 0) caretPos--;
break;
case VK_RIGHT:
while(text[i++] != '\0');
if(caretPos < i) caretPos++;
break;
case '\b':
if(caretPos > 0 && text[0] != '\0')
{
for(i = caretPos-1; text != '\0'; i++) text = text[i+1];
caretPos--;
}
break;
default:
while(text[i++] != '\0');
for(i; i> caretPos; i--) text[i+1] = text;
text[caretPos] = (char)wParam;
break;
}
}


and this is how I get that wParam


//main loop
//WPARAM kParam;
while (!exiting)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (msg.message == WM_QUIT) break;
///This one
kParam = msg.message;
///////
update();//call function above
draw();
draw2d();
}


I don't know why, but result changes only when I click the mouse. The result doesn't change when I'm punching the keyboard. Where did I go wrong?
Advertisement
Sorry ... but there's a lot wrong with the above. You are assuming that every message that is not WM_QUIT has a wParam that is a virtual key code. At the very least test for WM_CHAR, but you shouldn't be doing this kind of thing in the main loop anyway. Register a window class and handle keyboard input in the WNDPROC.

This topic is closed to new replies.

Advertisement