Remove Window Icon [Solved]

BlitzMax Forums/MaxGUI Module/Remove Window Icon [Solved]

RustyKristi(Posted 2016) [#1]
...


RustyKristi(Posted 2016) [#2]
Anyone knows how to remove the default window icon when using CreateWindow? Nothing specified in the manual re that part.


Kryzon(Posted 2016) [#3]
You need to use the OS API, as the window decoration (icon, caption text, border etc.) is managed by that.
For Windows there seems to be two ways:
Use SendMessage with a null icon parameter:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632643(v=vs.85).aspx

Or SetWindowLong:
http://stackoverflow.com/a/10833540


RustyKristi(Posted 2016) [#4]
Thanks Kryzon. I know I have checked on this before here and found the solution but with the tons of info and discussions here I seem to get lost sometimes. :-)


grable(Posted 2016) [#5]
If you have MinGW you can also use windres and make a resource object with the icon, which in turn can be baked into the executable.
Any MaxGUI window will then use that icon.


RustyKristi(Posted 2016) [#6]
hey grable, my problem is taking it out. Maybe I should create a resource file with a null value for the icon, just like Kryzon suggested.


grable(Posted 2016) [#7]
Ah, my mistake.

You can try this, but it will remove the other buttons as well:
SetWindowLongA( hwnd, GWL_STYLE, GetWindowLongA( hwnd, GWL_STYLE) & ~WS_SYSMENU)
Or change it into a toolwindow, though it wont look like or behave like a normal window any longer:
SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA( hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW)
Other then that, you would have to resort to overriding the NC region of the window and draw the titlebar yourself.

EDIT: Found this when searching https://stackoverflow.com/questions/3096359/wpf-remove-system-menu-icon-from-modal-window-but-not-main-app-window#3364875
EDIT2: Couldnt get it to work after all, had a typo.. but the below works to an extent:
	Local exstyle:Int = GetWindowLongA( hwnd, GWL_EXSTYLE)
'	SetWindowLongA( hwnd, GWL_EXSTYLE, exstyle | WS_EX_DLGMODALFRAME)
	SetWindowLongA( hwnd, GWL_EXSTYLE, exstyle | WS_EX_TOOLWINDOW)
	
	SendMessageA( hwnd, WM_SETICON, ICON_SMALL, 0)
	SendMessageA( hwnd, WM_SETICON, ICON_BIG, 0)

	SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED)

Note that im on Windows 10, so this might work differently on other versions.


RustyKristi(Posted 2016) [#8]
Thanks grable. It doesn't seem to be working, I'm using Win7. The window title icon is what I'm after not the app btw. I guess that will be the small part?


grable(Posted 2016) [#9]
All 3 options worked for me, and the two top ones arent anything special so should work on versions >= win2k.
If they dont for you, try forcing an update of the frame by using that last line with SetWindowPos.

The window title icon is what I'm after not the app btw. I guess that will be the small part?
Yes, the titlebar icon is what it removes.
Im not sure how windows handles small/big, it might make a small one out of a big one or vica versa of one of them is set.
Youd have to test with a custom icon to notice i guess.

EDIT: Note that the original link uses WS_EX_DLGMODALFRAME, which did nothing for me. So i used WS_EX_TOOLWINDOW instead which did.


RustyKristi(Posted 2016) [#10]
Thanks. would you mind posting your bmx source? Maybe I'm just doing something wrong.


RustyKristi(Posted 2016) [#11]
I tried a NULL icon on the manifest but it won't compile.


grable(Posted 2016) [#12]
I tested this on a window created by Graphics, and since it isnt resizable it works differently than with windows created by MaxGUI.
And there is also some flags that are cached by windows which means they cannot be changed after a window has been created (like WS_EX_DLGMODALFRAME)
And a bunch of other arbitrary rules about dialogs vs windows sigh...

What it boils down to is that a change to MaxGUI is required for no icon AND having all the other buttons intact. Specifically the flag WS_EX_DLGMODALFRAME must be used on creation.

If you dont mind having no min&max buttons, you can use the MaxGUI window flag WINDOW_TOOL (didnt know MaxGUI had this hehe)

But after some fussing about, i managed to fool MaxGUI into the proper behaviour, though it might cause issues because of the hidden parent window.
The code below, forces MaxGUI to create the second window as a Dialog window, which has no icon. It also hides the first window but still allows it to appear on the taskbar, since Dialogs dont show up there.

SuperStrict

Import MaxGUI.Drivers

Local hidden:TGadget = CreateHiddenWindow("hidden")

'NOTE: WINDOW_CENTER doesnt appear to work
Local w:TGadget = CreateWindow( "test", 300,300, 640,480, hidden, WINDOW_TITLEBAR | WINDOW_RESIZABLE)
 
While WaitEvent()
	Select CurrentEvent.ID
		Case EVENT_WINDOWCLOSE Exit
	EndSelect
Wend
End

Function CreateHiddenWindow:TGadget( title:String = Null)
	Local win:TGadget = CreateWindow( title, 0,0,0,0, Null, WINDOW_HIDDEN)
	Local hwnd:Int = win.Query(QUERY_HWND)
	ShowWindow( hwnd, SW_SHOW)
	Return win
EndFunction

EDIT: Oh, and heres the testbed i used if you want to continue trying yourself ;)



RustyKristi(Posted 2016) [#13]
thanks grable, the first example did it! awesome, problem solved :D


grable(Posted 2016) [#14]
Happy to help :) Note that i simplified the sample above, dont need that SetWindowLong after all.


RustyKristi(Posted 2016) [#15]
ok got it thanks. :)


Kryzon(Posted 2016) [#16]
Nice stuff grable.