如何通过Outlook Mailgrid设置定制控制?
-
09-10-2019 - |
题
我正在尝试使用SetParent和Resemize(MoveWindow)设置对Outlook Mailgrid的控制权,并在MailGrid更改时将其无效。
这有效,但是在调整大小时,控件启动了闪烁。
我的控制是替代Outlook的Mailgrid。要更改MailPreview,我只需通过我的控件更改原始MailGrid的选择。
我控制的父母是Outlook主窗口。我已经试图关闭邮递窗口,但这无济于事。
如果我将邮件格里德设置为父母,则闪烁会停止,但是在这种情况下,如果我更改选择,它会闪烁,并且不可能掌握我对MailSearch-Window的控制权。
有人知道如何阻止极端闪烁吗?
处理Outlook Mailgrid消息更改的课程
sealed class SubWindow : NativeWindow
{
public event EventHandler Changed;
protected override void WndProc(ref Message m)
{
if (m.Msg == (int)(NativEnums.WindowMessage.WM_SIZE) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_WINDOWPOSCHANGED) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_WINDOWPOSCHANGING) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_ERASEBKGND) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_NCHITTEST) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_NCCALCSIZE) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_PAINT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_NCPAINT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_PRINT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_PRINTCLIENT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_SETREDRAW) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_MOVE)
)
{
OnChanged();
}
base.WndProc(ref m);
//I have already tried to ignore wm_paint, but it still painted
//if (m.Msg != (int)NativEnums.WindowMessage.WM_PAINT)
//{
// base.WndProc(ref m);
//}
}
private void OnChanged()
{
if (Changed != null)
Changed(this, null);
}
}
创建事件列表并控制并设置它的父
//Is the Class above
SubWindow lw = new SubWindow();
lw.AssignHandle(ListHandle);
lw.Changed += new EventHandler(lw_Changed);
//Gets the IntPtr of the Mailgrid
//MainWindow is the Outlook main-window window
IntPtr ListHandle = GetSizes.GetMailFolderIntPtr(MainWindow);
//Gets the Rectangle of the Mailgrid
System.Drawing.Rectangle listsize = GetSizes.GetMailfolderSize(MainWindow, ListHandle);
//mc is the Custom Control
MoveWindow(mc.Handle, listsize.Left, listsize.Top, listsize.Width, listsize.Height, false);
SetParent(mc.Handle, MainWindow);
SetWindowLong(mc.Handle, (int)NativEnums.GetWindowLongConst.GWL_STYLE, (uint)(NativEnums.WindowStyles.WS_CHILD | NativEnums.WindowStyles.WS_VISIBLE));
关于变化事件
//Gets the Rectangle of the Mailgrid
System.Drawing.Rectangle listsize = GetSizes.GetMailfolderSize(MainWindow, ListHandle);
//Move and size the CustomControl to the Mailgrid Rectangle
MoveWindow(mc.Handle, listsize.Left, listsize.Top, listsize.Width, listsize.Height, false);
//Invalidate my Control
mc.Invalidate();
我的控制绘画
protected override void OnPaint(PaintEventArgs e)
{
DoPaint(e.Graphics);
//base.OnPaint(e);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//base.OnPaintBackground(pevent);
}
public void DoPaint(Graphics g)
{
g.Clear(BackColor);
//Here comes the painting of the GridRows (only the visible rows)
}
/// 编辑
添加一个 Thread.Sleep(1000)
我能够看到油漆顺序。调整大小后,我的控件立即出现,然后将Outlook Mailgrid Overgovers绘制我的控制。我试图设置 base.WndProc(ref m);
之前 OnChange();
但是什么都没有改变。我希望这有助于解决问题。
/// 编辑
经过一番测试,我尝试收听所有Outlook Windows和 Graphics.Clear
他们橙色。我不知道为什么,但即使这行不通。在调整大小的同时,几乎所有内容都是由Outlook绘制的。
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
/////////////////////////////////////////////////////
// Here i clear the complete window (all windows) //
/////////////////////////////////////////////////////
using (Graphics g = Graphics.FromHwnd(m.HWnd))
g.Clear(Color.Orange);
if (m.Msg == (int)(NativEnums.WindowMessage.WM_SIZE) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_WINDOWPOSCHANGED) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_WINDOWPOSCHANGING) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_WINDOWPOSCHANGING) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_ERASEBKGND) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_NCHITTEST) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_NCCALCSIZE) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_PAINT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_NCPAINT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_PRINT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_PRINTCLIENT) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_SETREDRAW) ||
m.Msg == (int)(NativEnums.WindowMessage.WM_MOVE)
)
{
OnChanged();
}
}
解决方案
我通过将侦听器添加到Outlook“框架分离器”中解决了问题。出于某种原因,Outlook将邮机看不见,并直接在主窗口上绘画。 (主窗口没有任何窗口)
我现在也绘画 WM_WINDOWPOSCHANGING
WM_WINDOWPOSCHANGED
WM_SETREDRAW
我对主窗口的控制。