bnicer
7th May 2010 14:26 UTC
unfocus a control
To unset the focus on the location on the Directory page, is the only way to set the focus on another control?
GetDlgItem $0 $mui.DirectoryPage "1020" ; Groupbox control
System::Call 'user32::SetFocus(i r0)' ; unfocus 1019, Edit control (location input)
It seems harmless enough, but it might be even better to set the focus on nothing, to blur.
Can that be done? My apologies for the trivial nature of the question.
Afrow UK
7th May 2010 16:52 UTC
I'm not certain but I think the only way is to move focus to another control.
Stu
DrO
7th May 2010 17:30 UTC
From my understanding of Win32, at least one control will have focus when an app is active unless every control is disabled (though not 100% on that). So something will have to have focus unless the installer is unfocused (which will defeat what you're trying to do).
Though i'm not too sure where the need for a requirement to not have the directory edit control focused, a bit more info of what you're trying to achieve may make it easier to give you a better answer.
-daz
Anders
7th May 2010 18:59 UTC
There are two levels when it comes to focus, the window manager and on top of that, the dialog manager. When you call SetFocus you are bypassing the dialog manager and talking directly to the window manager. This could be problematic since the dialog manager is actually responsible for the tab order. See http://blogs.msdn.com/oldnewthing/ar...02/205624.aspx for more.
But like Dro, I feel we need more info about what you really want...
bnicer
7th May 2010 21:46 UTC
I noticed some quirkiness with the tab-order at first -- e.g. alt-N, alt-B not responding -- but something I did seems to have fixed it. I was experimenting with different controls ...
The installer's behavior is that when a destination is full, the path cannot be installed to and the input text is selected, showing the path is taken. Otherwise, the input text is unselected, showing that the destination is available.
Moving the caret to the beginning of the path text would achieve that the text is unselected while the caret flashes. When the focus is set to another control, the caret is also removed. No flashing.
On the Startmenu Page, if the group name that displays in the Edit control is in use, the text is selected. If the group name is free, the text is unselected.
The code is below. DirState checks if the folder is full, empty or exists.
StartMenuPageShow
!ifdef MUI_STARTMENUPAGE_INTERFACE
GetDlgItem$0 $mui.StartMenuPage "1002" ; Edit control
GetDlgItem$1 $mui.StartMenuPage "1003" ; Label control
!else
GetDlgItem $0 $MUI_HWND "1002"
GetDlgItem $1 $MUI_HWND "1003"
!endif
Call check_sm_folder
FunctionEnd
>Function check_sm_folder
System
::Call 'user32::GetWindowText(i r0, t .R0, i 256)'
${If} $REM != "firsttime"
${AndIf} ${TEMP1} == $ICONS_PATH
${AndIf} $PATH == $INSTDIR
StrCpy $R1 2 #
${Else}
SetShellVarContext current
Push $SMPROGRAMS${TEMP1}
Call DirState
Pop $R1
${If} $R1 != 1
SetShellVarContext all
Push $SMPROGRAMS${TEMP1}
Call DirState
Pop $R1
${EndIf}
${EndIf}
${If}$R1 == 1
System::Call 'user32::SetFocus(i r0)'
SendMessage $0 ${EM_SETSEL} 0 -1 ; select location input
${Else}
System::Call 'user32::SetFocus(i r1)'
${EndIf}
>FunctionEnd
>Function StartMenuPageLeave
Call check_sm_folder
${If} $R1 == 1
MessageBox MB_USERICON|MB_OK "$(MESSAGE_SMF_USED)"
Abort ; smfolder not empty
${EndIf}
>FunctionEnd
>
Tab-order appears to be unaffected.