I have a simple GUI (in window9) that consists of two editboxes (one readonly) a combo box and 4 buttons.
Whenever I click the COMBOBOX or one of the buttons I want the focus to return to the writeable EDITTEXT box.
What is the best way to achieve this ??????
TIA
Dave
Forcing fucus on edittext?
-
- Posts: 293
- Joined: Jul 15, 2021 7:23
- Location: Greece
- Contact:
Re: Forcing fucus on edittext?
See SetFocus()
example with button
example with button
Code: Select all
ButtonGadget(1,10,10,60,30,"button")
SetFocus(Gadgetid(1)) ' focus on the button
Re: Forcing fucus on edittext?
Hello softfoot.. Not so clear what you are meaning? Do you are using winapi SDK Style for your gui with winmain / wndproc? Whats your Intension with the combobox and edibix?
WM_SETFOCUS and WM_KILLFOCUS
(wndproc)
hWndFocus = GetFocus ()
for simple gui exists too
SetFocus can be used for an edit-control-window... .
WM_SETFOCUS and WM_KILLFOCUS
(wndproc)
hWndFocus = GetFocus ()
for simple gui exists too
SetFocus can be used for an edit-control-window... .
-
- Posts: 293
- Joined: Jul 15, 2021 7:23
- Location: Greece
- Contact:
Re: Forcing fucus on edittext?
he said that he have used window9 libLöwenherz wrote: ↑Sep 24, 2024 10:17 Hello softfoot.. Not so clear what you are meaning? Do you are using winapi SDK Style for your gui with winmain / wndproc? Whats your Intension with the combobox and edibix?
WM_SETFOCUS and WM_KILLFOCUS
(wndproc)
hWndFocus = GetFocus ()
for simple gui exists too
SetFocus can be used for an edit-control-window... .
Re: Forcing fucus on edittext?
OK here's an example for an editbox created by Jose Roca with afx include Files
In winmain there is a setfocus hEdit and below in wndproc Part Case EN_Setfocus
'
In winmain there is a setfocus hEdit and below in wndproc Part Case EN_Setfocus
'
Code: Select all
#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
USING Afx
CONST IDC_EDIT1 = 1001
CONST IDC_EDIT2 = 1002
DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL szCmdLine AS ZSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
END WinMain(GetModuleHandleW(NULL), NULL, COMMAND(), SW_NORMAL)
' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL szCmdLine AS ZSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
AfxSetProcessDPIAware
' // Create the main window
DIM pWindow AS CWindow
pWindow.Create(NULL, "Edit controls - Auto selection of text", @WndProc)
' // Sizes it by setting the wanted width and height of its client area
pWindow.SetClientSize(500, 320)
' // Centers the window
pWindow.Center
' // Add an Edit control
DIM hEdit AS HWND = pWindow.AddControl("Edit", , IDC_EDIT1, "First Textbox", 20, 35, 305, 23)
' // Add another Edit control
pWindow.AddControl("Edit", , IDC_EDIT2, "Second Textbox", 20, 75, 305, 23)
' // Set the focus in the first edit control
SetFocus hEdit
' // Highlight the text
Edit_SetSel(hEdit, 0, -1)
' // Dispatch Windows messages
FUNCTION = pWindow.DoEvents(nCmdShow)
END FUNCTION
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
SELECT CASE uMsg
CASE WM_COMMAND
SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
CASE IDCANCEL
' // If ESC key pressed, close the application sending an WM_CLOSE message
IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
SendMessageW hwnd, WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
CASE EN_SETFOCUS
SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
' Note: To deselect, use EM_SETSEL, -1, 0
CASE IDC_EDIT1
Edit_SetSel(GetDlgItem(hWnd, IDC_EDIT1), 0, -1)
CASE IDC_EDIT2
Edit_SetSel(GetDlgItem(hWnd, IDC_EDIT2), 0, -1)
END SELECT
EXIT FUNCTION
END SELECT
CASE WM_DESTROY
' // End the application
PostQuitMessage(0)
EXIT FUNCTION
END SELECT
' // Default processing of Windows messages
FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
-
- Posts: 293
- Joined: Jul 15, 2021 7:23
- Location: Greece
- Contact:
Re: Forcing fucus on edittext?
window9 has its own SetFocus() function
example
you provide the handle of gadget to SetFocus and that's it, just change the ButtonGadget with EditorGadget
example
Code: Select all
ButtonGadget(1,10,10,60,30,"button")
SetFocus(Gadgetid(1)) ' focus on the button
Re: Forcing fucus on edittext?
Worked a treat
Dave
Dave