I'm writing a program that involves 3 edit controls, and I want to be able to use tab to flit between them.
I've managed to do that, but for some weird reason when tab is pressed while the cursor is in the 3rd edit control, before it switches focus back to the first edit box it does a regular tab stop, ie the cursor jumps forward 5 spaces or so.
So if you repeatedly press tab you notice that when the cursor appears in the third edit box each time it is 1 tab forward from it's previous position.
Hmm.. that was quite poorly explained, but i hope you get the gist. How do I stop it doing that?
I'm not really sure how this whole thing is working, i've basically stolen the code from one of the program's in Petzold's book.
As far as I can see, I tell the program to pass all of its messages first to ScrollProc (LRESULT CALLBACK ScrollProc (HWND hwnd,.... blah blah)
ScrollProc looks like this:
Code:
LRESULT CALLBACK ScrollProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int id = GetWindowLong (hwnd, GWL_ID);
switch (message)
{
case WM_KEYDOWN:
if (wParam == VK_TAB)
SetFocus (GetDlgItem (GetParent (hwnd),
(id + (GetKeyState (VK_SHIFT) < 0 ? 2: 1)) % 3));
break;
case WM_SETFOCUS:
idFocus = id;
break;
}
return CallWindowProc (Focus[id], hwnd, message, wParam, lParam);
}
I "call" ScrollProc in WndProc, WM_CREATE, after i've used CreateWindow to make the edit boxes:
Code:
temp1 = CreateWindowEx(WS_EX_CLIENTEDGE, //more or 'extended' styles
TEXT("EDIT"), //'class' of control to create
NULL, //the control caption
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL, //control style: how it looks
160, //control position: left
10, //control position: top
570, //control width
25, //control height
hWnd, //parent window handle
(HMENU) 0, //control's ID
hInst, //application instance
NULL);
Focus[0] = (WNDPROC) SetWindowLong (temp1, GWL_WNDPROC, (LONG) ScrollProc);
temp2 = CreateWindowEx(WS_EX_CLIENTEDGE, //more or 'extended' styles
TEXT("EDIT"), //'class' of control to create
NULL, //the control caption
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL, //control style: how it looks
160, //control position: left
50, //control position: top
570, //control width
25, //control height
hWnd, //parent window handle
(HMENU) 1, //control's ID
hInst, //application instance
NULL);
Focus[1] = (WNDPROC) SetWindowLong (temp2, GWL_WNDPROC, (LONG) ScrollProc);
temp3 = CreateWindowEx(WS_EX_CLIENTEDGE, //more or 'extended' styles
TEXT("EDIT"), //'class' of control to create
NULL, //the control caption
WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_BORDER|ES_LEFT|ES_MULTILINE, //|ES_NOHIDESEL|ES_AUTOHSCROLL|ES_AUTOVSCROLL //control style: how it looks
160, //control position: left
100, //control position: top
570, //control width
370, //control height
hWnd, //parent window handle
(HMENU) 2, //control's ID
hInst, //application instance
NULL);
Focus[2] = (WNDPROC) SetWindowLong (temp3, GWL_WNDPROC, (LONG) ScrollProc);
and I have the following under WndProc, WM_SETFOCUS:
Code:
case WM_SETFOCUS:
if (idFocus == 0)
SetFocus (temp1);
else if (idFocus == 1)
SetFocus (temp2);
else if (idFocus == 2)
SetFocus (temp3);
Now my understanding of the above code is that when tab or shift tab is pressed it changes the input focus, if any other message comes in that message is passed to WndProc, so surely when I press tab in the 3rd edit box it should NOT act like a normal tab at all..... but it does. And I don't understand why it happens for the 3rd one but not the other two.
*confused*