Creating an application with no taskbar icon

Does anyone know how to create an application that will not show a taskbar icon when run in WIndows?

This post mentions the right API calls to build the declares needed http://www.devx.com/vb2themax/Tip/18334

[code]The ShowInTaskbar property lets you decide whether a form is visible in Windows taskbar or not. However, this property is read-only at runtime, so it seems that you can’t change this setting while the program is running. Luckly, you just need to change the window’s style, using a pair of API functions, and you can stuff all the code in just one line:

Private Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_APPWINDOW = &H40000

Private Sub Form_Load()
’ hide this form from the taskbar
SetWindowLong Me.hWnd, GWL_EXSTYLE, (GetWindowLong(hWnd, _
GWL_EXSTYLE) And Not WS_EX_APPWINDOW)
End Sub
The next example demonstate that you can use the same approach to force a form to display itself in the taskbar:

Private Sub Form_Load()
’ show this form on the taskbar
SetWindowLong Me.hWnd, GWL_EXSTYLE, (GetWindowLong(hWnd, _
GWL_EXSTYLE) Or WS_EX_APPWINDOW)
End Sub
Notice that changing the form’s style in this way works only when the form hasn’t become visible yet, so you should put this code in the Form_Load event procedure.[/code]

Now this is VB code and it need to be translated to Xojo, but the important thing is to know where to look.

Here are the descriptions on the Microsoft Developer Network :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx

This might do it…

[code]Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (hWnd As Integer, nIndex As Integer) As Integer
Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (hWnd As integer, nIdex As integer, dwNewLong As Integer) As Integer

DIM t_dwNewLong As Integer = GetWindowLong(self.Handle, -20) AND NOT &H40000 // hide
’ DIM t_dwNewLong As Integer = GetWindowLong(self.Handle, -20) OR &H40000 // show

DIM t_result As Integer = SetWindowLong(self.Handle, -20, t_dwNewLong)[/code]

Thanks Guys,

I already have tried the mentioned solution, but it doesn’t seem to work. I need to know in which form event this code should work within Xojo?

Thanks,

[quote=110857:@shao sean]This might do it…

[code]Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (hWnd As Integer, nIndex As Integer) As Integer
Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (hWnd As integer, nIdex As integer, dwNewLong As Integer) As Integer

DIM t_dwNewLong As Integer = GetWindowLong(self.Handle, -20) AND NOT &H40000 // hide
’ DIM t_dwNewLong As Integer = GetWindowLong(self.Handle, -20) OR &H40000 // show

DIM t_result As Integer = SetWindowLong(self.Handle, -20, t_dwNewLong)[/code][/quote]

I tried that in the window Open event, but it does not work :frowning:

But I tried under Windows 8.1 Pro 64 bit, and reading the Msdn description of SetWindowLong again, I just noticed these calls should no longer used.

Here is the link to SetWindowLong http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=vs.85).aspx

I think another reason the code does not work is that in order to hide, it seems from the VB code one must call SetWindowLong and not GetWindowLong.

Never mind. I tried to use SetWindowLongPtr and I get an error “[quote]could not resolve function ‘SetWindowLongPtr’ in user 32[/quote]”. Strange, msdn says it is part of User32.lib and User32.dll…

And I should have remembered although I use Windows 64 bit, Xojo remains in 32 bit.

There is an interesting document on MSDN where I think they describe what to do to remove the taskbar button :
http://msdn.microsoft.com/en-us/library/windows/desktop/cc144179(v=vs.85).aspx

Managing Taskbar Buttons The Shell creates a button on the taskbar whenever an application creates a window that isn't owned. To ensure that the window button is placed on the taskbar, create an unowned window with the WS_EX_APPWINDOW extended style. To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window. The Shell will remove a window's button from the taskbar only if the window's style supports visible taskbar buttons. If you want to dynamically change a window's style to one that does not support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.

They recommend the window be invisible while the call is made to change the window style.

WS_EX_TOOLWINDOW is described here :
http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx#WS_EX_TOOLWINDOW

So instead of WS_EX_APPWINDOW = &H40000 we may have to use WS_EX_TOOLWINDOW = &h80L .

I will try to see if I can get anywhere with that…

Sometimes I wish Xojo for Windows took example from VB. In that language, a window has a property ShowInTaskBar that when set to False does exactly what the OP wants without need for declares :s

Got it :slight_smile:

Set the window as invisible in the inspector, then do :

[code]Sub Open()
'WS_EX_TOOLWINDOW = &h80
'Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (hWnd As Integer, nIndex As Integer) As Integer
Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (hWnd As integer, nIdex As integer, dwNewLong As Integer) As Integer

DIM t_result As Integer = SetWindowLong(self.Handle, -20,&h80)

me.visible = true
End Sub
[/code]

The taskbar icon never shows :slight_smile:

Hi Michel,

The code works greats great in Windows 7 64 bit environment.
Thanks for your help.

[quote=110968:@A Himmit]Hi Michel,

The code works greats great in Windows 7 64 bit environment.
Thanks for your help.[/quote]

You are welcome. And thanks to Shao Sean who posted the first draft of the Xojo declares without which I would not have been able to do it.

Off course. Thanks to all of you guys. Much appreciated.

Couldn’t you simply never open a window to have no icon and run completely in background?

:wink: