Old 10th March 2006, 22:24   #1
dienjd
Senior Member
 
Join Date: Oct 2005
Posts: 189
SetCaretPos system call

I'm trying to set the caret position within the text field of a custom page. My call is within the SetFocus function.
code:

System::Call "user32::CreateCaret(i r0, i, i R2, i R5)i"
System::Call "user32::SetCaretPos(i 10, i) i .r1"
System::Call "user32::ShowCaret(i r0)i"


This is the same order of calls that MSDN uses in their example. My return value ($1) is 1, which means that the call succeeded, according to the docs.

But, no matter what values I pass in, the caret remains at the beginning of the text field when it is given focus. Has anybody used this successfully? If so, how do you know what to pass in for the x/y coordinates? For example, how would you set the position to the end of the string in a text field?
dienjd is offline   Reply With Quote
Old 11th March 2006, 02:55   #2
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Set caret position to the end of the text:

Test.nsi
code:
Name "Test"
OutFile "Test.exe"

!include "WinMessages.nsh"

Var HWND
Var INI

Page Custom ShowCustom LeaveCustom
Page instfiles

Function ShowCustom
InstallOptions::initDialog /NOUNLOAD "$INI"
Pop $HWND

GetDlgItem $0 $HWND 1200
SendMessage $0 ${WM_SETTEXT} 1 "STR:12345$\r$\n67890$\r$\nabcdf$\r$\n"
System::Call "user32::SetFocus(i r0)"
System::Call "user32::SendMessage(i r0, i ${EM_GETLINECOUNT}, i 0, i 0)i .r1"
IntOp $1 $1 - 1
System::Call "user32::SendMessage(i r0, i ${EM_LINEINDEX}, i r1, i 0)i .r2"
System::Call "user32::SendMessage(i r0, i ${EM_LINELENGTH}, i r2, i 0)i .r3"
IntOp $4 $3 + $2
SendMessage $0 ${EM_SETSEL} $4 $4
SendMessage $0 ${EM_LINESCROLL} 0 $1

InstallOptions::show
Pop $0
FunctionEnd

Function LeaveCustom
ReadINIStr $0 $INI "Settings" "State"
StrCmp $0 0 Enter
goto main

main:
Abort

Enter:
FunctionEnd

Function .onInit
InitPluginsDir
GetTempFileName $INI $PLUGINSDIR
File /oname=$INI "Test.ini"
FunctionEnd

Section "Empty"
SectionEnd


Test.ini
code:
[Settings]
NumFields=1
NextButtonText=&Enter

[Field 1]
Type=Text
Flags=MULTILINE|VSCROLL|HSCROLL
Left=5
Right=-48
Top=5
Bottom=60


Last edited by Instructor; 11th March 2006 at 03:20.
Instructor is offline   Reply With Quote
Old 11th March 2006, 05:23   #3
dienjd
Senior Member
 
Join Date: Oct 2005
Posts: 189
Thanks Instructor! It works perfectly
dienjd 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