Set Focus to a Control: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.)
 
(7 intermediate revisions by 3 users not shown)
Line 2: Line 2:


== Description ==
== Description ==
'''Required:''' [[InstallOptions]] or [[InstallOptionsEx]] and [[System]] plugins.
'''Deprecated by:''' NSIS 2.24 - FOCUS InstallOptions flag.


This function sets focus to a control using InstallOptions.
'''Required:''' [[InstallOptions plug-in]] based resource file and [[System plug-in]].
 
This function sets focus to a control using information from an InstallOptions plug-in based resource file.
 
Normally, InstallOptions used to set the focus to the first focusable control found in the INI file. This allows specifying another control without messing with the controls' order.


== Function Call ==
== Function Call ==
Line 87: Line 91:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
== Snippet of usage (without "ioFile.ini") - by [[User:Afrow UK|Afrow UK]] ==
[http://forums.winamp.com/showthread.php?postid=1831384#post1831384 Forum link]
<highlight-nsis>
Page Custom ShowCustom1
Var HWND
Function .onInit
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "ioFile.ini"
FunctionEnd
Function ShowCustom1
  !insertmacro MUI_HEADERTEXT "blah" "blah"
  !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ioFile.ini"
  Pop $HWND ;HWND (handle) of dialog
    Push "$PLUGINSDIR\ioFile.ini" ;Page .ini file where the field can be found.
    Push "$HWND" ;Page handle you got when reserving the page.
    Push "1" ;Field number to set focus.
    Call SetFocus
  !insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd
</highlight-nsis>
{| style="background-color: #FFF; color:#000;  width: 100%; color: #353638;"
{{Pp-deprecated}}
|}


[[Category:User Interface Functions]]
[[Category:User Interface Functions]]

Latest revision as of 19:35, 23 January 2007

Author: deguix (talk, contrib)


Description

Deprecated by: NSIS 2.24 - FOCUS InstallOptions flag.

Required: InstallOptions plug-in based resource file and System plug-in.

This function sets focus to a control using information from an InstallOptions plug-in based resource file.

Normally, InstallOptions used to set the focus to the first focusable control found in the INI file. This allows specifying another control without messing with the controls' order.

Function Call

Push "Page.ini" ;Page .ini file where the field can be found.
Push "Handle" ;Page handle you got when reserving the page.
Push "Number" ;Field number to set focus.
Call SetFocus

Function Code

;----------------------------------------------------------------------------
; Title             : Set focus to a control
; Short Name        : SetFocus
; Last Changed      : 22/Feb/2005
; Code Type         : Function
; Code Sub-Type     : One-way Input
;----------------------------------------------------------------------------
; Required          : InstallOptions and System plugins.
; Description       : Sets focus to a control using InstallOptions.
;----------------------------------------------------------------------------
; Function Call     : Push "Page.ini"
;                       Page .ini file where the field can be found.
;
;                     Push "Handle"
;                       Page handle you got when reserving the page.
;
;                     Push "Number"
;                       Field number to set focus.
;
;                     Call SetFocus
;----------------------------------------------------------------------------
; Author            : Diego Pedroso
; Author Reg. Name  : deguix
;----------------------------------------------------------------------------
 
Function SetFocus
 
  Exch $0 ; Control Number
  Exch
  Exch $2 ; Page Handle
  Exch
  Exch 2
  Exch $3 ; Page INI File
  Exch 2
  Push $1
  Push $R0
  Push $R1
  Push $R2
  Push $R3
  Push $R4
  Push $R5
 
  IntOp $1 $0 + 1199
  GetDlgItem $1 $2 $1
 
  # Send WM_SETFOCUS message
  System::Call "user32::SetFocus(i r1, i 0x0007, i,i)i"
 
  ReadINIStr $R0 "$3" "Field $0" "Left"
  ReadINIStr $R1 "$3" "Field $0" "Right"
  ReadINIStr $R3 "$3" "Field $0" "Top"
  ReadINIStr $R4 "$3" "Field $0" "Bottom"
  IntOp $R2 $R1 - $R0
  IntOp $R5 $R4 - $R3
 
  System::Call "user32::CreateCaret(i r0, i, i R2, i R5)i"
  System::Call "user32::ShowCaret(i r0)i"
 
  Pop $R5
  Pop $R4
  Pop $R3
  Pop $R2
  Pop $R1
  Pop $R0
  Pop $1
  Pop $0
  Pop $2
  Pop $3
 
FunctionEnd

Snippet of usage (without "ioFile.ini") - by Afrow UK

Forum link

Page Custom ShowCustom1
 
Var HWND
 
Function .onInit
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "ioFile.ini"
FunctionEnd
 
Function ShowCustom1
 
  !insertmacro MUI_HEADERTEXT "blah" "blah"
 
  !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ioFile.ini"
  Pop $HWND ;HWND (handle) of dialog
 
    Push "$PLUGINSDIR\ioFile.ini" ;Page .ini file where the field can be found.
    Push "$HWND" ;Page handle you got when reserving the page.
    Push "1" ;Field number to set focus.
    Call SetFocus
 
  !insertmacro MUI_INSTALLOPTIONS_SHOW
 
FunctionEnd
This project or code is deprecated and is here for archival purposes only.