SetFocus to Control on startup

Started by Haakon Birkeland, August 22, 2006, 10:43:08 PM

Previous topic - Next topic

Haakon Birkeland

I have a form that has a tab control with 3 forms one in each tab. When the program loads it shows the form on tab 1, just the way I want it. I would like to give the focus to a textbox on that form.
I used SetFocus GetDlgItem(HWND_ESTIMATING, HWND_ESTIMATING_QUANTITYTXT)
in the form WM_CREATE but it doesn't work. When I press the tab key the focus does not respond. I actually have to mouse click in one of the textbox in order to make the tab order work.

thanx
bert
Haakon 8o)

TechSupport

Quote from: mercierb
I used SetFocus GetDlgItem(HWND_ESTIMATING, HWND_ESTIMATING_QUANTITYTXT)
That is not the correct syntax for GetDlgItem. You can use:

SetFocus GetDlgItem(HWND_ESTIMATING, IDC_ESTIMATING_QUANTITYTXT)

(note the IDC_ instead of HWND)

Actually, it is easier to reference the HWND directly:

SetFocus HWND_ESTIMATING_QUANTITYTXT


Hope this helps.

Haakon Birkeland

No setfocus HWND_ESTIMATING_QUANTITYTXT was the first thing I tried and it doesnt work in the WM_CREATE of the form.
What it looks like is that nothing has the focus so thetab key only beeps and does not bring focus to anything in the window

bert
Haakon 8o)

TechSupport

Maybe you are putting the SetFocus in the wrong WM_CREATE ???? Try putting it in the WM_CREATE of your main form, not in the Tab's Form.

For example, given the TabControl sample program, add a TextBox to the FRMGENERAL form. In the main form, add the following code:


Function FRMMAINFORM_WM_CREATE ( _
                              hWndForm As Dword, _  ' handle of Form
                              ByVal UserData As Long _  'optional user defined Long value
                              ) As Long

 
  SetFocus HWND_FRMGENERAL_TEXT1
 
End Function


Please let me know if this helps....

Haakon Birkeland

:oops:
Sorry to bug you I thought I had already tried it. It works

bert
Haakon 8o)