Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change a window's class after creation?

How can I change the window class of a win32 window after creation? I am asking out of curiosity, because I've found with Spy++ that one of these fancy desktop-customization tools from Stardock does exactly that.

Disclaimer (sadly neccessary nowadays): I've searched the documentation and couldn't find anything. I know that this is probably not intended to be done, might cause a lot of wierd side-effects, and should not be done in a production application. Still, I'd like to know how they pulled it off.

Edit: The background story, might be interesting.

I was playing around with Stardock's ModernMix, which allows you to use Metro / Modern / Windows Store apps on the Desktop, in windowed mode, and I wanted to figure out how they do it. I quickly found out that Modern apps just run in regular, fullscreen Win32 windows! You can actually change the window styles to un-maximized it and give it a titlebar etc.. However, at least one thing doesn't work: You cannot use aero snap on the window, and the hot edge on the top of the screen still treats the window as a Modern app. This problem does not exist in ModernMix, so I was looking for the difference.

I continuously displayed various debugging information in my app, including the HWND, window styles, and also examined the Window with Spy++. It turns out that when ModernMix unmaximizes a window, it's class "changes" from Windows.UI.Core.CoreWindow to Windows.UI.Core.CoreFramedWindow. The HWND displayed in my window didn't change however! So I wrongly concluded ModernMix gets rid of the special behavior of the window by changing the class... But it turns out, ModernMix just creates another toplevel, and somehow redirects the original window's contents to the new toplevel (at least that's what it looks like).

(I'm still leaving the question here, even if only as a reference that it can't be done.)

like image 747
jdm Avatar asked Mar 04 '26 04:03

jdm


1 Answers

There is no way to change the class of an existing window. The only option is to destroy the original window and create a new window using a different class.

like image 71
Remy Lebeau Avatar answered Mar 06 '26 02:03

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!