Is it possible to code a PureBasic program to open on each desktop, automatically?
If so, please, show me how!
I've checked past coding questions but have not been able to find help thee.
Program appears on each Windows 11 desktop, when run?
Re: Program appears on each Windows 11 desktop, when run?
Do you mean virtual desktops or multiple monitors?
Re: Program appears on each Windows 11 desktop, when run?
@idle,
Thank you for the reply.
Oops!. I meant the virtual desktops.
Currently I populate each desktop when I remember. It would be nice to make it automatic.
Thank you for the reply.
Oops!. I meant the virtual desktops.
Currently I populate each desktop when I remember. It would be nice to make it automatic.
Re: Program appears on each Windows 11 desktop, when run?
Doesn't appear to be a clear way on windows 10 and 11 that I can see.
Re: Program appears on each Windows 11 desktop, when run?
@idle,
Thank you very much for taking the trouble to check this.
I'll have to continue doing it by the long way; by right-clicking on the icon in the task view.
Thank you very much for taking the trouble to check this.

I'll have to continue doing it by the long way; by right-clicking on the icon in the task view.

- Michael Vogel
- Addict
- Posts: 2812
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Program appears on each Windows 11 desktop, when run?
Try this...
More functionality needs a dll for now, e.g. from here ...
Code: Select all
h=OpenWindow(0,0,0,400,400,"Hello Desktop")
SetWindowLong_(h,#GWL_EXSTYLE,GetWindowLong_(h,#GWL_EXSTYLE)|$00000080)
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
Code: Select all
If OpenLibrary(#Null,"VirtualDesktopAccessor.dll")
lib=#True
GetDesktopNumber=GetFunction(#Null,"GetCurrentDesktopNumber")
GetDesktopCount=GetFunction(#Null,"GetDesktopCount")
GetDesktopName= GetFunction(#Null,"GetDesktopName")
EndIf
h=OpenWindow(0,20,20,300,300,"Hello Desktop")
ButtonGadget(0,0,0,300,150,"Off")
ButtonGadget(1,0,150,300,150,"Desktop Info",#PB_Button_MultiLine)
on=0
PostEvent(#PB_Event_Gadget,0,0)
PostEvent(#PB_Event_Gadget,0,1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 0
v=GetWindowLong_(h,#GWL_EXSTYLE)
on!1
If on
v|128
Else
v&~128
EndIf
SetWindowLong_(h,#GWL_EXSTYLE,v)
SetGadgetText(0,"Window visible on all Desktops: O"+Mid("ffn",1+on<<1,2))
Case 1
If lib
vdact.l=CallFunctionFast(GetDesktopNumber)
vdcnt.l=CallFunctionFast(GetDesktopCount)
vdnam.s=Space(100)
vdlen.l=100
CallFunctionFast(GetDesktopName,vdact,@vdnam,@vdlen)
SetGadgetText(1,"Actual Desktop: "+Str(1+vdact)+" (total "+Str(vdcnt)+")"+#CRLF$+"Deaktop Name: "+PeekS(@vdnam,-1,#PB_UTF8))
EndIf
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Re: Program appears on each Windows 11 desktop, when run?
@Michael Vogel,
Thank you, Michael, I'll take a look at this and try it out when I eventually understand it!
Thank you, Michael, I'll take a look at this and try it out when I eventually understand it!
Re: Program appears on each Windows 11 desktop, when run?
@Michael Vogel,
Both example work fine. Thank you.
I notice that in both examples the icon on the taskbar disappears.
Is line 31 in the second example necessary? Because if 'commented out' it shows the icon on all desktops?
Both example work fine. Thank you.

I notice that in both examples the icon on the taskbar disappears.
Is line 31 in the second example necessary? Because if 'commented out' it shows the icon on all desktops?
- Michael Vogel
- Addict
- Posts: 2812
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Program appears on each Windows 11 desktop, when run?
This line 31 is doing the trick, it sets the window as a #WS_EX_TOOLWINDOW which is used for systray programs so you don't see an icon in the taskbar. When using this simple approach you'd better add an icon to the systray as well.
For a quick comfortable solution you've to download the library from github (see link in the source code)...
...until someone will convert the source code there and convert it to pure PB code
For a quick comfortable solution you've to download the library from github (see link in the source code)...
...until someone will convert the source code there and convert it to pure PB code

Code: Select all
; https://github.com/Ciantic/VirtualDesktopAccessor?tab=readme-ov-file
If OpenLibrary(#Null,"VirtualDesktopAccessor.dll")
lib=#True
SetDesktopNumber= GetFunction(#Null,"GoToDesktopNumber")
GetDesktopNumber= GetFunction(#Null,"GetCurrentDesktopNumber")
GetDesktopCount= GetFunction(#Null,"GetDesktopCount")
GetDesktopName= GetFunction(#Null,"GetDesktopName")
PinWindow= GetFunction(#Null,"PinWindow")
UnPinWindow= GetFunction(#Null,"UnPinWindow")
EndIf
on=0
h=OpenWindow(0,20,20,300,300,"Hello Desktop"+Left(" - Library loaded",lib<<10))
ButtonGadget(0,0,0,300,150,"-")
ButtonGadget(1,0,150,300,150,"No Info",#PB_Button_MultiLine)
PostEvent(#PB_Event_Gadget,0,0)
PostEvent(#PB_Event_Gadget,0,1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 0
on!1
If lib
If on
CallFunctionFast(PinWindow,h)
Else
CallFunctionFast(UnPinWindow,h)
EndIf
Else
v=GetWindowLong_(h,#GWL_EXSTYLE)
If on
v|128
Else
v&~128
EndIf
;SetWindowLong_(h,#GWL_EXSTYLE,v)
EndIf
SetGadgetText(0,"Window visible on all Desktops: O"+Mid("ffn",1+on<<1,2))
Case 1
If lib
vdact.l=CallFunctionFast(GetDesktopNumber)
vdcnt.l=CallFunctionFast(GetDesktopCount)
vdnam.s=Space(100)
vdlen.l=100
CallFunctionFast(GetDesktopName,vdact,@vdnam,@vdlen)
SetGadgetText(1,"Actual Desktop: "+Str(1+vdact)+" (total "+Str(vdcnt)+")"+#CRLF$+"Deaktop Name: "+PeekS(@vdnam,-1,#PB_UTF8))
EndIf
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver