Set focus on a specific window, dialog or control

To set focus to WordPerfect, use this command: 

vFocus:=SetFocus("Corel WordPerfect - *")

To set focus to a dialog, use a similar command, but specify the caption of the dialog in the parameter: 

vFocus:=SetFocus("MyDialog")

You can specify the complete, exact caption, or if the caption may vary, specify part of it and include an asterisk, as shown in the first example above.

You can check whether the command was successful, if desired, by testing vFocus.   If successful, it will have a value of 1.  If not, it will have a value of 0.

Place this routine towards the bottom of the macro, along with any other PROCEDURES or FUNCTIONS.

 //****************************************************************
 // Copyright (c) 1999 J. Jeppson All Rights Reserved.
 // http://www.wpmacros.com
 // Function: SetFocus(vCaption)
 // Purpose: Set focus on a specific window or dialog
 // Action: Attempt to set focus, then return whether successful or not
 // Input: The caption of the window or dialog to set focus to
 // Output: The return value 0 = failure, 1 = success 
 //*****************************************************************

FUNCTION SetFocus(vCaption)
 hWnd:=AppLocate(vCaption)
 DLLLoad(User; "User32.exe")
 DLLCall (User; "SetForegroundWindow"; vResult:Integer; {hWnd})
 DLLFree(User)
 Return(vResult)
ENDFUNC

To set focus to a specific control on a dialog, use the following command:

 RegionSetFocus("WordPerfect.DialogName.ControlName")

Dialog and control names are case-sensitive. If the dialog is not displayed when the command is invoked, or if the specified control does not exist ont hat dialog, and error will occur.  You can use this command on either WordPerfect dialogs or user-defined dialogs. Some dialogs that appear within WordPerfect are shared code dialogs, and may not have a named region.

If you are setting focus on a user-defined dialog, the dialog name and control name can be found in the properties of the dialog in the Dialog Editor, or if you are using old-style dialogs, in the DialogAdd command that adds the control.

For information on determining the named region of a WordPerfect dialog control, see How to get named regions for WP dialogs.

Terms of Use:

You may include the code displayed here in your own macros with the following conditions:

The code must be included in its entirety, including copyright and header information.
You may use the code in macros used within your own organization, as part of your job, for your employer, or for your own personal use.
You may modify the code to meet your own needs.
If you modify any code in the routine, you must comment out the original line of code, and leave that original line intact, then type a new line of code with the change that you made. You must then add a comment  noting your change. 
You may not use the code in macros you create for hire, other than at your regular work for an employer, where the macrowill be used in-house.  For example, you may not use this routine in macros you create, modify, or convert for hire as a consultant for a company or individual that you are not a regular employee for. 
You may not sell or publish macros that use this routine in any form. 
You accept full responsibility for macros that you include this routine in.
J. Jeppson will not be obligated  to make the code work for you, or for your particular need or usage.
Under no circumstances will J. Jeppson be held liable for any damages or liabilities incurred while using  this code.

 

Copyright Notice: The information included in these pages is protected by US Copyright.  If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your particular purpose, or for your ability or inability to use the information. You are advised to make backups of all relevant files before implementing any suggestion  or technique.
© Copyright 1999 by J. Jeppson.