Screen flashes when windows form is unloaded?

  • Thread starter Thread starter TCook
  • Start date Start date
T

TCook

Hey All,

I have a VS2003, C# addin for MS Word 2003. When the windows form unloads,
the screen flashes. I've never seen this behavior before. Usually, the
unloading of a form is very smooth.

I was wondering if anyone else has experienced this and, if so, if you were
able to resolve it.

Thanks & Regards,

TC
 
Hey Folks,

Some more info on the behavior.

I have used the Win32 API in attempt to set Word as the windows form's
parent. I have also tried creating an IWin32Window class as well.

Win32 Method:

public static void SetParentAsTopWindow(WordReferences wordReferences)

{

try

{

IntPtr HwndWindow=new IntPtr(0);

bool Result=new bool();

Win32.EnableWindow((IntPtr)wordReferences.Handle, true);


HwndWindow=FindWindow(WordReferences.WordClassName, null);

if (HwndWindow!=IntPtr.Zero)

{

Result=Win32.SetForegroundWindow(HwndWindow);

}

}

catch(System.Exception ex)

{

ExceptionHandler.HandleException(ex);

}

}


The class:

public class WordHWND : IWin32Window

{

public const string WordWindowSuffix = " - Microsoft Word";

string _windowName;

public WordHWND(string windowName)

{

_windowName = windowName + WordHWND.WordWindowSuffix;

}

public IntPtr Handle

{

// Note: "OpusApp" is the class name for Word

get { return Win32.FindWindow(WordReferences.WordClassName, _windowName);}

}

}


What appears to be happening is the form is taking the window behind Word as
the parent. When it unloads, it briefly displays another window for a split
second and then one is back in Word. However, Word's title bar is grayed.
Even though you can work in the Word window, the title bar remains grayed.
Not until the window is resized via Minimize, Maximize or Normal does it
become un-grayed.

I have also tried turning off screenupdating as well as the Win32 API
"LockWindowUpdate" but the flashing and graying out continue.

Has anyone else experienced this using C# in VS2003 with an MSWord addin?

I am using Word 2003.

Any assistance would be greatly appreciated.

Regards,

TC
 
Back
Top