Old 23rd December 2005, 12:02   #1
MikeSchinkel
Guest
 
Posts: n/a
Set Focus to a Field

I'm trying to use the function on the wiki Set Focus to a Control but there is only an abstract function call syntax and no tangible working example and I'm having a hard time figuring out how to call it.

Can someone please help and give me a real simple example that would set the focus to the first text field in a custom dialog? Better yet, add it to the wiki too?

Thanks in advance.
  Reply With Quote
Old 23rd December 2005, 14:27   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
It is quite simple really.

code:
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



-Stu
Afrow UK is offline   Reply With Quote
Old 23rd January 2007, 18:32   #3
********
Junior Member
 
Join Date: May 2004
Posts: 43
From version 2.24 InstallOptions has native FOCUS flag
******** is offline   Reply With Quote
Old 23rd January 2007, 19:22   #4
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to Comm@nder21
NSIS version 2.24 is still to be released

InstallOptions will be v2.45 then.
Comm@nder21 is offline   Reply With Quote
Old 20th March 2007, 03:46   #5
darshanaltekar
Junior Member
 
Join Date: Feb 2007
Posts: 47
SetFocus is not working can anyone tell me why?


Page custom organisation_id_pre organisation_id_leave

function organisation_id_pre
strcmp $ALREADY_INSTALLED "YES" 0 +2
abort
!insertmacro MUI_HEADER_TEXT "Required Information" "Please enter following required information"
InstallOptions:ialog "$PLUGINSDIR\Organisation_id.ini"
Pop $HWND_org_id
functionend



function organisation_id_leave
ReadINIStr $0 "$PLUGINSDIR\Organisation_id.ini" 'Field 2' "State" ;l$ip_addr "$PLUGINSDIR\Organisation_id.ini" 'Field 4' "State"
ReadINIStr $1 "$PLUGINSDIR\Organisation_id.ini" 'Field 3' "State"
ReadINIStr $2 "$PLUGINSDIR\Organisation_id.ini" 'Field 4' "State"
ReadINIStr $3 "$PLUGINSDIR\Organisation_id.ini" 'Field 5' "State"

${If} $0 > '255'
messagebox mb_ok "IP address not valid from IP field 1"
Push "$PLUGINSDIR\Organisation_id.ini" ;Page .ini file where the field can be found.
Push "$HWND_org_id" ;Page handle you got when reserving the page.
Push "2" ;Field number to set focus.
Call SetFocus
!insertmacro MUI_INSTALLOPTIONS_SHOW
; WriteINIStr "$PLUGINSDIR\Organisation_id.ini" 'Field 2' 'Flags' 'FOCUS'
; FlushINI $TEMP\something.ini
; !insertmacro MUI_INSTALLOPTIONS_READ $R1 "$PLUGINSDIR\Organisation_id.ini" "Field 2" "HWND"
; SendMessage $R1 ${WM_SETFOCUS} 0 0
; SendMessage $R1 ${WM_SETTEXT} 0 "STR:8080"
; abort
${EndIf}
darshanaltekar is offline   Reply With Quote
Old 20th March 2007, 18:36   #6
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Don't call MUI_INSTALLOPTIONS_SHOW in the leave function. That should only be called in the page callback function (organistaion_id_pre in your case).

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 21st March 2007, 09:03   #7
darshanaltekar
Junior Member
 
Join Date: Feb 2007
Posts: 47
If i dont display the page again how the chages will get reflect in UI ?
darshanaltekar is offline   Reply With Quote
Old 21st March 2007, 18:56   #8
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
If you call Abort, the page isn't left. If you call InstallOptions again, you just create another page with the old settings and will create trouble when the pages are destroyed.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 22nd March 2007, 11:01   #9
darshanaltekar
Junior Member
 
Join Date: Feb 2007
Posts: 47
Then what i should i do to reflect the changes
darshanaltekar is offline   Reply With Quote
Old 23rd March 2007, 06:35   #10
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
As I said, call Abort.
code:
Function leave
Abort # in case leaving the page should be stopped...
FunctionEnd


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 17:32   #11
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
I was able to use this thread to set focus to a known field number, but how do I focus the next button?
mrtech is offline   Reply With Quote
Old 20th July 2007, 17:40   #12
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
code:
!include WinMessages.nsh
#...
GetDlgItem $0 $HWNDPARENT 1
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $0 1


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 18:05   #13
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
tried a few things, but where in this logic would that go, i've commented out what I have my hacky SetFocus to remove focus from the text object that I have in there:

code:

!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "eula.ini"

Pop $HWND ;HWND of dialog

; this removes the focus from the text field on my custom
; form so that pressing enter continues the install flow.
;Push "eula.ini"found.
;Push "$HWND"
;Push "7" ; this is a custom label
;Call SetFocus

Call SetOtherGoodies ;

; Now show the dialog
!insertmacro MUI_INSTALLOPTIONS_SHOW

mrtech is offline   Reply With Quote
Old 20th July 2007, 18:10   #14
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Ah, you want the focus to go there right away. I don't think that'd be possible without modifying InstallOptions. But why do it? Since the next button is the default button, it'd still go to the next page when you hit enter.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 18:12   #15
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
that's just it, it doesn't I have call just after the Pop to:

!insertmacro MUI_INSTALLOPTIONS_READ $DLGITEM "eula.ini" "Field 4" "HWND"
SetCtlColors $DLGITEM 0x000000 0xFFFFFF

Field 4 is my text box, focus is put there and pressing enter doesn't work.
mrtech is offline   Reply With Quote
Old 20th July 2007, 18:14   #16
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Have you tried using the FOCUS flag instead?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 18:18   #17
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
that's another one, where does the focus flag go for the next button? been trying to do searches here in the forums for about 15-20 minutes, but no examples of where to use the focus flags, etc. pardon my moronic ways...
mrtech is offline   Reply With Quote
Old 20th July 2007, 18:20   #18
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Not for the Next button, for the control you want focus for. Without any settings, the first control should receive focus and the Next button should still be the default button, so pressing enter should still go to the next page.

There is no setting to set focus to the Next button, because there shouldn't be any need to do that.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 18:29   #19
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
how do I set the focus flag to one of my controls?
mrtech is offline   Reply With Quote
Old 20th July 2007, 18:32   #20
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Just add Flags=FOCUS in the INI file.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 18:38   #21
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
ok, I had tried that on the label and link controls just to get the focus off of the text control, but I have to see what's up. thanks.
mrtech is offline   Reply With Quote
Old 20th July 2007, 18:43   #22
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
It won't work on those controls. It knows which controls can receive focus and will ignore the flag if they can't. But weren't you saying you wanted the focus on the Next button rather than off it?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 18:46   #23
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
yeah, but if I can get the focus off the text control (as I have done with the SetFocus function) then the Next button will behave like the default button and continue when pressing enter.
mrtech is offline   Reply With Quote
Old 20th July 2007, 18:48   #24
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
It should behave that way with or without focus.

How about you attach an example? I'm starting to get confused about what exactly happens and what exactly you want.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 19:41   #25
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
here's a stripped version of what I'm trying to do, thanks.
Attached Files
File Type: zip eula-test.zip (2.2 KB, 383 views)
mrtech is offline   Reply With Quote
Old 20th July 2007, 19:43   #26
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
What's the BackButton plug-in?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 19:47   #27
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
oops just remove that puppy
mrtech is offline   Reply With Quote
Old 20th July 2007, 19:54   #28
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Ah, you didn't mention it's a multiline text field. It might have the same bug as with the richedit control where it eats up Enter and Escape even though it doesn't have the ES_WANTRETURN style. Instead of leaving them be, it acts on the dialog manager's behalf and sends WM_COMMAND to IDOK or WM_CLOSE to its parent dialog. But its parent dialog is just a internal dialog which doesn't handle this. Unlike richedit, edit controls don't have EN_MSGFILTER so if it's really the case, it'd require subclassing.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th July 2007, 19:56   #29
mrtech
Junior Member
 
Join Date: Oct 2002
Posts: 46
ok, I'll stick with my SetFocus hack for now, thanks.
mrtech is offline   Reply With Quote
Old 8th September 2007, 19:48   #30
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Raymond Chen confirms this is the same bug as with the Rich Edit control. His post also links to another post stating the solution, similar to what Sunjammer used for the RichEdit. I need to think how this can be implemented for nsDialogs as you obviously do want the controls eat the Enter key in some cases.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump