

#XOJO FOCUS SET CONTROL CODE#
To the method, add the Declare code as follows: Declare Function becomeFirstResponder Lib "UIKit" Selector "becomeFirstResponder" (controlHandle As Ptr) As Boolean To do this, create a module and add a global method to it with this declaration: SetFocus(Extends c As iOSTextField) As Boolean If you want to use this function often you can wrap it in an Extension method so that it is available everywhere. The Call command is used to ignore the return value, which is not relevant in this situation. In the open event of the toolbar add code to inject your control into the toolbar item. When designing your Toolbar make sure the locations where you want to use controls are regular 'PushButton' style toolbar items. Assuming you have a control called TextField1 on the view you can call the method like this: Call becomeFirstResponder(TextField1.Handle) Native Xojo doesnt support placing controls in the toolbar, but the App Kit has you covered there. You can call this method just as you would any other Xojo method, but remember you have to pass it a reference to the control. The important thing to note here is that you have to always have a parameter (the first parameter) that is a reference to an instance of the class (or control in this case). With this information you can now create a Xojo Declare command to call it: Declare Function becomeFirstResponder Lib "UIKit" Selector "becomeFirstResponder" (controlHandle As Ptr) As Boolean You should also note on the page that this is part of the UIKit library. The above is Objective-C code that indicates that this is a function that returns a Boolean value. When you click on becomeFirstResponder you’ll get to its doc page with this declaration: (BOOL)becomeFirstResponder On the doc page you’ll find information about calling becomeFirstResponder to show the keyboard, which is what happens when a text field gets focus. Click the link to open the Apple doc page. Looking at the Summary on the iOSTextField page you’ll see that the actual UIKit control is called “UITextField”. To start with a simple example, consider that you may want to set focus to a text control such as an iOSTextField. For the Xojo Declare, the first parameter is always required and must be a reference to the class containing the method you are calling. Unlike with Xojo methods, the case of the name also has to match exactly. The selector name has to end in a “:” if there are any parameters that are passed, an oddity of how Objective-C works. When you call Cocoa methods you supply the method name using the Selector part of the Declare command. Xojo Declares use the Objective-C names so be sure to refer to those in the documentation rather than the Swift naming.


Most of the time you will reference the Foundation and UIKit libraries, but there are many other libraries as well. To create a Declare statement you first need to track down the API you want to use in Apple’s documentation: Apple Developer Documentation. Examplesįor an example, see Initializing a Dialog Box.You can call into Cocoa Touch APIs to use methods and properties that are not built into the framework by using the Declare command. For the Xojo Declare, the first parameter is always required and must be a reference to the class containing the method you are calling. This allows a thread to call SetFocus to set the keyboard focus to a window attached to another thread's message queue. Otherwise, the messages produced do not have this bit set.īy using the AttachThreadInput function, a thread can attach its input processing to another thread. If the VK_MENU key is also pressed, bit 30 of the lParam parameter of the message is set. If a window is active but does not have the focus, any key pressed produces the WM_SYSCHAR, WM_SYSKEYDOWN, or WM_SYSKEYUP message. It also activates either the window that receives the focus or the parent of the window that receives the focus. This function sends a WM_KILLFOCUS message to the window that loses the keyboard focus and a WM_SETFOCUS message to the window that receives the keyboard focus. To get extended error information, call GetLastError function.Įxtended error ERROR_INVALID_PARAMETER (0x57) means that window is in disabled state. If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL. If the function succeeds, the return value is the handle to the window that previously had the keyboard focus. If this parameter is NULL, keystrokes are ignored. Syntax HWND SetFocus(Ī handle to the window that will receive the keyboard input. The window must be attached to the calling thread's message queue. Sets the keyboard focus to the specified window.
