首页 > 解决方案 > InstallShield 自定义对话框,WaitOnDialog() 始终返回 -1 (DLG_ERR)

问题描述

我目前正在做一个自定义对话框来处理 InstallScript 项目上的锁定文件情况。我知道有像 SdException() 这样的内置函数来处理这种情况,但这是避免用户意外选择忽略这种情况的要求。

总之,我初始化了 EzDefineDialog(),然后调用 WaitOnDialog() 来显示对话框,但它总是返回 -1。

以下是我的代码:

prototype NUMBER LockedFile(string /*FilePath*/);

//[[ ID_DATA
#define IDD_VER 300
#define ID_NAME_LOCKED_FILE "LockedFile"
#define ID_TITLE_LOCKED_FILE "Default Dialog Title\nDefault Title message"
#define ID_TEMPLATE_LOCKED_FILE 12345
//]]

//[[ ID_SYMBOLS
#define BT_PostPone 1303 
#define BT_Retry    1304 
#define BT_Abort    1305

#define IDC_TEXT1_LOCKED_FILE   1301

//]]

function NUMBER LockedFile(szFile /*FilePath*/)

NUMBER  nId;        // contains the return code of WaitOnDialog 
NUMBER  nResult;    // contains the return code of LockedFile
BOOL    bDone;      // tells if the dialog is to be closed
INT     hwndDlg;    // the handle of the dialog itself
STRING  szTitle;    // dialog's title
STRING  szDlg;      // the name of the dialog
STRING  szMessage;  // message to display on dialog
NUMBER  nTemplate;  // variable to store the template to be used for this dialog

begin

// Specify a name to identify the custom dialog in this installation.
szDlg = ID_NAME_LOCKED_FILE;
nTemplate = ID_TEMPLATE_LOCKED_FILE;



if (EzDefineDialog (szDlg, ISUSER, "", nTemplate) = DLG_ERR) then
    MessageBox("Fail to initialize the Locked Dialog for "+szFile, SEVERE);
    abort;
endif;

bDone = FALSE;
while (!bDone)
    nId = WaitOnDialog(szDlg);

    switch (nId)
        case DLG_INIT:
            // first internal InstallShield intitialise
            hwndDlg = CmdGetHwndDlg( szDlg );
            SdGeneralInit(szDlg, hwndDlg, 0, "");
        case DLG_CLOSE:
            // The user clicked the window's Close button.
            Do (EXIT);
        case DLG_ERR:
            MessageBox ("Unable to display dialog. Setup canceled.", SEVERE);
            abort;  
        case BT_PostPone:
            // user clicked PostPone button, the operation will be carried out after reboot
            bDone = TRUE;
            nResult =  1;
        case BT_Retry:
            // user clicked retry button, retry the operation immediately
            bDone = TRUE;
            nResult = 2;
        case BT_Abort:
            // user clicked abort button, abort the installation
            bDone = TRUE;
            nResult = 3;
        default:    
            // user do something else
            bDone = TRUE;
            nResult = -1;
     endswitch;
endwhile;

EndDialog(szDlg); // Close the dialog box. 

ReleaseDialog(szDlg);   // Free the dialog box from memory.

return nResult;

end;

我已经仔细检查并使用对话框和直接编辑器中的 ISResourceID 为 12345,它EzDefineDialog (szDlg, ISUSER, "", nTemplate)作为 nTemplate 传入。对话框名称 (szDlg) 也经过双重检查。

我想知道我哪里做错了。如何显示我的自定义对话框?

标签: dialogreturn-valueinstallshieldcustomdialoginstallscript

解决方案


我也有类似的经历,我是按名称引用对话框,而不是resourceID. 该WaitOnDialog()函数始终返回DLG_ERR,直到我将对话框更改resourceID0.

也许这有帮助...


推荐阅读