互联网探险家的儿童窗口闪烁 [英] Child window for Internet explorer flickering

查看:185
本文介绍了互联网探险家的儿童窗口闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写浏览器辅助对象,并希望在Internet Explorer浏览器窗口中显示一个子窗口,向用户显示一些消息。我使用DS_CONTROL和WS_CHILDWINDOW,并希望获得类似于此图像中的消息的行为:

I am writing a browser helper object and want to show a child window inside the internet explorer window to show the user some messages. I use DS_CONTROL and WS_CHILDWINDOW and want to get a behaviour similar to the message in this image:

我成功地插入和显示了一个子窗口,但窗口闪烁,有时它是可见的,有时网站内容在z坐标的窗口之上。我试图将子窗口设置为最顶层的窗口,但没有改变任何东西。如何让子窗口始终可见,直到它被关闭?这里是一些我使用的源代码:

I succeeded in inserting and showing a child window, but the window is flickering and sometimes it's visible and sometimes the website content is above the window in the z coordinate. I tried to set the child window as topmost window, but that didn't change anything. How can I get the child window to be always visible until it is closed? Here is some source code I use:

resource.rc:

resource.rc:

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_NOTIFICATIONBAR DIALOG 0, 0, 186, 95
STYLE DS_3DLOOK | DS_CONTROL | DS_MODALFRAME | DS_SYSMODAL | DS_SHELLFONT | WS_VISIBLE |  WS_CHILDWINDOW
EXSTYLE WS_EX_TOPMOST
FONT 8, "Ms Shell Dlg"
{
    DEFPUSHBUTTON   "OK", IDOK, 129, 7, 50, 14
    PUSHBUTTON      "Cancel", IDCANCEL, 129, 24, 50, 14
    LTEXT           "Static", IDC_STATIC, 25, 16, 68, 21, SS_LEFT
}

对话框类别:

#include "atlbase.h"
#include "atlwin.h"
#include "resources/resource.h"

class CMyDialog : public CDialogImpl<CMyDialog>
{
public:
   enum { IDD = IDD_NOTIFICATIONBAR };

   BEGIN_MSG_MAP(CMyDialog)
      MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
      COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnBnClickedCancel)
   END_MSG_MAP()

   CMyDialog() {Create(::GetActiveWindow());}

   ~CMyDialog() {DestroyWindow();}

   LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
      BOOL& /*bHandled*/)
   {
      // ::MessageBox(NULL,_T("OnInit"),_T("OnInit"),MB_ICONINFORMATION|MB_OK);
      // Do some initialization code
      return 1;
   }

   static CMyDialog &getInstance()
   {
       static CMyDialog dlg;
       return dlg;
   }
public:
   LRESULT OnBnClickedCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
   {
       ShowWindow(SW_HIDE);
       return 0;
   }
};

呼叫:

CMyDialog &bar=CMyDialog::getInstance();
bar.ShowWindow(SW_SHOWNORMAL);


推荐答案

最后我可以解决它信息我从下面的许多不同的答案)。

Finally I could solve it (with the help of the information I got from the many different answers below).

对于那些你有同样的问题,这里的解决方案:
我必须收缩窗口正在显示HTML网站,所以我自己的窗口不与它重叠。
对于这个,我得到当前的选项卡,例如此处
此选项卡窗口包含html文档窗口和状态栏。
因此我调用FindWindowEx两次来获取这两个窗口的HWND:

For those of you having the same problem, here the solution: I have to shrink the window that is displaying the HTML website, so my own window doesn't overlap with it. For this I get the current tab like in the example here. This tab window contains the html document window and the status bar. So I call FindWindowEx twice to get the HWNDs of those two windows:

FindWindowEx(tab,NULL,_T("Shell DocObject View"),_T("")) //html document window
FindWindowEx(tab,NULL,_T("msctls_statusbar32"),_T("")) //status bar

然后我调整文档窗口的大小,使其填充整个客户区域,除了状态栏和地方采取由我的对话。这里是代码(webbrowser.getCurrentTabHwnd()是示例的实现这里提到的。isShown是一个变量,如果我的对话框应该显示或不显示):

Then I resize the document window so that it fills the whole client area except for the place taken by the status bar and the place taken by my dialog. Here is the code (webbrowser.getCurrentTabHwnd() is an implementation of the example here mentioned above. isShown is a variable indicating, if my dialog should be shown or not):

CWindow tab(webbrowser.getCurrentTabHwnd());
CWindow child(FindWindowEx(tab,NULL,_T("Shell DocObject View"),_T("")));
CWindow statusbar(FindWindowEx(tab,NULL,_T("msctls_statusbar32"),_T("")));

RECT statusbarrect;
statusbar.GetWindowRect(&statusbarrect);
RECT documentrect;
tab.GetClientRect(&documentrect);
documentrect.bottom-=(statusbarrect.bottom-statusbarrect.top);

if(isShown)
{
    //Request document window rect
    static const unsigned int DLGHEIGHT=50;
    RECT dialogrect=documentrect;
    documentrect.top+=DLGHEIGHT;
    dialogrect.bottom=dialogrect.top+DLGHEIGHT;
    //Shrink document window
    MoveWindow(&dialogrect);
}

child.MoveWindow(&documentrect);

这段代码现在必须在每个浏览器窗口调整大小和对话框显示/隐藏。

This piece of code now has to be called on each browser window resize and on dialog show/hide.

这篇关于互联网探险家的儿童窗口闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆