父窗口重绘时子窗口的消失

时间:2021-04-17 07:29:59

I created child window (dialog) end set it's parent the window of another process (Notepad for example) by its handle.

我创建了子窗口(对话框),通过其句柄设置它的父窗口另一个进程(例如记事本)的窗口。

HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
    PROCESS_VM_READ,
    FALSE, processID );

if (NULL != hProcess )
{
    HWND hw;
    hw = find_main_window(processID); //some function of getting win handle through process ID
}

................

CMyHud *mhDlg = new CMyHud();
CWnd* pWnd = CWnd::FromHandle(hw);


//if(mhDlg->m_hWnd != 0) 
if (!mhDlg->GetSafeHwnd())
{
    if (mhDlg != NULL)
    {
        ret = mhDlg->Create(IDD_DIALOG1, pWnd);
    }

    if (!ret)   //Create failed.
    {
        AfxMessageBox(_T("Error creating Dialog"));
        return FALSE;
    } 
}

Then I set styles for parent and child windows

然后我为父窗口和子窗口设置样式

LONG t = GetWindowLong(hw,GWL_STYLE) | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
SetWindowLong(hw,GWL_STYLE,t);

LONG t1 = GetWindowLong(mhDlg->m_hWnd,GWL_STYLE) | WS_CLIPSIBLINGS | WS_OVERLAPPED;
SetWindowLong(mhDlg->m_hWnd,GWL_STYLE,t1);
::BringWindowToTop(mhDlg->m_hWnd);
mhDlg->ShowWindow(SW_SHOW);

The child window appears in the client area of the parent window (Notepad).

子窗口显示在父窗口(记事本)的客户区域中。

Good.

好。

BUT! It's disappears when I set focus on parent window. Well. Physically it's still there, but its background merges with parent's window background, and it seems like the child window is gone.

但!当我将焦点设置在父窗口上时,它会消失。好。物理上它仍然存在,但它的背景与父窗口背景合并,似乎子窗口消失了。

When you find child window and set focus on it, it's appearing again. But it is redrawing bad, still having a parts of parent's window background (look at the picture). 父窗口重绘时子窗口的消失

当您找到子窗口并将焦点设置在它上面时,它会再次出现。但它重绘不好,仍然有一部分父母的窗口背景(看图片)。

What have i done wrong?? What should I do for appearing child window over the parent ALWAYS, regardless of redrawing the parent window?

我做错了什么?无论是否重绘父窗口,我应该如何在父ALWAYS上显示子窗口?

1 个解决方案

#1


1  

With using the SetWindowPos method all works perfectly!

使用SetWindowPos方法一切都很完美!

#1


1  

With using the SetWindowPos method all works perfectly!

使用SetWindowPos方法一切都很完美!