Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3499032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:33:44+00:00 2026-05-18T12:33:44+00:00

I’m trying to set my control over the Outlook Mailgrid with SetParent and resize

  • 0

I’m trying to set my control over the Outlook Mailgrid with SetParent and resize (MoveWindow) and invalidate it if the Mailgrid changed.

This works, but on resize the control starts the flicker.

My Control is a replacement of Outlook’s Mailgrid. To change the mailpreview i just change the selection of the original mailgrid via my control.

The Parent of my Control is the Outlook main-window. I have already tried to close the Mailgrid window, but that didn’t help.

The flicker stops if I set the the Mailgrid as Parent, but in this case it flickers if i change the selection, and its not possible to draw my control over the mailsearch-window.

Does anybody know how to stop the extrem flicker?

Class to Handle changes of Outlook’s Mailgrid Messages

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);
    }
}

Creating the Event-Listener and Control and set it’s parent

//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));

On Change-Event

//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();

Painting of my Control

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)
}

/// EDIT

After adding a Thread.Sleep(1000) to the the DoPaint methode i was able to see the paint order.
After resizing, my control shows up for an instant, afterwards the Outlook Mailgrid overpaints my Control.
I’ve tried to set base.WndProc(ref m); befor OnChange(); but nothing changed.
I hope this helps to resolve the problem.

/// EDIT

After some testing I’ve tried to listen to all outlook windows and Graphics.Clear them orange.
I don’t know why, but even this doesn’t work. While resizing nearly everything is drawn by 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();
    }               

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:33:45+00:00Added an answer on May 18, 2026 at 12:33 pm

    I have solved the problem by adding the listener to the Outlook “Frame Splitter”.
    For some reason Outlook sets the Mailgrid invisible and paints direct on the main window. (the main window doesn’t get any windowmessage)

    I now also paint on WM_WINDOWPOSCHANGING WM_WINDOWPOSCHANGED WM_SETREDRAW my control over the main window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.