Archive: MessageBox with more buttons


MessageBox with more buttons
I am looking for a way to make a MessageBox with the buttons "yes", "yes to all", "no" and "no to all".

I searched, and checked documentation but still don't know how to do it.

anyone? ;)


As always, it's a built-in Windows API function, you need a plug-in to change it.


A brand new plugin, or a trick with the system plugin?

I think you meant a brand new plugin but since I saw many nice tricks with that system plugin, maybe I can find a workaround :rolleyes:

If I can't find a workaround, users will have to click 'yes' to all ;)


With system plugin? I don't know... too much API calls since we're subclassing


mmm.... I was playing with messagboxes and saw that I can't use two sets of buttons at once, so the max buttons is three (abor, retry, ignore or yes, no, cancel), but there's a MB_DEFBUTTON4 for making default the 4th button. I am missing something?

Lobo, are you saying that using system plugin for this would be difficult but possible?


actually...in VB you are using the same MsgBox but you edit
the strings, you know: "OK", "CANCEL" with stuff you like.
Is subclassing. I think Nsis have one, maybe the developers can put some test code so we can convert it to system plugin syntax.


I don't think this is possible using the System plug-in. You have to write a new one.


System allows to do everething needed to create custom dialog, but NSIS somehow brokes all the dialogs created at the scripting thread. And the system couldn't create a new thread for it... :(


http://www2.skwire.net/~n0On3/Smileys/sad.gif

http://www2.skwire.net/~n0On3/Smileys/shock.gif


Try this (isn't complete yet but it shows the basics i hope ;) )

It allows you to set the title and caption as a normal messagebox but you can define the number of buttons to include and also the text for the 4 buttons on the messagebox (the 4th is the 'help' button).

Has a few problems still in handling the number of buttons and some of the standard styles of a messagebox but it works eg MB_HELP.

note: if a button text isn't associated for a button then in most cases the button text will be cleared - haven't put checking of that in yet :blah: .

Example is basic but should give you an idea of things so far (more complete info will come soon). I will alter the way of setting the button text so that you just pass in what you want to change
eg
with a yes|no|cancel then you can pass only the text needed for the 'no' to change it to yes|blah|cancel.

Feedback welcome

Daz

ps when using the 'help' button nothing happens at the moment - thinking of playing with it to act as a full button eventually if things work out


Nice ;) Thanks dude...


huh :) Windows Hooks ;) Nice idea!


Originally posted by brainsucker
huh :) Windows Hooks ;) Nice idea!
that's what i thought to :D

found it when i was playing with hooks to get all visible windows to dock to the edge of the desktop and found that i could catch a messagebox being created, so i can get its hwnd :)

will upload the new version when i get on the other work machine in a bit. changed a few bits so that now the 'help' button will react as a proper button (apart from a few cases still :( ) and fixed some bugs and stuff.

what's the normal buffer limit for the included messagebox?

-daz

update
latest version attached

now you can set only the button text you want to otherwise the existing text will be kept. also it doesn't matter which way round you pass in the button order :cool:

done a number of internal changes so that now there is a functional 'forth' button on the dialog so it is possible to do "yes", "yes to all", "no" and "no to all" and have the option working.

setting the number of buttons to -1 allows the normal button states to be set and the text can still be set for the buttons.

still are a few issues ie using MB_HELP to get the forth button will not always close for a few mode combinations when using '-1'.

enjoy
daz


wow!!!

I missed all this replies!!!

How could I!!!???

Thanks DrO, gonna test this :)


Originally posted by n0On3
wow!!!

I missed all this replies!!!

How could I!!!???

Thanks DrO, gonna test this :)
don't worry about it ;)

done a few more bits on it so that the 'help' button will always work as a full button whatever style is passed in and some more bug fixes/changes

also trying to get custom icon setting working for the messagebox as well - thought it might be useful :D

-daz

And where's the update?

I looked in the Archive and couldn't find it.


I looked in the Archive and couldn't find it.
latest version is now attached (with readme explaining how to use it that makes sense i hope :D )

only real feature missing now is the ability to set the icon shown by the messagebox to be a user defined icon (ran out of time last night).

wahtever mode you use now, the button texts will always be altered correctly and the 'help' button will always close the messagebox whatever the style used (wasa glaring issue in the last release)

has anyone tried it with a language other than english yet? i'm interested to see how it works with other languages.

also would the ability to alter the button sizes on the messagebox so that the text passed in will fit correctly be a good to implement?
(noted that NT has small buttons so the example may not appear correctly :( )

enjoy

-daz

ps will put a copy into the archive soon once i've got the user icon part working

thanks for posting :)

I haven't used any other languages than english.

and yes, auto-resize buttons seems nice


thanks for working in this plugin :up:


Note: thanks for writing my name in the text files, can you write 'n0On3' instead of 'n0on3'? ;)


At last user icon support works!!

Attached is now the latest version including a few typo fixes for the readme file.

@n0On3 - sorry for getting it wrong, it was 2:30am when i was writing that file ;)

note: if using the user icon option and the icon does not exist then a blank space will be seen where the icon goes - likely to happen with the second test messagebox in the example script (at least on NT, i found 2k was fine).

I will setup a archive page for this in a bit and when i get the chance to tonight i will work on the resizing of the text buttons so that the text will always fit :cool: (may take a while with other things on at the moment)

enjoy this people

-daz


auto-resize buttons seems nice
well it's implemented now so when you set the button text if you want it then the button will be resized to the text (and a bit more either side for a nicer look ;))
eg
"/but1 /trim install me now"

still a few little issues such as getting the sizing to work correctly when the text is just too big for the button.

also the messagebox will max out at 80% of the screen size (not fully supported yet and may add a little extra when this limit is reached...)

-daz

thanks :)

I wanted to say that I find the command a bit confusing:

I can pass which styles I want to use(like MB_OKCANCEL) but if I want to use them I have to pass "-1", but if i also pass "/but3 c" then the style is overwritten.

I also don't understand the hwnd. I thought these messageboxes will always be created from the installer, or is this plugin doing something more?

I tried to think a simpler format. Describing the window from up to down:

MessageBox::Show "window title" "icon.dll,3" "window text" 4 "IDYES" "yes to all" "IDNO" "no to all"

I used IDYES for telling that I want a 'yes' style in the first button and IDNO for having a no in the third. And I think that making it always return the number of the button instead of No = 9 is easier to understand.

I also think that if somebody uses a long text for a button, he will always want it resized, so the /trim switch can be avoided.

just some suggestions ;)


PS: maybe with this format you can pass things that can't be done, like this: MessageBox::Show "window title" "" "window text" 2 "IDNO" "IDYES" and you can't have a first button with a 'no' and the second be a 'yes'. If this is the case you can make the script refuse to compile and say that it has to be 'yes' and 'no' instead.


suggestions are good ;)

thought it was getting a bit confusing too for the parameters (was going to overhaul how they are passed anyway for v1.0).

I thought these messageboxes will always be created from the installer, or is this plugin doing something more?
when you pass a 0 for the parameter then it will use the installer as the owner. the reason it is in there is basically from the initial development phase of the plugin (since i ported the basics of what i had from another program) and was going to drop it anyway

I also think that if somebody uses a long text for a button, he will always want it resized, so the /trim switch can be avoided.
was going to drop it too - since that part isn't finished yet i was using the /trim to allow me to test the feature for specific button positions (without hard coding tests into the code) to make sure that the messagebox would resize and move subsequent buttons correctly.
MessageBox::Show "window title" "icon.dll,3" "window text" 4 "IDYES" "yes to all" "IDNO" "no to all"
nice :)
i like that idea and it's not to difficult to change the existing code to do it as well. also the "icon.dll,3" is better for the whole icon thing since "0,3" could be used to get the resource from the installer.

about the '-1' thing, the idea was that with it the function will return what the messagebox returns but with the ability if needed to alter the button text if wanted (late night programming that :)). so if the forth is 'no' then it will return 9 since that is the button's id.

can understand the confusion about it so i will map the return to 1,2,etc in all cases now (does make it more consistant) and will drop the -1 option.

"IDYES" "yes to all" "IDNO" "no to all" part - i like that idea and it isn't hard to put it in as things are since i can just set internally set the button text to 'yes' when a 'IDYES' is passed for example.

i can see what you're getting at about the IDNO can't be first but i think that if the return value is going to be mapped to the button number then it should not matter which way round the buttons are - just my thought on it.

hope that clarifies a few bits.
thanks for the suggestions n0On3 :), always good to have a different view point on things. will get on with this tonight and get a test version uploaded tomorrow.

-daz

ps just had a thought, if doing "IDYES" "yes to all" "IDNO" "no to all" then it's possible to drop the number of buttons specification. instead it can be worked out from the number of button texts passed in

Great!

I am very glad you liked my ideas :)


latest test version
changed the calling syntax of the function to be simpler and hopefully make more sense ;)

now the number of buttons to show is all based on the number of button strings passed with default button texts used when you pass the defines
e.g.
IDYES => 'Yes' IDCANCEL => 'Cancel' (see the readme for the supported options)

buttons are resized in all cases (more logical) and the resizing is more gradual especially when the text is near to the existing button width.

the handling of long button texts when the messagebox width is exceeded (that's the 80% of the screen limit) is not done yet.
also the MB_DEFBUTTON? style will not work for resized buttons (defaults to the first button but i have the fix worked out for it).

-daz


yes, this plugin works great :)

I found that I can't use the installer icon when the installer is set to silent:

SilentInstall "Silent"


great plugin, thanks :)


I found that I can't use the installer icon when the installer is set to silent
will have a look at that tonight, thanks for pointing it out (and will have a go at the few other bits left to do).

-daz

Can you create an archive page when it's finished?


Can you create an archive page when it's finished?
Will do that once i've got the last few bits fixed (and got the code readable ;) )

I found that I can't use the installer icon when the installer is set to silent
had a check of the code and the icon part works fine in a silent installer.

i did notice that in the example with v0.98 beta, the last messagebox did not have the icon set, instead it has a "" where the icon part goes.

working on the button widths at the moment for the 80% limit being reached. also fixed the default button issue - just needed to prevent a message being sent to the messagebox :igor:

should have the new version with the button adjustment fully done by tomorrow i hope

-daz

Originally posted by DrO
[B]had a check of the code and the icon part works fine in a silent installer.
You mean that you could use the icon when silent installer in the messagebox? I used your example and now, not only it's not showed but even crashes :(

I attach the thingy.



also, what's this "MB_ICONHAND" style? the nsis I use doesn't have it... :weird:

what OS are you using?
(checked the example and it is fine on NT4 and 2k)

also is it the last messagebox that is failing?

messagebox::show MB_TOPMOST|MB_DEFBUTTON2|MB_RIGHT "look at me a title" \
"" \
"and for a messagebox that will show an icon... :o)$\n" "ah go on if you dare" IDYES IDYES2
with the second line, to get the installer icon it should be "0,103" instead of "" - typo on my part (was trying to get that test version done beofre i left for work)

-daz

@n0On3 - if you can, can you let me know what the crash error is please (picture?)

I'll have a look at the code tonight (haven't touched it for a few days) and i'll make sure that any potential parts that could cause a crash are catered for. Will try and get a newer version up for tomorrow which should hopefully fix things for you.

Adding in parameter checks so that you can't do IDYES "blah" IDYES since it's not good having two 'Yes' buttons :)

also, what's this "MB_ICONHAND" style? the nsis I use doesn't have it...
magic that is ;) it is just the stop sign icon but using a different name (throw back to Windows 3.x before 95 came along and they altered the defined names that's all, check here)

-daz

added a page into the archive for the Customisable MessageBox plugin (thought a proper name would be good for it instead of 'MessageBox with more buttons' ;))

-daz

[p.s. is it fine to just link to here for the downloads since i haven't anywhere to host files :( ]


Originally posted by DrO
[B]what OS are you using?
(checked the example and it is fine on NT4 and 2k)

also is it the last messagebox that is failing?
sorry, I left that info. I use win98se. Does the compiled exe work in your 2k?

and is the first messagebox that fails. Strange because it works in another silent installer I made. But in that other it always shows 4 buttons. This is the code:
MessageBox::Show MB_ICONQUESTION "Can't Move, Copy instead?" "" \
`We can't move through different drives.$\nBut we can copy and \
delete if no errors` "Copy && Delete" "Copy" "IDCANCEL"

Originally posted by DrO
[p.s. is it fine to just link to here for the downloads since i haven't anywhere to host files :( ]
It can be put on the Archive too. Just e-mail the file to an Archive admin and we'll upload it.

give this version a try - have altered the handling of one or two strings internally so hopefully it won't crash (had not fully checked the module handle for a "" situation).

also included two compiled versions (normal and silent) which work on my machine at least ;)

note: long button text handling is still fudged (got to get full limit checking working still)

note 2: just looking at the function call, the "IDCANCEL" should be just IDCANCEL (no "'s around it) if you want the button text to be 'cancel' ;)

@n0On3: will test that later. i tested your file on NT4 and it worked (will check later on my machine under both oses)

@kichik: will pm it once it's working fully :)

-daz


ok, I won't use "IDCANCEL" ;)


please, can some moderator edit my post and make it not soooooooo wide?


and... doesn't anybody know when this forum decides to create a second page???


Originally posted by n0On3
ok, I won't use "IDCANCEL" ;)
ignore what i said about that, was half asleep at work and not remembering that the "" are stripped before being passed to the plugin :confused:
(also it looks neater without the ""s for the predefined texts i think)

tested your file under 98 and 2k - crashed under 98 :cry:

found the problem (was only related to silent installers!) so new none crashing version is attached ;)

-daz

ps issue is that with the silent installer it does not have a window title and so my code for that was incorrectly handling a "" for the caption (so it was the second messagebox crashing ;)) - i just can't code at times :D

I currently know nothing about win32 programming; you obviously must know quite a bit!

Good work!!

-Stu :)


Archive: MessageBox with more buttons


Originally posted by Afrow UK
you obviously must know quite a bit!
enough to get by with ;)

is mainly from playing around with things (all self taught though i wonder why at times :weird: ) that i've learnt win32 and even then i still have to research things / spend hours working out why it won't work but that's the same with anything really

-daz

[edit]
p.s. starts a second page here ;) @ n0On3
[/edit]

That's the way I get taught.
I know a few basic languages inside out by making the same program for my game in the different languages.
My programs basically read through a Quake2 log file getting the number of kills the entered name has done, how many deaths etc for specific weapons.

So far I've done it in Basic, QuickBasic, Perl and C
I'm looking forward to getting MS Visual Studio but that will come once I have finised school.

-Stu


i remember basic ;) first language i learnt back on my old atari ste (one for the history books and i've still got it).

only do c now since it's straight forward, have dabbled a bit in c++ but not enough to be able to do it all the time.

learnt the basics of c at uni and then win32 for my final project (a little editor and development thing for some DOS tools from the first year).

still developing the thing so that i can have a MDI text editor with customisable syntax highlighting of my source files. also worked on a thing to allow most windows and dialogs to 'dock' to the screen edge or the inside of MDI window eg Excel and that as linux does - makes positioning of windows easier to do but still have a few bugs with the code when it's closed down :( (but with recent stuff i've done here i think i may have the solution to the problems)

File reading is the fun stuff to do ;) windows hooks and subclassing are a real pain in comparison at times

-daz


hi, I used v0.98 beta 3 and still have the extra fourth button. I don't know how it got there :hang:

MessageBox::ShowMB_TOPMOST|MB_ICONQUESTION"Can'tMove,Copyinstead?"""

`Wecan'tmovethroughdifferentdrives.$\nButwecancopyanddeleteifnoerrors`
"Copy&&Delete""Copy"IDCANCEL

        

                

can you post a screen shot of what's appearing for you. also what OS are you using?

i will have a look at the code again in a bit but i can't think what could be going wrong :weird:

also did this version definitely fix the crash issue you were having in the earlier versions?

-daz


yes, it seems that the silent crash is gone :)

I attach a snap. Using Win98se


thanks for the picture and it's what i expected to see.

i managed to reproduce the problem and it's down to there being other values on the stack. the function will read in until it gets to the 4 button limit or there is nothing else on the stack hence what you get.

best option i can think of would be to add a control character on for the last button to ensure that the correct number of buttons are added
e.g. IDYES "blah" \eIDCANCEL

-daz


ah, so the problem is the stack...

do all plugins read parameters from stack?


yep, that's how they are passed for the plugin to get them. the issue with this plugin is that it takes variable parameters unlike most other plugins which accept a fixed number of parameters - hence the problem with reading what is available.

so the options are:
* a control flag on the last button
* assuming that if the stack parameter converts to a number to stop
* to control the number it expects (as in older versions)
* ensure the stack is clear before using the function

personally i think the first option is the easiest to use. didn't have enough time to make the above alteration last night, will be up by tomorrow.

-daz


You can do what the author of UnTGZ has done. He forced an extra stack push of "--" for inputs of variant sizes. It's the most elegant and simple way in my opinion. Forcing a flag on the last button might cause the user to delete it when editing or move it around when moving the buttons.

BTW, nsisdt uses the $0 variable :p


yeah the flag option has it's issues ;)
i'll have a look at what you've mentioned, thanks.

-daz


Can somebody help me out on this one. Here is the code I'm using:
messagebox::show "MB_ICONQUESTION" "" "" "$(TEXT_INSTCLIENT_MSG)" "$(TEXT_YES_MSG)" "$(TEXT_NO_MSG)"
I keep getting a third button like what is described above. I've tried the possible fixes except I can't figure out how to clear the stack to make the third button go away. I tried the control flag "\e$(TEXT_NO_MSG)" but then it just shows up in the buttons text. It also looks like the last option is one he was talking about putting back in but never did. Is there a newer version of this available or can somebody show me a workaround?


and I'm upping this topic because I think you should explain in your txt what is the id of an icon group


I have this code :


messagebox::show MB_ICONEXCLAMATION|MB_ICONHAND|MB_TOPMOST "$(question_hercules)" \
"another_software.exe,103" \
"$(messagebox_hercules)" $(yes) $(no)


and I didn't find the good value for "103"

resource hacker gave me the good values...

say it in your help file ;)


see ya and thx for your great plugin dro ;)

hello

I have this messagebox :


        messagebox::show MB_YESNO|MB_ICONEXCLAMATION|MB_TOPMOST "$(question_hercules)" \
"0,103" \
"$(messagebox_hercules)$\n" "$(yes)"

Pop $0
StrCmp $0 "1" yes
StrCmp $0 "2" no



But I have no sound when it appears
I'd like that a window "question" sound comes...

How can I do ?


thx for your answers :D

point 1: yeah, i agree on that. i also really need to just better document the plugin (as well as finding the source code for it on my old machine otherwise it's re-write time which in some ways could be a good thing i think :) and since there's a decent changelog in the zip i can re-work things if needed that way)

point 2: not sure to be honest, only thing i can think of is that you don't have a sound assigned to that system action (you'd need to check in the sound properties dialog)

-daz


are saying that this code is giving you a sound ?


i've just looked through some info on msdn and the MessageBeep(..) needs to be called. as a work around you can use the system plugin to manually do this.

i think i will just do a complete re-code of the plugin and i'm noting down to have sound support in there as well (for some of my Winamp plugins i need to alter a standard messagebox so i intend to make a general core which will work for them and as a nsis plugin for this)

just as i was about to post i did a quick system scan and i've found what looks like the source code for 0.98beta (first one i believe) so i'll do a bit more and see what else i can find since if i can get 0.98b3 that'll make my life easier)

-daz


yeah :D

this is cool

I'm waiting for it ;)

"bon courage" like we say in France ;) see ya :D


Hey DrO,
This might be a moot point if you are still planning to re-write, but I thought I'd mention it:

In your latest reslease (v0.98 beta 3), I still get a crash with the silent install.

To recreate, just run the file messagebox_s.exe included with the package. The crash occurs on the message box that reads "And for the special options"

I've attached a screenshot of the message box that generates the error. i also noticed that the "no" button should be named "m12if you can!"

Here's the text of the error:
The application, , generated an application error The error occurred on 07/11/2005 @ 07:54:13.718 The exception generated was c00000fd at address 100023B4 (<nosymbols>)

This is nothing urgent--just letting you know.
Thanks! :D


btw, nsis (english translation) officially uses "OK" and not "Ok", like that messagebox plugin (IDOK)


Hello DrO,

I am using your MessageBox plugin v0.98 beta 3.

I found two bugs:

1. when I use you plugin in a section twice without pop $0 between them, I get three buttons in the second messagebox. Here an example script:

-------------------------
OutFile "MessageBoxTest.exe"

; Installer sections
Section "-Installation actions" SecInstallation

messagebox::show MB_ICONINFORMATION|MB_DEFBUTTON1 "" "" "test" "Download Now" "Download Later"
; Pop $0 ; without this the next messagebox will have three buttons although only two are defined!!!

messagebox::show MB_ICONINFORMATION|MB_DEFBUTTON1 "" "" "test2" "Download Now" "Download Later"
Pop $0
StrCmp $0 "1" 0 readyTest ; pressed "Download Now"
ExecShell "open" "http://google.com/"
readyTest:

SectionEnd
-----------------------------

2. When I use your plugin in the .onInit function my installer always crashes. Here an example script:

-----------------------------
OutFile "MessageBoxTest.exe"

Section

SectionEnd

Function .onInit

messagebox::show MB_ICONINFORMATION|MB_DEFBUTTON1 "" "" "test" "Download Now" "Download Later"

messagebox::show MB_ICONHAND|MB_DEFBUTTON2 "" "" "and for the special options...$\n" "IDYES" "m12if you can!"

ClearErrors
FunctionEnd
-----------------------------

Could you help me with this bugs or do I have bugs in my scripts.
Thanks in advance and regards


I too am also experiencing this problem :(


because the plugin uses a variable parameter list you need to ensure that the stack is in a 'clean' state otherwise it will start pulling more than it should do (as you've come across). there was a post a few up by kichik about using a terminating parameter to indicate the end of the params.

as for the crash, i've managed to find the source code for 0.98 beta 1. i'm not sure where the beta 3 code is (could be on my old dev machine still...) i'll see if i can at least get the code working again and fix up some of the issues that i'd fixed from b1 to b3 and hopefully the issue you're having as well

-daz


How do I apply what Kichik mentioned a few post up? I am not sure although I tried pushing before and after this plugin and failed to work around it :(

Also, if you do plan on re-writing the code can you possibly add in support for jumps much like how MessageBox Handles them now?

e.g.messagebox::show"""Title""""Body"'"B_A"+12''"B_B"-12''"B_D".DONE'

I find the idea of $Pop and $StrCmp a bit cumbersome... Do you think you can add in support for jumps right pass the buttons somehow (all on the same line)?

Thank you DrO, I find the plugin very promising. Thank you again!

I found this link (http://forums.winamp.com/showthread....212#post935212) in the forums and tried out what Virtlink said. It seems to work as advertised...

LoopAgain:

Pop$R9
IfErrorsDoneLoopAgain
Done
:

the post by kichik was a suggestion on how the plugin could be fixed to handle the multiple parameters better.

i've been out of the loop on any real nsis coding for a while so i'm not sure if plugins are able to do what you're asking for with the jumps so i can't say. the other option is to have a quick macro in place to wrap things up for such a case (is something i'd need to look into to see if it's viable or not, etc)

Do you think you can add in support for jumps right pass the buttons somehow
not quite sure what you mean by that

-daz

i've managed to get the 0.98 beta 1 code compiling on my machine here at work and that example script doesn't crash for me but beta 3 does so i broke something with beta 3.

i've just added in /end needing to be on the end of a call to the plugin's function which fixes all of the pop fun since i can now at least only process what's needed and not anything else (will have to make sure it's working 100% though before i do anything else with it).

because of the state of the code i'm going to ditch a 1.0 and effectively re-code a fair chunk of it to aim towards a 2.0 since i also want to have the ability to have a checkbox on the bottom of the messagebox for setting as a default action type of thing.

it's going to take a few days for me to get upto speed with the code again but should have at least a fixed working build by the middle of the week :)

-daz


What I meant was instead of...

messagebox::show"""Title""""Body""B_A""B_B""B_D"

pop$0
StrCmp
$01+12
StrCmp
$02-12
StrCmp
$03.DONE
Something a bit more like this...
messagebox::show"""Title""""Body"`"B_A"+12``"B_B"-12``"B_D".DONE`

Just keeping it on one line like the traditional MessageBox instead of Popping and StrCmping just to Goto. Just an idea if you're really going to rewrite the code... Thanks Dr0!

I have a problem I am not too sure how to get passed. It involves nesting a variable within a temporary !define inside a !macro. Basically, I am trying to create a macro in which I would be able to use relative jumps a bit easier to get around...
PHP Code:


!macromessageboxTITLEBODYB1X1B2X2B3X3B4X4
Pop$R9
#CleartheStack...
IfErrors0-1
messagebox
::show"""${TITLE}""""${BODY}""${B1}""${B2}""${B3}""${B4}"
Pop$1
IntOp
$2$2+1
StrCmp
$1$2${X$2}-1
!macroend
In theory, the above will jump forward perfectly whereas jumping back would require I add on +5. This way though insures the jumps are predictable as where the following leads to a lot of math for relative jumps...
!macromessageboxTITLEBODYB1X1B2X2B3X3B4X4

Pop$R9
#CleartheStack...
IfErrors0-1
messagebox
::show"""${TITLE}""""${BODY}""${B1}""${B2}""${B3}""${B4}"
Pop$1
StrCmp
$11${X1}
StrCmp$12${X2}
StrCmp$13${X3}
StrCmp$14${X4}
!
macroend
Global jumps are no problem *but* I am really trying to get this to be relatively friendly. My problem in example 1 (line 6) is, I do not know how to nest the variable inside the define... I tried doubling the $, quotes, backslashes and am completely lost as to how to do it... Can anybody shed some light or some better code?

I might have mistakes in the code but am unable to test it out fully :(

Any help is greatly appreciated on this! Thank you!

how do you include a custom icon, where do you put that icon (dll file) for it to recognised


Anyone?
Dro

Please


sorry for the delay in reply, real world kept me from a proper browse of the forums yesterday.

the icon needs to be in a resource dll if i remember correctly (the example script uses shell32.dll from memory). i'll try and double-check the code over tonight (if need be i can look at modifying to make a custom build which allows you to specify just a .ico to be used (should be a relatively easy change from what i rememeber of the icon api in windows)

-daz


Thanks DrO for the reply,
No need to change it to a ico, (but if you want that would be great), I can easily make icon dll file, I just need to no where to place or extract the dll file too, so it works, I tried placing it in the system32 folder, but it didn't work I just got a blank space where a icon should have been.

That's just messing around with your default script, I'm not really bother about adding more button, it would just be nice if I could place a custom icon in it.

Plus I'm not really sure what to put in the script, whether you can specify a named custom icon as in "fred.dll,0" or does could you specify it as "$INSTDIR\fred.dll,0"

Thanks

Tony


you'd need to specify a full path, the reason the shell32 one works is because it's already on the system's default search path

-daz


ah ok I'll try it thanks mate :)


Nah I can't get it to work, I've placed a dll file in the system32 folder, the dll file has 2 icons in it so the full path and icon number (for icon 2) would be "$SYSDIR\fred.dll,2" right?

It didn't work

It frustrating :(


with that dll, open it up in resource hacker for example and look for a [icon group] value in the tree. check which icon group the icon you want to use is in and then use the id of that group. that works ok for me from what i can tell

-daz


Ah this is why it probably won't work tried opening it with res hacker as you suggested, but Res Hack says its not a win32 executable file I made the dll file with Axialis IconWorkshop

Bugger :(


use the attached dll for adding your icons into. it's a valid dll i built in msvc and i tested by manually adding an icon in with resource hacker and it worked for me

-daz


thank but that didnt work but it gave me an idea, I found a existing dll file it was a file called acctres.dll deleted all the crap out of it leaving two icon and replaced those with my icons

And it works

so thanks


Archive: MessageBox with more buttons


strange, not sure why it wouldn't have worked assuming the icon was fully added and then saved to the dll. as long as it works now then that's the main thing :)

-daz


I'm using LogicLib and I need a custom messagebox nested within some logic. However, this causes the stack to be unable to be in a clean state. I was wondering when their would be a fixed implemented for this? Reading back on this thread I saw that a /end switch was being tested.

Thanks!

EDIT: Also, with my testing, I've noticed that whenever I quit the installer, it seems to give a memory read violation whenever it tries to unload the messagebox dll.


Solution with extra buttons
Hi,
Am I right that there is no solution for extra buttons still except for manually clearing stack? This is not elegant solution as the stack could keep some values from outer procedure calls.


Hi,

I have just tested the messagebox plugin v.098 beta 3 and I found another small bug inside.
I am using Modern UI, and just after the Welcome page, and before the License page agreement shows, I insert a function to display a simple messagebox with a specific title and only a "OK" button (with the plugin).
When clicking, on "Next" (in the Welcome page), then this pops up the messagebox correctly. Then, when I click back (to return to the welcome page), and then "Next" again, this pops up the same messagebox with my "OK" button but also an additional "1" button !!!
Repeating the process another time, will display the messagebox with "2" if I have clicked on "1", etc...

Below is the essential part of the code:

!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowLicenseInfo
!insertmacro MUI_PAGE_LICENSE "myLicense.txt"
.
.
.
Function ShowLicenseInfo
messagebox::show MB_TOPMOST "my specific title" \
"" "\
PLEASE NOTE: this is some additional information" \
IDOK
FunctionEnd

Is there something I have done wrong ? Or is it a problem from the plugin ?


Originally posted by lilisbbc
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowLicenseInfo
!insertmacro MUI_PAGE_LICENSE "myLicense.txt"
.
.
.
Function ShowLicenseInfo
messagebox::show MB_TOPMOST "my specific title" \
"" "\
PLEASE NOTE: this is some additional information" \
IDOK
FunctionEnd

Is there something I have done wrong ? Or is it a problem from the plugin ? [/B]
Okay, after some investigations, it appears that simply adding Pop $0 at the end of the function solves the problem.
Don't really know why, but well, as long as it works...
Thanks Dr0 for the plugin ! :-)

The reason that happens is that this plugin requires that the stack be empty. The first four elements on the stack will be used as the messagebox buttons.


Does anyone have any idea why a message box with this plugin might not work in certain instances? As the developer of our installer, I have not experienced any issues with it, nor have others who've tested it, but one tester has. I'm using the messagebox::show in 3 separate places, and for him, when he clicks on the button in the custom pages to display these message boxes, nothing happens. I've created this simple script, which duplicates the problem on his machine, but works fine for others and myself. He can see the "normal" message box, but not the MB via the plugin. Any thoughts?


One thing in that script is that you've got InitPluginsDir after MUI_INSTALLOPTIONS_EXTRACT and it should be before.
What happens if you put a normal MessageBox before the plugin MessageBox. Does that get displayed?

-Stu


I updated the InitPluginsDir, and that didn't seem to make a difference (though I will update that in my real code anyway, thanks for pointing it out). I also inserted a normal message box to confirm that we're getting to that place in the code, and it appears. The very next line, the messagebox::show, still doesn't work on his (still does on mine).

On a side note, we're both using our standard company issue workstations with Windows XP Pro SP2.


Sorry, meant to update attachment with your suggestions:


Any ideas for us to try? Has anyone else ran into this before?


at the moment no since i don't have the source code on my machine here (i think my attempt at a new version was on the machine at work) so i'll have to track that down tomorrow and see what i can make up to test the thing out). i will add that it appears to work fine for me (though i can't test on an XP install until later). not too sure why it'd fail to display as such if it's working on all other installs (unless the test machine where it fails has something else installed on it which could be breaking the OS hacks)

-daz


Found an odd issue with messagebox.

If I have message text with a ':' in it, sometimes the text after the ':' isnt shown, sometimes it is.

Any idea why this might be?


I've tested the latest version (v.0.98 beta 3) of your plugin.

messagebox::show MB_DEFBUTTON2|MB_TOPMOST "title" "" "Body" "Button1" IDNO

If i see this messagebox and press Escape a sound is played and the messagebox disappears.

messagebox::show MB_DEFBUTTON2|MB_TOPMOST "title" "" "Body" "Button1" "Button2"

If i press Escape on a messagebox without standard buttons the process uses 99 procent cpu resources and stops responding.

Any ideas?

- flizebogen


i tried looking into that issue but there's a quirk with the overrides i do and the OS. i can't remember if i managed to resolve the issue or not since it was something i was trying to work on during my lunch breaks at work and i don't have that code to hand. from what i remember if there's no proper close button (with the [x] in the top right being greyed out) will cause the lock up

-daz


I added a Close button. Like you said this prevented the crash.

Unfortunately i have an other problem:

Below is the output of the example from the latest version. If i execute it on a terminal server within a rdp session. No problems on a workstation.

The Plugin return not the number of the chosen button, it don't display at all and gives this faulty output

Any ideas?

C:\DOKUME~1\ab\LOKALE~1\Temp\3\nsu10.tmp\messagebox.dll
messagebox call 1 returned... MB_DEFBUTTON4|MB_TOPMOST
C:\DOKUME~1\ab\LOKALE~1\Temp\3\nsu10.tmp\messagebox.dll
messagebox call 2 returned... MB_SETFOREGROUND|MB_ICONHAND|MB_DEFBUTTON3
C:\DOKUME~1\ab\LOKALE~1\Temp\3\nsu10.tmp\messagebox.dll
messagebox call 3 returned... MB_ICONHAND|MB_DEFBUTTON2
C:\DOKUME~1\ab\LOKALE~1\Temp\3\nsu10.tmp\messagebox.dll
messagebox call 4 returned... MB_ICONEXCLAMATION|MB_ICONHAND|MB_TOPMOST|MB_DEFBUTTON2|MB_RIGHT
C:\DOKUME~1\ab\LOKALE~1\Temp\3\nsu10.tmp\messagebox.dll
Completed


This is a great plugin.

I cant seem to work out why, but every time i try to show a custom messagebox, it adds an extra button on to the end that says, "success"

I can't seem to make it not show.
Any ideas?

Nevermind, worked it out, had to Pop $0 before it
Cheers


Great work!!!
I'm using it in a current project of mine. Pressing the escape button when the message box is shown (2 custom buttons in my case) hangs the installer, with the CPU going to 60%...a known issue?

Thanks in advance,
Hrish


It's a pity that messagebox plugin is no longer developed, because it's great. I encountered only one bug but it's a nasty one: messagebox crashes (it freezes, actually) when Esc is pressed. Seems that it goes into some infinite loop (cpu load is 99%).


Just realized that the previous reply said the same thing. :o


Hey guys,

I'm pretty new to all NSIS-stuff, but I truly enjoy the capabilities of the system! :)

Anyway, let's get straight to the point:
1. Awesome plugin, but:
2. Could you, DrO, enable support for .ico-files?

Since I'm only using a single icon for kinda "Xmas welcome-screen", I'd prefer to not generate a DLL, but instead use such an .ico-file.

Thanks in advance,
Martin.. :)


Here's how I do it:

> You need Resource Hacker (http://www.angusj.com/resourcehacker/).


> Put the .ico in the folder where your script is and create a cmd file, e.g. header.cmd. Here's what you should put in it:

@echo off
rem 'Inject' the icons into the header with ResHacker:
"%ProgramFiles%\Resource Hacker\ResHacker.exe" -add "%TEMP%\exehead.tmp", "%TEMP%\exehead.tmp", "%~dps0IconName.ico", icongroup,104,1033
rem If you want to compress the header with upx:
"%ProgramFiles%\UPX\upx.exe" --best "%TEMP%\exehead.tmp"

Icon group 104 will contain icons from your ico file. Add more lines for more icon groups.


> Put this at the end of your script:

!packhdr "$%TEMP%\exehead.tmp" "header.cmd"


> And finally, the MessageBox example:

Messagebox::show MB_TOPMOST "Caption" "0,104" "Text" "Button 1" "Button 2" "Button 3" "Button 4"
# it uses the 1st icon from icongroup 104


First of all, thank you very much for your guide.

Unfortunately, the sad thing about this solution is the fact that Resource Hacker doesn't work under Vista (at least not x64, which is the one I run).. :(


You could try XN Resource Editor or eXeScope as alternatives. I don't know if they'll work on Vista x64 but even if they do, the problem is they don't support command line operation, at least not to my knowledge. eXeScope documentation says it supports some kind of batch processing based on log files but I haven't tried the program. But if you do find a resource editor that works on your system, what you can do is:

> Instead of that header.cmd, create two new ones:

header1.cmd:
copy "%TEMP%\exehead.tmp" C:\tmphead.tmp

header2.cmd:
copy C:\tmphead.tmp "%TEMP%\exehead.tmp" /Y

> Compile the script with:
!packhdr "$%TEMP%\exehead.tmp" "header1.cmd"

> Edit C:\tmphead.tmp with a resource editor

> Compile again with header2.cmd"


Or settle for a regular messagebox and use MB_USERICON... :)


Originally posted by aerDNA
(...)
Useful suggestions
(...)

Or settle for a regular messagebox and use MB_USERICON... :)
Uh! That MB_USERICON shows the same like I did (as a workaround) while waiting for an answer from you (which means I set the app's icon to a different one):
MessageBox::show styles "Ho! Ho! Ho!" "0,103" "   Merry Xmas$\r$\n   to all you geeks! :)" IDOK

Though, following your way I can't set my own message box-title.. :(

And I used "0,103" instead of your suggested "0,104" (AFAIR the Wiki told me that "3") - maybe you could explain this to me? :)

Or settle for a regular messagebox and use MB_USERICON...
Being sleepy makes me slip. You don't have to settle for a regular mb, you can also use the installer icon with the plugin, exactly the way you did. Icon group 103 always contains the installer icon. 104 was the one I suggested to create for adding an extra, which is unnecessary if you're willing to use the same icon for the installer and the messagebox.
Btw, there's a way to change the title even when using the regular mb. But you don't need that now, or do you?

Originally posted by aerDNA
Being sleepy makes me slip. You don't have to settle for a regular mb, you can also use the installer icon with the plugin, exactly the way you did.
This sounds somewhat familiar for me.. ;)

Originally posted by aerDNA
Icon group 103 always contains the installer icon. 104 was the one I suggested to create for adding an extra, which is unnecessary if you're willing to use the same icon for the installer and the messagebox.
Thanks for clarifying this for me! :)

Originally posted by aerDNA
Btw, there's a way to change the title even when using the regular mb. But you don't need that now, or do you?
I always want to learn more, so if you like, please go on! :)

Here, I've made a script that shows how to change a single MB's caption. My method may not be very elegant but it works, and it allows you to create an animated title. This doesn't really belong to this thread any more, I hope the moderators don't mind...


OutFile "XMAS.exe"
;Icon "xmas.ico"
XPStyle On

!include "WinMessages.nsh"
!define InstCaption "Merry XMAS Wisher 1.0 beta"
!define MBCaption1 " Merry XMAS, human!"
!define MBCaption2 " Live long and prosper!"
Caption "${InstCaption}"

Function .onInit
# If you don't want the blinking caption on the taskbar as well, use .onGUIInit

InitPluginsDir
WriteUninstaller $PLUGINSDIR\MBCaption.exe
MessageBox MB_OK|MB_ICONINFORMATION|MB_TOPMOST "This MessageBox has a normal title."
Exec "$PLUGINSDIR\MBCaption.exe"
MessageBox MB_OK|MB_USERICON|MB_TOPMOST "But this one has a festive title!"
MessageBox MB_OK|MB_ICONINFORMATION|MB_TOPMOST "This is the normal title again."
Abort

FunctionEnd

Section "Blank"
SectionEnd


Function un.onInit

FindWindow $0 "" "${InstCaption}" "" ""
IsWindow $0 0 -1

CaptionLoop:
SendMessage $0 ${WM_SETTEXT} "0" "STR:${MBCaption1}"
Sleep 800
SendMessage $0 ${WM_SETTEXT} "0" "STR:"
Sleep 400
SendMessage $0 ${WM_SETTEXT} "0" "STR:${MBCaption2}"
Sleep 800
SendMessage $0 ${WM_SETTEXT} "0" "STR:"
Sleep 400
FindWindow $1 "" "${InstCaption}" "" ""
IsWindow $1 0 CaptionLoop

Abort
FunctionEnd

Section "un.Blank"
SectionEnd

Thank you very much! :)
And merry Xmas to you and your family! ;)


Appendix:
The above script is missing one thing: RequestExecutionLevel User. Without it, MBCaption.exe should (re)trigger UAC (Utterly Annoying Component :down: ).
And as I said, the method is not very elegant. When you don't really need a flashing caption, the proper way to go would be to create a custom MB through Win API. E.g.:

!include "${NSISDIR}\Examples\System\System.nsh"
!define STYLE ${MB_OK}|${MB_ICONINFORMATION}|${MB_TOPMOST}
System::Call 'User32::MessageBox(i $HWNDPARENT, t "The text", t "A caption", i ${STYLE}) i.'

To use a custom icon (including the installer icon), you need MessageBoxIndirect, but it accepts only module handles. Handles returned by LoadImage don't work, that must be why MessageBox plugin can't support ico files.

Again, thanks a lot for pointing this out! :)


Has anyone ever converted the messagebox plugin into Unicode? If not I would be interested in trying to do so if the source is available somewhere.


nope it's not been done since the source was lost. i did begin to reimplement it but my winamp commitments have killed that from happening. but maybe one day i'll get around to it...

-daz


have just removed the downloads for this and the wiki page relating to the plug-in has been removed.

i'm never going to get around to re-creating it to make it compatible with current OSes since it's been almost 6 years and i've never found the time.

is also better to remove it to prevent other users trying to use it and then wonder why they have issues - doesn't help it was compiled in a manner which turns out to not be DEP compatible *doh*

:lock:

-daz