开发者

DialogBox in Win32 - Prevent multiple instance

I have a program which creates DialogBox window when user clicks the menu item from tray icon,

 case ID_OPTIONS:
        DialogBox ( GetModuleHandle ( NULL ), 
                    MAKEINTRESOURCE ( IDD_SETUP_DIALOG ), 
                    hWnd, 
                    reinterpret_cast<DLGPROC>(SetupDlgProc) );
        return 0;

Bu开发者_StackOverflowt the problem here is everytime when users clicks item from tray , a new instance of the dialogbox appears. Is there anyway to prevent this multiple instance ?

BTW, my SetupDlgProc looks like this,

BOOL CALLBACK SetupDlgProc ( HWND hwnd, UINT Message, WPARAM wParam, 
                                                            LPARAM lParam )
{
    switch ( Message )
    {
    case WM_INITDIALOG:
     ...
    }
}

Thanks for your help.


A common problem. Use a flag:

static bool bDialogShowing = false;
switch (Message)
{
case ID_OPTIONS:

    if (bDialogShowing) 
        return true;
    bDialogShowing = true;

    DialogBox ( GetModuleHandle ( NULL ), 
                MAKEINTRESOURCE ( IDD_SETUP_DIALOG ), 
                hWnd, 
                reinterpret_cast<DLGPROC>(SetupDlgProc) );

    bDialogShowing = false;

    return 0;
/* ... */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜