Even easier paging system, no more Abort and Quit from custom pages creator functions, NSIS does it all!

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1636 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-11-09 12:50:00 +00:00
parent 35b45db225
commit 297e981d32
17 changed files with 123 additions and 335 deletions

View file

@ -9,7 +9,7 @@ OutFile "StartMenu Test.exe"
XPStyle on
Page directory
DirText "This installer will create some shortcuts to MakeNSIS in the start menu.$\nFor this it needs NSIS's folder path." \
DirText "This installer will create some shortcuts to MakeNSIS in the start menu.$\nFor this it needs NSIS's path." \
"Please specify the path in which you have installed NSIS:"
InstallDir "${NSISDIR}"
Function .onVerifyInstDir
@ -21,7 +21,7 @@ Page custom StartMenuGroupSelect
Function StartMenuGroupSelect
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:StartMenu.dll test Setup: Start Menu Folder"
StartMenu::Select /autoadd "StartMenu.dll test"
StartMenu::Select /autoadd /lastused $R0 "StartMenu.dll test"
Pop $R1
StrCpy $R2 $R1 5
@ -29,11 +29,8 @@ Function StartMenuGroupSelect
; error
MessageBox MB_OK $R1
Return
StrCmp $R1 "cancel" 0 +2
Quit
StrCmp $R1 "back" 0 +2
Abort
StrCpy $R0 $R1 ; got the dir
StrCpy $R0 $R1 ; got the dir, or cancel, but if it's cancel NSIS will exit and
; then we shouldn't care about the value of $R0
FunctionEnd
Page instfiles

View file

@ -5,10 +5,11 @@ To show the dialog use the Select function. This function has one required param
which is the program group default name, and some more optional parameters:
/autoadd - automatically adds the program name to the selected folder
/noicon - doesn't show the icon in the top left corner
/text [please select...] - sets the top text to something else than "Select
the Start Menu folder in which..."
/cancelconfirm [text] [caption] [flags] - displays a cancel confirmation
message box when the user click on the cancel button
/text [please select...] - sets the top text to something else than
"Select the Start Menu folder in which..."
/lastused [folder] - sets the edit box to a specific value folder.
Use this to make this plug-in remember the last
folder selected by the user
The function pushes the folder selection back to the stack. It does not push the
full path but only the selected sub-folder. It's up to you to decide if to put

View file

@ -1,7 +1,9 @@
#include <windows.h>
#include "exdll.h"
#include "../exdll/exdll.h"
#include "resource.h"
#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
HINSTANCE g_hInstance;
HWND hwParent;
@ -15,10 +17,7 @@ HWND hwDirList;
char buf[MAX_PATH];
char text[1024];
char progname[1024];
char cancelconfirm[1024];
char cancelconfirmcaption[1024];
unsigned int cancelconfirmflags = 0;
char lastused[1024];
int autoadd = 0;
int g_done = 0;
@ -71,24 +70,9 @@ void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variab
{
autoadd = 1;
}
else if (!lstrcmpi(buf+1, "cancelconfirm"))
else if (!lstrcmpi(buf+1, "lastused"))
{
static TableEntry MBFlagTable[] = {
{ "MB_ICONEXCLAMATION", MB_ICONEXCLAMATION },
{ "MB_ICONINFORMATION", MB_ICONINFORMATION },
{ "MB_ICONQUESTION", MB_ICONQUESTION },
{ "MB_ICONSTOP", MB_ICONSTOP },
{ "MB_TOPMOST", MB_TOPMOST },
{ "MB_SETFOREGROUND", MB_SETFOREGROUND },
{ "MB_RIGHT", MB_RIGHT },
{ "MB_DEFBUTTON1", MB_DEFBUTTON1 },
{ "MB_DEFBUTTON2", MB_DEFBUTTON2 },
{ NULL, 0 }
};
popstring(cancelconfirm);
popstring(cancelconfirmcaption);
popstring(buf);
cancelconfirmflags = LookupTokens(MBFlagTable, buf);
popstring(lastused);
}
if (popstring(buf))
*buf = 0;
@ -131,15 +115,9 @@ void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variab
static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_CLOSE)
if (message == WM_NOTIFY_OUTER_NEXT)
{
message = WM_COMMAND;
wParam = IDCANCEL;
}
if (message == WM_COMMAND && (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK || LOWORD(wParam) == 3))
{
PostMessage(hwStartMenuSelect,WM_USER+666,0,LOWORD(wParam));
return 0;
PostMessage(hwStartMenuSelect,WM_USER+666,wParam,0);
}
return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
}
@ -238,7 +216,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
temp_r.bottom - temp_r.top
);
SendMessage(hwLocation, WM_SETTEXT, 0, (LPARAM) progname);
SendMessage(hwLocation, WM_SETTEXT, 0, (LPARAM) (*lastused ? lastused : progname));
ProgressiveSetWindowPos(
hwDirList,
@ -268,20 +246,12 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
case WM_USER+666:
g_done = 1;
switch (lParam) {
case IDOK:
SendMessage(hwLocation, WM_GETTEXT, MAX_PATH, (LPARAM) buf);
pushstring(buf);
break;
case IDCANCEL:
if (*cancelconfirm && MessageBox(hwStartMenuSelect, cancelconfirm, cancelconfirmcaption, MB_YESNO|cancelconfirmflags) == IDNO)
g_done = 0;
else
pushstring("cancel");
break;
case 3:
pushstring("back");
break;
if (wParam == 0xD1E)
pushstring("cancel");
else
{
SendMessage(hwLocation, WM_GETTEXT, MAX_PATH, (LPARAM) buf);
pushstring(buf);
}
break;
}

View file

@ -101,7 +101,7 @@ SOURCE=.\StartMenu.c
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\ExDLL.h
SOURCE=..\ExDLL\exdll.h
# End Source File
# End Group
# Begin Group "Resource Files"

View file

@ -1,93 +0,0 @@
#ifndef _EXDLL_H_
#define _EXDLL_H_
// only include this file from one place in your DLL.
// (it is all static, if you use it in two places it will fail)
#define EXDLL_INIT() { \
g_stringsize=string_size; \
g_stacktop=stacktop; \
g_variables=variables; }
typedef struct _stack_t {
struct _stack_t *next;
char text[1]; // this should be the length of string_size
} stack_t;
static int g_stringsize;
static stack_t **g_stacktop;
static char *g_variables;
static int popstring(char *str); // 0 on success, 1 on empty stack
static void pushstring(char *str);
enum
{
INST_0, // $0
INST_1, // $1
INST_2, // $2
INST_3, // $3
INST_4, // $4
INST_5, // $5
INST_6, // $6
INST_7, // $7
INST_8, // $8
INST_9, // $9
INST_R0, // $R0
INST_R1, // $R1
INST_R2, // $R2
INST_R3, // $R3
INST_R4, // $R4
INST_R5, // $R5
INST_R6, // $R6
INST_R7, // $R7
INST_R8, // $R8
INST_R9, // $R9
INST_CMDLINE, // $CMDLINE
INST_INSTDIR, // $INSTDIR
INST_OUTDIR, // $OUTDIR
INST_EXEDIR, // $EXEDIR
INST_LANG, // $LANGUAGE
__INST_LAST
};
// utility functions (not required but often useful)
static int popstring(char *str)
{
stack_t *th;
if (!g_stacktop || !*g_stacktop) return 1;
th=(*g_stacktop);
lstrcpy(str,th->text);
*g_stacktop = th->next;
GlobalFree((HGLOBAL)th);
return 0;
}
static void pushstring(char *str)
{
stack_t *th;
if (!g_stacktop) return;
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
lstrcpyn(th->text,str,g_stringsize);
th->next=*g_stacktop;
*g_stacktop=th;
}
static char *getuservariable(int varnum)
{
if (varnum < 0 || varnum >= __INST_LAST) return NULL;
return g_variables+varnum*g_stringsize;
}
static void setuservariable(int varnum, char *var)
{
if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
lstrcpy(g_variables + varnum*g_stringsize, var);
}
#endif//_EXDLL_H_