简体   繁体   English

在NSIS中,如何在使用nsDialogs :: Create 1018时设置对话框的大小?

[英]In NSIS, How to set the size of the dialog box when using nsDialogs::Create 1018?

In Nsis, I'm using: 在Nsis,我正在使用:

 ...
 nsDialogs::Create 1018
 Pop $0

 nsDialogs::Show
 ...

But the size of the dialog box doesn't fit my needs. 但是对话框的大小不符合我的需要。 How can I specify a length for x and y to this dialog ? 如何为此对话框指定x和y的长度?

If you want to resize everything it is probably better to use Resource Hacker and ChangeUI but you can do it at runtime: 如果你想调整所有内容,最好使用Resource Hacker和ChangeUI但你可以在运行时完成:

!include nsDialogs.nsh

Function mypage
System::Call 'user32::SetWindowPos(i$hwndparent,i,i,i,i 640,i 480,i 0x16)' ; Resize outer dialog
nsDialogs::Create 1018
Pop $0
System::Call 'user32::MoveWindow(i$0,i0,i0,i 600,i 200,i0)' ; Resize inner (nsDialogs) page

${NSD_CreateLabel} 0 10u 100% 10u "Hello, welcome to nsDialogs!"
Pop $0
SetCtlColors $0 0xffffff 0xff2255

nsDialogs::Show
FunctionEnd

page custom mypage

My dialog isn't tall enough for all the controls I am putting in. 我的对话框不够高,不适合我投入的所有控件。

I tried your two Windows API's and while they worked, the client area of the install overlapped and covered up the OK/Cancel buttons. 我尝试了两个Windows API,当它们工作时,安装的客户区重叠并覆盖了确定/取消按钮。

I eventually worked out "use resource hacker and ChangeUI". 我最终制定了“使用资源黑客和ChangeUI”。 It was much harder than I thought it would be. 这比我想象的要困难得多。 So, here is a more detailed how-to. 所以,这里有一个更详细的操作方法。 I was deeply entrenched with nsDialogs NOT ModernUI. 我完全没有使用nsDialogs而不是ModernUI。 So this is a how-to for nsDialogs resizing of a window created the same as in the examples. 因此,这是nsDialogs调整窗口大小的方法,其创建方式与示例相同。 ModernUI is covered above. 上面介绍了ModernUI。

nsDialogs::Create 1018 nsDialogs ::创建1018

  1. Get ResourceHacker from Angus: http://www.angusj.com/resourcehacker/ 从Angus获取ResourceHacker: http//www.angusj.com/resourcehacker/
  2. Go to your NSIS Contrib folder. 转到NSIS Contrib文件夹。 C:\\Program Files (x86)\\NSIS\\Contrib\\UIs and copy default.exe to the same folder as your NSI script file. C:\\ Program Files(x86)\\ NSIS \\ Contrib \\ UIs并将default.exe复制到与NSI脚本文件相同的文件夹中。
  3. Rename your local copy of default.exe to tall_UI.exe. 将default.exe的本地副本重命名为tall_UI.exe。
  4. Open ResourceHacker, drag tall_UI.exe into the window. 打开ResourceHacker,将tall_UI.exe拖到窗口中。
  5. Use the treeView to dig down into resource 105 and click on 1033. When you click on 1033, it shows a preview. 使用treeView深入查看资源105并单击1033.当您单击1033时,它会显示预览。
  6. What you have a is the code and the preview. 你有一个是代码和预览。 Take note of the first line of code... 记下第一行代码......

     105 DIALOGEX 0, 0, 280, 162 
  7. Now click on the top edge of the preview window and stretch it to make it taller. 现在单击预览窗口的顶部边缘并将其拉伸以使其更高。 Note that the final number in that line got bigger. 请注意,该行中的最终数字变得更大。 Notice how there is empty space at the bottom of the window now. 注意现在窗口底部是否有空白区域。
  8. There are four controls along the bottom edge of the dialog: a button, an invisible box and two more buttons. 对话框底部边缘有四个控件:一个按钮,一个不可见的框和另外两个按钮。 Drag all of these down near the bottom of the window. 将所有这些拖到窗口底部附近。 As you select each you will notice the red * marking which control is being modified in the code window. 当您选择每个时,您会注意到红色*标记在代码窗口中正在修改哪个控件。 Just get them close to where you want them. 让他们靠近你想要的地方。
  9. Move the horizontal divider line. 移动水平分隔线。 It's skinny and hard to move. 它很瘦,很难移动。
  10. You will want your buttons to all be in a straight row. 你会希望你的按钮都是直的。 To get them exact, move over to the code window and edit the 3rd number from the end of the line for each of the controls. 为了使它们准确,请转到代码窗口并从每行控件的行尾编辑第3个数字。 To apply these changes to the code window, click "Compile Script". 要将这些更改应用于代码窗口,请单击“编译脚本”。
  11. Click on the big gray box to select then use its bottom edge pip to stretch it to the desired height. 单击灰色大框以选择然后使用其底部边缘点将其拉伸到所需高度。
  12. Tweak the code or preview. 调整代码或预览。 Hit compile a lot. 命中编译很多。
  13. It's perfect, you like it. 它很完美,你喜欢它。 Hit compile one final time. 命中编译最后一次。
  14. Click "File" and "Save". 单击“文件”和“保存”。 It will save your Tall_UI.exe as well as make a copy called Tall_UI_original.exe. 它将保存您的Tall_UI.exe以及制作名为Tall_UI_original.exe的副本。
  15. In your NSIS script, you need to add a call to ChangeAll early on. 在NSIS脚本中,您需要尽早添加对ChangeAll的调用。

     ChangeUI all tall_UI.exe Page custom nsDialogsPage Function nsDialogsPage nsDialogs::Create 1018 Pop $Dialog ... 

That did it for me. 这样做对我来说。 You will do some trial and error, always hit commpile and save in ResourceHacker and then rebuild your NSI. 您将进行一些试验和错误,总是打开commpile并保存在ResourceHacker中,然后重建您的NSI。 You may note that your dialog is bigger or smaller than the preview shown in ResourceHacker. 您可能会注意到您的对话框大于或小于ResourceHacker中显示的预览。 That is because NSIS does scale your dialog based on font size, DPI... stuff like that. 那是因为NSIS会根据字体大小,DPI ......这样的东西来缩放对话框。 Try and retry till it looks good. 尝试重试直到看起来不错。

You will note that nsDialogs::Create 1018 matches the number in the 5th line of resource hacker: 您会注意到nsDialogs :: Create 1018匹配资源黑客第5行中的数字:

CONTROL "", 1018, STATIC, SS_BLACKRECT | WS_CHILD | WS_GROUP, 7, 7, 266, 160  

I did some testing after getting this demo together and the positioning and size of that 1018 resource does have an effect but I can't tell you why it isn't black. 我把这个演示放在一起后做了一些测试,1018资源的定位和大小确实有效,但我不能告诉你为什么它不是黑色的。

Full code of my demo is below showing. 我的演示的完整代码如下所示。

#Created with NSIS version 2.46 downloaded from SourceForge.net
#Based on "Adding Controls" section of user docs
# http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html#step-add

!include nsDialogs.nsh

Name "Launchpad"
OutFile "Master Installer.exe"
BrandingText " "
Caption "Launchpad"
RequestExecutionLevel admin
SetFont "Arial" 10
VIProductVersion "2.5.0.0"

Var Dialog
Var Button

ChangeUI all tall_UI.exe
Page custom nsDialogsPage

Function nsDialogsPage
    nsDialogs::Create 1018 
    Pop $Dialog

    # It will create a new dialog in the page and return its HWND on the stack. The result must be popped from the stack to prevent stack corruption. If the result is error, the dialog couldn't be created.
    ${If} $Dialog == error
    Abort
    ${EndIf}

    # ${NSD_Create*} x y width height text

    ## Going to use $0 for y of each new control.
    StrCpy $0 "29"

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product Manual"
    Pop $Button
    ${NSD_OnClick} $Button Manual_Install_Clicked
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product 1 Installer"
    Pop $Button
    ${NSD_OnClick} $Button Product1_Install_Clicked
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product 2 Installer"
    Pop $Button
    ## ${NSD_OnClick} ...
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product 3 Installer"
    Pop $Button
    ## ${NSD_OnClick} ...
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product 4 Installer"
    Pop $Button
    ## ${NSD_OnClick} ...
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product 1 Installer"
    Pop $Button
    ## ${NSD_OnClick} ...
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    ${NSD_CreateButton} 50% "$1u" 25% 12u "Product 1 Installer"
    Pop $Button
    ## ${NSD_OnClick} ...
    IntOp $0 $0 + 18
    IntOp $1 $0 - 2

    nsDialogs::Show
FunctionEnd

Function ExecInstall
    pop $0
    ExecWait $0 $1
    IfErrors 0 ExecDone
    MessageBox MB_OK|MB_IconExclamation "$1 $0 not found"
    ExecDone:
    ##Call Update_Install_Statuses
FunctionEnd

Function Manual_Install_Clicked
    ExecShell "open" "$EXEDIR\Manual\Manual.PDF"
FunctionEnd

Function Product1_Install_Clicked
    Exec "Explorer.exe $EXEDIR\Support Files"
FunctionEnd

Function Product2_Install_Clicked
    Push "$EXEDIR\Product2 Folder\Product2 Installer.exe"
    Call ExecInstall
FunctionEnd

Section

SectionEnd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM