Original Post
Hi. I've got a problem. I create a edit box using CreateWindowEx and then i subclass it to handle input. When i type into the editbox, the character repeat itself until there's no more space for characters (when it have reached the max length). Why, and what can i do to prevent this and make the control work properly (i mean, like a general editbox)?
I create the control using:
The oldProc looks like:
And..what books do you recommend for a guy like me with this level of programming skills?
Thanks in advice!
/Andreas
[edited by - michalson on October 8, 2002 12:42:52 PM]
newHwnd=CreateWindowEx(WS_EX_CLIENTEDGE,"BUTTON",cCaption,BS_PUSHBUTTON |WS_VISIBLE | WS_CHILD,
xPos, yPos, iWidth, iHeight,hwnd,(HMENU)bID,hInstance,NULL);
I subclass it using:
oldProc = (WNDPROC)SetWindowLong(eHwnd,GWL_WNDPROC,(LONG)eWndProc);The new message handler looks like:
LRESULT CALLBACK eWndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{
struct _timeb nowTime;
char oldString[100];
int diff;
_ftime(&nowTime);
diff = nowTime.time-lastTime.time;
diff = nowTime.millitm-lastTime.millitm+diff*1000;
if(diff>100)//Only repeat typing each 100 millisecond.
{
if(umsg == WM_KEYDOWN)
{
GetWindowText(wHwnd,oldString,100);
strcat(oldString,"xxx");
SetWindowText(eHwnd,oldString);
}
lastTime = nowTime;
}
return CallWindowProc(oldProc,hwnd,umsg,wparam,lparam);
}
LRESULT CALLBACK wWndProc(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam)
{
WORD wWho,wCmd;
char c[20];
struct _timeb nowTime;
char oldString[100];
int diff;
_ftime(&nowTime);
diff = nowTime.time-lastTime.time;
diff = nowTime.millitm-lastTime.millitm+diff*1000;
wWho = LOWORD(wParam);
wCmd = HIWORD(wParam);
switch(msg)
{
case WM_KEYDOWN:
keys[wParam] = true;
break;
case WM_KEYUP:
keys[wParam] = false;
break;
case WM_COMMAND:
if(diff>200)
{
strcpy(c,"Hihi");
if(wWho==bID)
{
if(wCmd==BN_CLICKED)
TextOut(GetDC(wHwnd),0,350,c,strlen(c));
if(rand()%10==5)
done=true;
}
else if(wWho==eID)
{
if(wCmd==EN_SETFOCUS)
TextOut(GetDC(wHwnd),0,350,c,strlen(c));
}
}
break;
case WM_CLOSE:
case WM_DESTROY:
break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}