EnableVisualStyles breaks PropertyGrid..

G

Guest

Ok, here is what I was going to post

"Ok, I have a custom form that behaves like the MSN Messenger popup. I wrote a small demo with two tabs: one tab has a few controls that allows you to modify some properties of the popup window (caption, position, animation, etc...) On the second tab I have a propertyGrid who's SelectedObject is the popup window. When I alter properties from code or from using the controls (popupWindow1.<property> = whatever) it all works ok. However, when I use the property grid to change properties a strange thing happens: when I change a property that is represented by an enum (like BorderStyle), I can change it once, but when I change it the second time a SEHException occurs... Here is the stack trace

StackTrace " at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at MyFormProject.MainForm.Main()

I need at least to know if there is something broken in my form or if this is some sort of weird behavior in connection with the propertyGrid? I don't understand why DispatchMessage would raise an error? It doesn't seem an usual thing from my win32 knowledge...

Here is some more details about the exception

ErrorCode -2147467259 in
_COMPlusExceptionCode -532459699 in

However, while testing this is what I also noticed: If I double click the combo in the property grid which automatically switches the value to the next in the list, no error occurs and the form correctly updates. The error occurs ONLY if I drop down the combo in the property grid and choose another value with the mouse. This makes me think that there is something wrong with either the property grid or the UITypeEditor.

Before posting I decided to do more tests... Guess what: the same thing was happening with ANY control associated with the property grid. And guess what: when I removed the Application.EnableVisualStyles() from the Form_Load, it all went away... So, beware: EnableVisualStyles is a bad thing to use. Probably it might have some other side effects too..

regards
iulia
 
Y

Yasutaka Ito

Thanks iulian,
Keep sharing such info.

This is just off the hat, but what if you used the EnableVisualStyle in your
Main function, rather than in the Form_Load()? Would that makes difference?
Like this...

static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}

thanks!
-Yasutaka

Iulian Ionescu said:
Ok, here is what I was going to post:

"Ok, I have a custom form that behaves like the MSN Messenger popup. I
wrote a small demo with two tabs: one tab has a few controls that allows you
to modify some properties of the popup window (caption, position, animation,
etc...) On the second tab I have a propertyGrid who's SelectedObject is the
popup window. When I alter properties from code or from using the controls
(popupWindow1.<property> = whatever) it all works ok. However, when I use
the property grid to change properties a strange thing happens: when I
change a property that is represented by an enum (like BorderStyle), I can
change it once, but when I change it the second time a SEHException
occurs... Here is the stack trace:
StackTrace " at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason,
Int32 pvLoopData)\r\n at
System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)\r\n at
System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)\r\n at
System.Windows.Forms.Application.Run(Form mainForm)\r\n at
MyFormProject.MainForm.Main() "
I need at least to know if there is something broken in my form or if this
is some sort of weird behavior in connection with the propertyGrid? I don't
understand why DispatchMessage would raise an error? It doesn't seem an
usual thing from my win32 knowledge...
Here is some more details about the exception:

ErrorCode -2147467259 int
_COMPlusExceptionCode -532459699 int

However, while testing this is what I also noticed: If I double click the
combo in the property grid which automatically switches the value to the
next in the list, no error occurs and the form correctly updates. The error
occurs ONLY if I drop down the combo in the property grid and choose another
value with the mouse. This makes me think that there is something wrong with
either the property grid or the UITypeEditor."
Before posting I decided to do more tests... Guess what: the same thing
was happening with ANY control associated with the property grid. And guess
what: when I removed the Application.EnableVisualStyles() from the
Form_Load, it all went away... So, beware: EnableVisualStyles is a bad thing
to use. Probably it might have some other side effects too...
 
H

Herfried K. Wagner [MVP]

* "Yasutaka Ito said:
This is just off the hat, but what if you used the EnableVisualStyle in your
Main function, rather than in the Form_Load()? Would that makes difference?
Like this...

static void Main()
{
Application.EnableVisualStyles();

.... and would make adding 'Application.DoEvents()' here make a difference?
 
G

Guest

I actually checked what EnableVisualStyles does by decompiling the method and it's just this:

this.useVisualStyles = true;

It simply sets a field to true...
It means that at some point, when the control render needs to draw something it will simply look at the value of this field and it will then call the UXTheme functions or not. So I believe it's something that goes deeper in the render engine. Just the fact that it is a SEHException (Structured Handled Error) it means to me that it escapes all exception traps and basically ends up in the deepest win32 exception pool. Again, it might be something that is only triggered by a certain system or various services in the memory. I thought maybe it's because of the StyleXP software I had installed, but even after uninstallation the bug was still on...
Anyway, I am almost finished with my own XPControlRender class and I can say goodbye to manifest files and EnableVisualSyles... Of course, Longhorn will already have them (I saw references to ButtonThemeRenderer and likes), but who knows when it will be finally released?

regards,
iulian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top