Archive: Changing DirRequest control properties


Changing DirRequest control properties
Hi, noob alert.

I am using NSIS to create an installer for our product, I must say first a big thanks to anyone involved in the development of NSIS, or people who help out here.

Basically my query is relating to a custom page I have created, which in all essence looks near identical to the MUI_PAGE_DIRECTORY macro, although I have built a custom dialog using the DirRequest control, asking the user 'where a directory is' (not a normal install directory), anyway, its near enough finished but this question is merely about cosmetics really,

is it possible to change the "..." Caption on the button in the DirRequest control to "B&rowse" or any text you like? I just want it to look near identical to the MUI_PAGE_DIRECTORY page, and this is the only thing stopping me so far.

Many thanks in advance for anyone who replies.


I just read something about this being possible in later versions of installoptions2, does this mean that functionality is included in the NSIS 2.16 release?


Not that I am aware of.
You can try using InstallOptionsEx.

If all else fails, you'd need to change it with the System plugin by calling user32::SetWindowText and then resize the button control with user32::SetWindowPos.

May I ask why you need to create a custom dialog which is almost identical to the NSIS Directory page?

-Stu


I want to ask the 'user' for the location of their ColdFusionMX install.

I did have it working using just another MUI_PAGE_DIRECTORY, but i honestly found it easier building my own dialog rather than removing the 'space required/space available' and the title and subtitle, also I found it added the directory in question to the end, probably as I didnt set a seperate variable for it to go out of.

apologies for my noobiness I've only been on the case since this week. NSIS is very powerful though and a great tool.

Hmm, seems a little tricky, it doesnt look so bad as "..." but it'd be nice if it matched the dialog following it.

I'll keep looking around, I take it InstallOptionsEX is a seperate external plugin to InstallOptions2, and doesnt come with NSIS?

Thanks for your help.


If I remember correctly, putting a \ on the end of the install dir path for the Directory pages stops the end dir name being appended to the end every time (or vise versa).

InstallOptionsEx is on the Wiki.

-Stu


It's your lucky day :p

I decided to have a 'break' from doing maths revision.
This example changes the browse button text to "Browse..." and resizes the button accordingly.

-Stu


I'll try it at work tomorrow, very kind of you.

thanks


Nice trick, Afrow!
Another option is to setup a custom page with a text box and a button. (Make the button say whatever you want.)

Then, using the DialogsEX plugin, make a folder browser appear when clicking on the button.

Sounds complicated, but it's really fairly simple. The page's exit function would look something like this:


Function MyLeaveFunction
; This assumes that the text field is Field 5 and the browse button is Field 6
ReadIniStr '$PLUGINSDIR\mypage.ini' $0 'Settings' 'State'
StrCmp $0 6 DirBrowseButton Continue

DirBrowseButton:
; browse button was pressed:
; make sure you also write the value to the ini file in case you return to the page later during the install
${ModernFolderBox} "Browse for Key Disk" "Choose a location contianing a keydisk" "C:\" ${Var_1}
!insertmacro XPUI_INSTALLOPTIONS_WRITE "Page_InputcusNumber.ini" "Field 5" "State" "$1"
SendMessage $2 ${WM_SETTEXT} 0 "STR:$1"
abort

continue:
; [ the rest of your code goes here ]
FunctionEnd

Seems to work fine! thanks a lot

I noticed the defines at the top of the code arent used so I cut it down a bit, I am just fiddling with the button width size multiplication so I can get it the same width, maybe eventually position, and maybe height as the browse button on the next page.

I just know people will look at it and moan although it looks fine to me, I will try using the example to change the other properties of the control. thanks!


Yeh I put those defines in there and forgot to put them into the actual code :p

$R3 stores the height, but I'm sure you worked that out :)

-Stu


Btw, if you're displaying a NSIS Directory page before your custom page, you could get the dimensions of the browse button from there instead.

-Stu


Hmm, maybe its more sense to ask for the product install dir using a normal nsis directory page, then ask for the CF install location after. I can now change the height and size of the button but not its location hehe.

Anyway, I'm starting to try and fill in some logic for checking the users' input CF dir is valid, using the Locate plugin, but I'm not entirely sure how to block on the current page (obviously disable next button) and keep asking for a valid path, with a messagebox to prompt illegal paths.

I seem to have it producing a messagebox but not reverting to the same window, it just carries on to the next NSIS page.

I'll poke around and probably swap the page order as it looks better asking for the product dir before the CF dir.

Obviously the "product install" path doesnt need to exist, as the installer will create it, but the 'where is CF installed' box doesnt need to create directories etc, it just needs to unzip files to the correct locations in the CF dir. I'm just having a few issues blocking on a page, waiting for a 'decent' CF path from the dirrequest, and messagebox'ing the user if its not a decent path.

plus if I could change the button on my custom page like you said, to have the same dimensions as the Dirrequest button on the previous page, it would be great.

obviously I'm not asking anyone to hand me this on a plate, and most of this bumf is probably me clearing it in my own head, but at least you'll maybe understand what I'm getting at, hehe :)

Thanks again

Then I'll think about the dir checking again. ack!


I would consider using two Directory pages again. In normal InstallOptions the NOTIFY flag doesn't work well with DirRequest fields. You won't be able to validate the new path on key up, for example. You'd have to check the path in the pages' Leave function and then call Abort to go back to the page.

The NSIS Directory page already validates the entered directory path for you. It also removes any unwanted characters if you're dealing with the $INSTDIR variable when Pushing it to the stack.

-Stu


ah, hmm. whimper

I did have it checking in the leave function before, I'm not against using another normal directory page again, but I've maybe just wasted a day creating this custom dialog, when I could have been removing parts from the default directory page.

hm, what you've said does point to using another directory page as the best method, if I can remove all the unimportant items from the said page. I'll take a look


It seems the :

locate CFdir
if fail
messagebox "choose correct cf dir etc yeah"
abort
else
continue:


: actually looks alright, I thought it would produce a blank page with the messagebox on, then go back to the previous page, but this method actually looks 'ok', now if I could get the button to move away from the textbox a bit in the dirrequest control, and get it to move up a little so the bottom of the texbox and the bottom of the button are the same level, but not at the top, that would basically mean my custom page is finished and I wouldnt have to resort to using a normal NSIS directory page and removing the irrellevant details.

I'm good at rambling, thanks though :)


Well thats the logic added

Only moving and resizing the button on the dirrequest control is an issue, but thats not really that important if it can't be moved it can't.

thanks anyone who helped, especially Afrow UK

(I'll probably make another topic regarding any other queries I have, after reading of course)


The button can be moved, but it would need quite a bit of extra code. GetClientRect returns 0 for the X and Y coordinates (bit pointless I know) because it works with the control itself rather than anything to do with the window that it sits in.

A better idea would be to make the DirRequest text box width smaller. This can be achieved with the same code, except you probably need to take about 10 units off, and the control ID will be one less than that of the button (e.g. 1201)

-Stu