Window recreation on theme change

  • Thread starter Thread starter Peter Wone
  • Start date Start date
P

Peter Wone

The short version is that when the theme is changed my application barfs.

The problem is a control I've created to host the WebBrowser control and
implement all the com callbacks for browser customisation. The problem only
occurs when it's present.

I'll fix it, but first I need detailed info on exactly what happens to a
winform when the theme changes. It seems to me that the native window would
have to be recreated to pick up the new window style, and there are
undoubtedly various messages flying around that my control ought to respond
to.

Obviously I want to handle this in my control rather than on the form. Other
controls get re-themed, so obviously they get notified somehow and I ought
to be handling this notification... I don't suppose there's an OnThemeChange
or OnRecreateNativeWindow event...?

And having detected the change, what are the responsibilities of a control
at this point?
 
There is a notfication WM_THEMECHANGED and the form seems to be handling it.

When the exception occurs the call stack is very short, it looks like the
DNF is invoking System.Windows.Forms.MessageBox.ShowCore() and passing it a
null reference.

Naturally the ShowCore() method is about as well documented as my bum.
 
It only barfs if my wrapper is installed:

(IE.GetOcx() as IOleObject).SetClientSite(this as IOleClientSite);

Setting

(IE.GetOcx() as IOleObject).SetClientSite(null);

Makes the problem go away - but of course you lose all the benefits of the
wrapper.
 
I tried hooking WM_THEMECHANGED in WndProc and disconnecting from the
browser. To reconnect I send myself a message using BeginInvoke() to call
the method that installs my control as the client site of the browser
object.

It no longer dies but the browser has a tantrum when I try to use it.

I tried creating a new browser and setting that up. It hooks up and does
callbacks (I can tell because it changes its border in accordance with the
host settings) but it has a tantrum when I try to call Navigate();
 
Built myself a test harness: I send the WM_THEMECHANGED message to the form
myself using a button click event handler.

It works in the test harnes - I detach and send a message to reattach and it
all happens and Bob's your uncle. Except that it doesn't work when the
message is the real McCoy. I still get my NullReferenceException.

What's REALLY puzzling is that I've discovered that the hWnd is constant
which implies that the window ISN'T being destroyed, so I'm blowed if I know
what's giving it indigestion.

Someone say something useful, I'm starting to freak out!

Next thing I'll try is putting the thread to sleep for say two seconds while
themes gets its act together.
 
Back
Top