首页
社区
课程
招聘
[求助]如何在不关闭MessageBox的情况下解除对话框hWnd的锁定?
发表于: 2008-2-22 11:10 7024

[求助]如何在不关闭MessageBox的情况下解除对话框hWnd的锁定?

2008-2-22 11:10
7024
请教大家一个问题:

MessageBox,hWnd,CTXT("请试着在不关闭本窗口的情况下解除锁定"),CTXT("试试看"),MB_OKCANCEL

用这一句产生一个MessageBox窗口
它的父窗口设置为一个对话框hWnd
如何在不关闭MessageBox的情况下解除对话框hWnd的锁定?
有兴趣的看一下。

源程序下载地址:
Dialog.rar
点击OK之后,会出现MessageBox。



我的51博客开通了:江山烟雨楼-惊轩楼主 http://tshemeng.51.com

附一些我搜集的汇编资料,仅限个人使用!

【罗云彬的编程乐园.chm】:106.63MB
罗云彬的编程乐园.chm

【老罗的缤纷天地.chm】:19.32MB
老罗的缤纷天地.chm

【Win32ASMTRK.chm】:2.70MB
Win32ASMTRK.chm

【API助手】易语言中提取的:2.26MB
API助手.rar

【RC资源编辑器.exe】绿色215.5KB
资源编辑器.exe

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 1
支持
分享
最新回复 (6)
雪    币: 100
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
?用什么YY写的咯。。。
2008-2-22 11:46
0
雪    币: 203
活跃值: (12)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
自己实现一个MessageBoxXXX
2008-2-22 11:53
0
雪    币: 216
活跃值: (2407)
能力值: ( LV10,RANK:170 )
在线值:
发帖
回帖
粉丝
4

invoke MessageBox,hWnd,CTXT("请试着在不关闭本窗口的情况下解除锁定"),CTXT("试试看"),MB_OKCANCEL
改为
invoke MessageBox,0,CTXT("请试着在不关闭本窗口的情况下解除锁定"),CTXT("试试看"),MB_OKCANCEL
2008-2-22 13:06
0
雪    币: 7309
活跃值: (3778)
能力值: (RANK:1130 )
在线值:
发帖
回帖
粉丝
5
注意他的要求:

用这一句产生一个MessageBox窗口
它的父窗口设置为一个对话框hWnd
如何在不关闭MessageBox的情况下解除对话框hWnd的锁定?
2008-2-22 13:18
0
雪    币: 325
活跃值: (97)
能力值: ( LV13,RANK:530 )
在线值:
发帖
回帖
粉丝
6
::EnableWindow(hWnd,TRUE)
我刚测试了一下,是可行的:
#include "windows.h"
#include "resource.h"
DWORD WINAPI ThreadProc(
  LPVOID lpParameter
)
{
        OutputDebugStringA("Thread Proc Startup ....");
        HWND hWnd = (HWND)lpParameter;
        Sleep(2000);
        if(::EnableWindow(hWnd,TRUE) == FALSE){
                OutputDebugStringA("Error On EnableWindow");
        }
        return FALSE;
}
VOID CALLBACK WaitOrTimerCallback(
  PVOID lpParameter,
  BOOLEAN TimerOrWaitFired
)
{
        if(TimerOrWaitFired == TRUE){
                OutputDebugStringA("WaitOrTimerCallback Proc Startup ....");
                HWND hWnd = (HWND)lpParameter;
                if(::EnableWindow(hWnd,TRUE) == FALSE){
                        OutputDebugStringA("Error On EnableWindow");
                }
                return;
        }
}
INT_PTR CALLBACK DialogProc(          HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
)
{
        BOOL bProcess = TRUE;
        switch(uMsg)
        {
        case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                case IDOK:
                case IDCANCEL:
                        {
                                ::PostQuitMessage(NULL);
                        }
                        break;
                case IDC_BUTTON_SHOWMSGBOX:
                        {
                                //::CreateThread(NULL,NULL,&ThreadProc,(LPVOID)hwndDlg,NULL,NULL);
                                HANDLE hTimer;
                       
                                HANDLE hTimerQueue = NULL;
                                hTimerQueue = ::CreateTimerQueue();
                                if(::CreateTimerQueueTimer(
                                        &hTimer,
                                        hTimerQueue,
                                        WaitOrTimerCallback,
                                        (LPVOID)hwndDlg,
                                        2000,
                                        NULL,
                                        WT_EXECUTEDEFAULT
                                        ) == FALSE){
                                                OutputDebugStringA("Error CreateTimerQueueTimer");
                                }
                                ::MessageBoxA(hwndDlg,"Test Show Mode MessageBox","Testing",MB_ICONINFORMATION);
                                if(hTimerQueue != NULL)
                                        ::DeleteTimerQueueEx(hTimerQueue,NULL);
                        }
                        break;
                }
                break;
        default:
                DefWindowProcA(hwndDlg,uMsg,wParam,lParam);
                bProcess = FALSE;
        }
       
        return bProcess;
}
void main(){
        DialogBoxA(::GetModuleHandleA(NULL),MAKEINTRESOURCEA(IDD_DIALOG1),NULL,&DialogProc);
}
2008-2-22 16:14
0
雪    币: 325
活跃值: (97)
能力值: ( LV13,RANK:530 )
在线值:
发帖
回帖
粉丝
7
原理可以看
/***********************************************************************
*           DIALOG_CreateIndirect
*       Creates a dialog box window
*
*       modal = TRUE if we are called from a modal dialog box.
*       (it's more compatible to do it here, as under Windows the owner
*       is never disabled if the dialog fails because of an invalid template)
*/
static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
                                   HWND owner, DLGPROC dlgProc, LPARAM param,
                                   BOOL unicode, BOOL modal )
{
    HWND hwnd;
    RECT rect;
    DLG_TEMPLATE template;
    DIALOGINFO * dlgInfo = NULL;
    DWORD units = GetDialogBaseUnits();
    BOOL ownerEnabled = TRUE;
    HMENU hMenu = 0;
    HFONT hUserFont = 0;
    UINT flags = 0;
    UINT xBaseUnit = LOWORD(units);
    UINT yBaseUnit = HIWORD(units);

      /* Parse dialog template */

    if (!dlgTemplate) return 0;
    dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );

      /* Load menu */

    if (template.menuName) hMenu = LoadMenuW( hInst, template.menuName );

      /* Create custom font if needed */

    if (template.style & DS_SETFONT)
    {
          /* We convert the size to pixels and then make it -ve.  This works
           * for both +ve and -ve template.pointSize */
        HDC dc;
        int pixels;
        dc = GetDC(0);
        pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
        hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
                                          template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
                                          PROOF_QUALITY, FF_DONTCARE,
                                          template.faceName );
        if (hUserFont)
        {
            SIZE charSize;
            HFONT hOldFont = SelectObject( dc, hUserFont );
            charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy );
            if (charSize.cx)
            {
                xBaseUnit = charSize.cx;
                yBaseUnit = charSize.cy;
            }
            SelectObject( dc, hOldFont );
        }
        ReleaseDC(0, dc);
        TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
    }

    /* Create dialog main window */

    rect.left = rect.top = 0;
    rect.right = MulDiv(template.cx, xBaseUnit, 4);
    rect.bottom =  MulDiv(template.cy, yBaseUnit, 8);
    if (template.style & WS_CHILD)
        template.style &= ~(WS_CAPTION|WS_SYSMENU);
    if (template.style & DS_MODALFRAME)
        template.exStyle |= WS_EX_DLGMODALFRAME;
    if (template.style & DS_CONTROL)
        template.exStyle |= WS_EX_CONTROLPARENT;
    AdjustWindowRectEx( &rect, template.style, (hMenu != 0), template.exStyle );
    rect.right -= rect.left;
    rect.bottom -= rect.top;

    if (template.x == CW_USEDEFAULT16)
    {
        rect.left = rect.top = CW_USEDEFAULT;
    }
    else
    {
        if (template.style & DS_CENTER)
        {
            rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
            rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
        }
        else
        {
            rect.left += MulDiv(template.x, xBaseUnit, 4);
            rect.top += MulDiv(template.y, yBaseUnit, 8);
        }
        if ( !(template.style & WS_CHILD) )
        {
            INT dX, dY;

            if( !(template.style & DS_ABSALIGN) )
                ClientToScreen( owner, (POINT *)&rect );

            /* try to fit it into the desktop */

            if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
                 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
            if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
                 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
            if( rect.left < 0 ) rect.left = 0;
            if( rect.top < 0 ) rect.top = 0;
        }
    }

    if (modal)
    {
        ownerEnabled = DIALOG_DisableOwner( owner );
        if (ownerEnabled) flags |= DF_OWNERENABLED;
    }

    if (unicode)
    {
        hwnd = User32CreateWindowEx(template.exStyle, (LPCSTR)template.className, (LPCSTR)template.caption,
                                    template.style & ~WS_VISIBLE,
                                    rect.left, rect.top, rect.right, rect.bottom,
                                    owner, hMenu, hInst, NULL,
                                    TRUE);
    }
    else
    {
        LPSTR class = (LPSTR)template.className;
        LPSTR caption = (LPSTR)template.caption;

        if (HIWORD(class))
        {
            DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
            class = HeapAlloc( GetProcessHeap(), 0, len );
            WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
        }
        if (HIWORD(caption))
        {
            DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
            caption = HeapAlloc( GetProcessHeap(), 0, len );
            WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
        }
        hwnd = User32CreateWindowEx(template.exStyle, class, caption,
                                    template.style & ~WS_VISIBLE,
                                    rect.left, rect.top, rect.right, rect.bottom,
                                    owner, hMenu, hInst, NULL,
                                    FALSE);
        if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
        if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
    }

    if (!hwnd)
    {
        if (hUserFont) DeleteObject( hUserFont );
        if (hMenu) DestroyMenu( hMenu );
        if (modal && (flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
        return 0;
    }

    /* moved this from the top of the method to here as DIALOGINFO structure
    will be valid only after WM_CREATE message has been handled in DefDlgProc
    All the members of the structure get filled here using temp variables */

//    dlgInfo = DIALOG_get_info( hwnd, TRUE );

    if (!(dlgInfo = HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo) ))) return 0;
    SETDLGINFO(hwnd, dlgInfo);

    dlgInfo->hwndFocus   = 0;
    dlgInfo->hUserFont   = hUserFont;
    dlgInfo->hMenu       = hMenu;
    dlgInfo->xBaseUnit   = xBaseUnit;
    dlgInfo->yBaseUnit   = yBaseUnit;
    dlgInfo->idResult    = 0;
    dlgInfo->flags       = flags;
//    dlgInfo->hDialogHeap = 0;

    if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );

    if (unicode) SetWindowLongPtrW( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
    else SetWindowLongPtrA( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );

    if (dlgInfo->hUserFont)
        SendMessageW( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );

    /* Create controls */

    if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
    {
        /* Send initialisation messages and set focus */

        if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ) &&
            ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
        {
            /* By returning TRUE, app has requested a default focus assignment */
            dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
            if( dlgInfo->hwndFocus )
                SetFocus( dlgInfo->hwndFocus );
        }

        if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
        {
           ShowWindow( hwnd, SW_SHOWNORMAL );   /* SW_SHOW doesn't always work */
        }
        return hwnd;
    }
    if (modal && ownerEnabled) DIALOG_EnableOwner(owner);    if( IsWindow(hwnd) ) DestroyWindow( hwnd );
    return 0;
}

/* INTERNAL FUNCTIONS ********************************************************/

/***********************************************************************
*           DIALOG_EnableOwner
*
* Helper function for modal dialogs to enable again the
* owner of the dialog box.
*/
void DIALOG_EnableOwner( HWND hOwner )
{
    /* Owner must be a top-level window */
    if (hOwner)
        hOwner = GetAncestor( hOwner, GA_ROOT );
    if (!hOwner) return;
        EnableWindow( hOwner, TRUE );}
2008-2-22 16:17
0
游客
登录 | 注册 方可回帖
返回
//