Program appears on each Windows 11 desktop, when run?

Just starting out? Need help? Post your questions and find answers here.
davidow
User
User
Posts: 10
Joined: Mon Mar 20, 2023 7:34 am
Location: Uttoxeter, UK

Program appears on each Windows 11 desktop, when run?

Post by davidow »

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.
User avatar
idle
Always Here
Always Here
Posts: 5956
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Program appears on each Windows 11 desktop, when run?

Post by idle »

Do you mean virtual desktops or multiple monitors?
davidow
User
User
Posts: 10
Joined: Mon Mar 20, 2023 7:34 am
Location: Uttoxeter, UK

Re: Program appears on each Windows 11 desktop, when run?

Post by davidow »

@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.
User avatar
idle
Always Here
Always Here
Posts: 5956
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Program appears on each Windows 11 desktop, when run?

Post by idle »

Doesn't appear to be a clear way on windows 10 and 11 that I can see.
davidow
User
User
Posts: 10
Joined: Mon Mar 20, 2023 7:34 am
Location: Uttoxeter, UK

Re: Program appears on each Windows 11 desktop, when run?

Post by davidow »

@idle,
Thank you very much for taking the trouble to check this. :D
I'll have to continue doing it by the long way; by right-clicking on the icon in the task view. :)
User avatar
Michael Vogel
Addict
Addict
Posts: 2812
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Program appears on each Windows 11 desktop, when run?

Post by Michael Vogel »

Try this...

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
More functionality needs a dll for now, e.g. from here ...

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
davidow
User
User
Posts: 10
Joined: Mon Mar 20, 2023 7:34 am
Location: Uttoxeter, UK

Re: Program appears on each Windows 11 desktop, when run?

Post by davidow »

@Michael Vogel,
Thank you, Michael, I'll take a look at this and try it out when I eventually understand it!
davidow
User
User
Posts: 10
Joined: Mon Mar 20, 2023 7:34 am
Location: Uttoxeter, UK

Re: Program appears on each Windows 11 desktop, when run?

Post by davidow »

@Michael Vogel,
Both example work fine. Thank you. :D

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?
User avatar
Michael Vogel
Addict
Addict
Posts: 2812
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Program appears on each Windows 11 desktop, when run?

Post by Michael Vogel »

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 :lol:

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
Post Reply