Jump to content
  • Advertisement
Sign in to follow this  
Knight52

DirectX9 TextBox in c++

This topic is 2504 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

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?

Share this post


Link to post
Share on other sites
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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!