Jump to content



DirectX9 TextBox in c++

  • You cannot reply to this topic
1 reply to this topic

#1 Knight52   Members   -  Reputation: 104

Like
0Likes
Like

Posted 03 February 2012 - 12:34 AM

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[i] != '\0'; i++) text[i] = text[i+1];
	  caretPos--;
	 }
	 break;
    default:
	 while(text[i++] != '\0');
	 for(i; i> caretPos; i--) text[i+1] = text[i];
	 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?

Ad:

#2 jwezorek   GDNet+   -  Reputation: 275

Like
0Likes
Like

Posted 03 February 2012 - 02:44 PM

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.






We are working on generating results for this topic
PARTNERS