PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Haakon Birkeland on August 22, 2006, 10:43:08 PM

Title: SetFocus to Control on startup
Post by: Haakon Birkeland on August 22, 2006, 10:43:08 PM
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
Title: Re: SetFocus to Control on startup
Post by: TechSupport on August 22, 2006, 11:56:06 PM
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.
Title: SetFocus to Control on startup
Post by: Haakon Birkeland on August 23, 2006, 12:10:53 AM
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
Title: SetFocus to Control on startup
Post by: TechSupport on August 23, 2006, 12:33:45 AM
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....
Title: SetFocus to Control on startup
Post by: Haakon Birkeland on August 23, 2006, 12:47:10 AM
:oops:
Sorry to bug you I thought I had already tried it. It works

bert