write HWND and HWND2 entries to the INI with the control's HWND

no more weird calculations when there's a browse button


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4315 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2005-10-11 16:27:04 +00:00
parent 49179ea08d
commit d144639111
3 changed files with 36 additions and 16 deletions

View file

@ -156,6 +156,9 @@ struct FieldType {
int nParentIdx; // this is used to store original windowproc for LINK
HANDLE hImage; // this is used by image/icon field to save the handle to the image
int nField; // field number in INI file
char *pszHwndEntry; // "HWND" or "HWND2"
};
// initial buffer size. buffers will grow as required.
@ -482,6 +485,9 @@ int WINAPI ReadSettings(void) {
};
FieldType *pField = pFields + nIdx;
pField->nField = nCtrlIdx + 1;
pField->pszHwndEntry = "HWND";
wsprintf(szField, "Field %d", nCtrlIdx + 1);
pszAppName = szField;
@ -565,6 +571,8 @@ int WINAPI ReadSettings(void) {
pNewField->rect.bottom = pField->rect.bottom;
pNewField->rect.top = pField->rect.top;
pField->rect.right = pNewField->rect.left - 3;
pNewField->nField = nCtrlIdx + 1;
pNewField->pszHwndEntry = "HWND2";
nNumFields++;
nIdx++;
}
@ -1114,6 +1122,14 @@ int WINAPI createCfgDlg()
NULL
);
{
char szField[64];
char szHwnd[64];
wsprintf(szField, "Field %d", pField->nField);
wsprintf(szHwnd, "%d", hwCtrl);
WritePrivateProfileString(szField, pField->pszHwndEntry, szHwnd, pszFilename);
}
if (hwCtrl) {
// Sets the font of IO window to be the same as the main window
mySendMessage(hwCtrl, WM_SETFONT, (WPARAM)hFont, TRUE);

View file

@ -581,6 +581,14 @@ used.</td>
specify the foreground color of the text. Format: 0xBBRRGG
(hexadecimal).</td>
</tr>
<tr>
<td class="lefttable"><strong>HWND<br>HWND2</strong></td>
<td class="lefttable"><em>(output)</em></td>
<td class="righttable">After initDialog returns, this will contain
the HWND of the control created by this field. It can be used
instead of FindWindow and GetDlgItem. HWND2 contains the HWND of
an additional control, such as the browse button.</td>
</tr>
</table>
</div>
<h2>How to use</h2>
@ -801,11 +809,9 @@ dialogs, you should use the initDialog and show functions.
initDialog creates the dialog in memory, but does not show it.
After calling initDialog, you can set the fonts and colors, and
call show to show the dialog. initDialog pushes the HWND of the
custom dialog to the stack. To get the HWND of the controls
use:</p>
<pre>
GetDlgItem (output var) (hwnd of the custom dialog) (1200 + Field number - 1)
</pre>
custom dialog to the stack. Control HWND's are available for each
control in the HWND entry of the corresponding field in the INI
file.</p>
<p>Example of using a custom font:</p>
<pre>
Function FunctionName ;FunctionName defined with Page command
@ -819,7 +825,7 @@ Function FunctionName ;FunctionName defined with Page command
InstallOptions::initDialog /NOUNLOAD $PLUGINSDIR\test.ini
Pop $R0
GetDlgItem $R1 $R0 1200 ;1200 + Field number - 1
ReadINIStr $R1 $PLUGINSDIR\test.ini "Field 1" "HWND"
;$R1 contains the HWND of the first field
CreateFont $R2 "Tahoma" 10 700

View file

@ -3,8 +3,6 @@
!include WinMessages.nsh
Var hwnd ; Window handle of the custom page
; The name of the installer
Name "InstallOptions Test"
@ -34,7 +32,7 @@ Function ShowCustom
WriteINIStr "$PLUGINSDIR\test.ini" "Settings" "RTL" "1"
InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\test.ini"
; In this mode InstallOptions returns the window handle so we can use it
Pop $hwnd
Pop $0
; Now show the dialog and wait for it to finish
InstallOptions::show
; Finally fetch the InstallOptions status value (we don't care what it is though)
@ -56,9 +54,9 @@ Function LeaveCustom
supportx:
; Make the FileRequest field depend on the first checkbox
ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 2" "State"
GetDlgItem $1 $hwnd 1204 ; PathRequest control (1200 + field 5 - 1)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 5" "HWND"
EnableWindow $1 $0
GetDlgItem $1 $hwnd 1205 ; ... button (the following control)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 5" "HWND2"
EnableWindow $1 $0
; Add the disabled flag too so when we return to this page it's disabled again
StrCmp $0 0 0 +3
@ -71,11 +69,11 @@ supportx:
clearbtn:
; Clear all text fields
GetDlgItem $1 $hwnd 1204 ; PathRequest control (1200 + field 5 - 1)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 5" "HWND"
SendMessage $1 ${WM_SETTEXT} 0 "STR:"
GetDlgItem $1 $hwnd 1206 ; DirRequest control (1200 + field 6 - 1 + 1 browse button)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 6" "HWND"
SendMessage $1 ${WM_SETTEXT} 0 "STR:"
GetDlgItem $1 $hwnd 1209 ; Multiline control (1200 + field 8 - 1 + 2 browse buttons)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 8" "HWND"
SendMessage $1 ${WM_SETTEXT} 0 "STR:"
Abort ; Return to the page
@ -86,9 +84,9 @@ droplist:
StrCpy $0 0
Goto +2
StrCpy $0 1
GetDlgItem $1 $hwnd 1206 ; DirRequest control (1200 + field 6 - 1 + 1 browse button)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 6" "HWND"
EnableWindow $1 $0
GetDlgItem $1 $hwnd 1207 ; ... button (the following control)
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field 6" "HWND2"
EnableWindow $1 $0
; Add the disabled flag too so when we return to this page it's disabled again
StrCmp $0 0 0 +3