Direct write or draw on desktop
Direct write or draw on desktop
Hi guys,
what is the easiest way? I don’t need any window, only write or draw directly. Is it possible?
what is the easiest way? I don’t need any window, only write or draw directly. Is it possible?
Last edited by nartex on Fri Mar 20, 2020 8:38 pm, edited 1 time in total.
Re: Direct write or draw on desktop
Do u have an example in another language? - if yes, its possible.nartex wrote:i guys,
what is the easiest way? I don’t need any window, only write or draw directly. Is it possible?
Re: Direct write or draw on desktop
Hi nartex
You are asking in the wrong forum
But until some MOD will move it to Coding Questions the answer is yes
You are asking in the wrong forum
But until some MOD will move it to Coding Questions the answer is yes
Code: Select all
hdc = CreateDC_("DISPLAY", 0, 0, 0)
If hdc
BeginPath_(hdc)
Rectangle_(hdc,100,100,210,210)
Arc_(hdc,220,100,320,210,0,90,0,90)
EndPath_(hdc)
OldPen = GetCurrentObject_(hdc,#OBJ_PEN)
NewPen = CreatePen_(#PS_SOLID,10,$0000FF)
SelectObject_(hdc,NewPen)
StrokePath_(hdc)
EndIf
Egypt my love
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Direct write or draw on desktop
I assume you'd like to use PureBasic drawing commands to draw to the desktop. This can be accomplished in a straightforward and easy way with just a couple of API calls. Here is the method:
1. Create a transparent image to serve as the drawing surface
2. Draw whatever you like to this surface
3. Open a borderless window to host the surface
4. Apply the 'Layered' extended style to the window
5. Blit the image to the window
5. If desired, provide the ability to move the image around on the desktop or close it
Code Example:
Remember, everything in the Windows Operating System is a window. If you use a window for your output it will be persistent and well-behaved on your desktop. Trying to draw directly to the desktop without using a window is folly. It would be like running into a grocery store, grabbing an item off the checkout counter and running like hell. It just goes against all of the structure and order of things.
1. Create a transparent image to serve as the drawing surface
2. Draw whatever you like to this surface
3. Open a borderless window to host the surface
4. Apply the 'Layered' extended style to the window
5. Blit the image to the window
5. If desired, provide the ability to move the image around on the desktop or close it
Code Example:
Code: Select all
; Another entry in an endless string of useless programs by netmaestro
CreateImage(0,320,320,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
VectorSourceColor(RGBA(255,0,0,255))
AddPathCircle(120,120, 70)
StrokePath(6)
VectorSourceColor(RGBA(0,0,255,255))
AddPathBox(120,80,100,80)
StrokePath(6)
VectorSourceColor(RGBA(0,0,255,60))
AddPathCircle(120,120,68,-38,38)
AddPathBox(120,80,57,80)
FillPath(#PB_Path_Winding)
StopVectorDrawing()
Procedure BlitWindow(window, image)
hDC = StartDrawing(ImageOutput(image))
With sz.SIZE
\cx = ImageWidth(image)
\cy = ImageHeight(image)
EndWith
With BlendMode.BLENDFUNCTION
\SourceConstantAlpha = 255
\AlphaFormat = 1
EndWith
UpdateLayeredWindow_(WindowID(window),0,0,@sz,hDC,@ContextOffset.POINT,0,@BlendMode,2)
StopDrawing()
EndProcedure
OpenWindow(0,0,0,320,320,"Gdiplus Drawing",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
CreatePopupMenu(0)
MenuItem(9, "Exit")
BlitWindow(0, 0)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #WM_LBUTTONDOWN
SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case #PB_Event_Menu
If EventMenu()=9 : End : EndIf
Case #WM_RBUTTONDOWN
DisplayPopupMenu(0, WindowID(0))
EndSelect
Until EventID = #PB_Event_CloseWindow
BERESHEIT
Re: Direct write or draw on desktop
netmaestro wrote:It would be like running into a grocery store, grabbing an item off the checkout counter and running like hell.

That's just normal shopping practice in some parts of Scotland.
Proud supporter of PB! * Musician * C64/6502 Freak
-
- Enthusiast
- Posts: 225
- Joined: Sat Jul 07, 2018 6:50 pm
Re: Direct write or draw on desktop
Btw, why not GetDC_(0)?RASHAD wrote:Code: Select all
hdc = CreateDC_("DISPLAY", 0, 0, 0)
Tell me more about the advantages.
Re: Direct write or draw on desktop
Hi Everything
You do not want to mess with the DeskTop device context
After all we should finish our work in a proper way
With CreateDC_(?) end the code with DeleteDC_(?) (Good practice)
With GetDC_(?) end the code with ReleaseDC_(hWnd,hDC)
You do not want to mess with the DeskTop device context
After all we should finish our work in a proper way
With CreateDC_(?) end the code with DeleteDC_(?) (Good practice)
With GetDC_(?) end the code with ReleaseDC_(hWnd,hDC)
Code: Select all
hIcon = ExtractIcon_(#Null,"shell32.dll",55)
AddSysTrayIcon(0,GetDesktopWindow_(), hIcon)
SysTrayIconToolTip(0,"Draw to DeskTop")
hdc = CreateDC_("DISPLAY", 0, 0, 0)
Repeat
If hdc
Delay(100)
BeginPath_(hdc)
Rectangle_(hdc,100,100,210,210)
Arc_(hdc,220,100,320,210,0,90,0,90)
EndPath_(hdc)
OldPen = GetCurrentObject_(hdc,#OBJ_PEN)
NewPen = CreatePen_(#PS_SOLID,10,$0000FF)
SelectObject_(hdc,NewPen)
StrokePath_(hdc)
EndIf
x + 1
Until x > 100
DeleteDC_(hdc)
;SHChangeNotify_($8000000, $1000, 0, 0)
SendMessageTimeout_(#HWND_BROADCAST,#WM_SETTINGCHANGE,0, 0,#SMTO_ABORTIFHUNG,10,dwResult)
Egypt my love
Re: Direct write or draw on desktop
I am using the code posted by Rashad to draw on the desktop. I am using PureBasic 6.20 (x64) on Windows 11 with the compiler option "Enable DPI aware executable enabled".
Sometimes the area inside the shapes is transparent and at other times the area inside the shapes is black. Is there a way of ensuring that the area in the shape is always transparent?
Sometimes the area inside the shapes is transparent and at other times the area inside the shapes is black. Is there a way of ensuring that the area in the shape is always transparent?
Re: Direct write or draw on desktop
Sorry, I cannot help you with that.
BTW: I always take a transparent window, place it on the z-axis (e.g. behind the icons) and then draw in it.
OFF-TOPIC: Why do I see this "MR. GREEN" Smily on the picture (first column) in the overview list? Sorry again for off-topic.
/OFF-TOPIC
BTW: I always take a transparent window, place it on the z-axis (e.g. behind the icons) and then draw in it.
OFF-TOPIC: Why do I see this "MR. GREEN" Smily on the picture (first column) in the overview list? Sorry again for off-topic.

Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Direct write or draw on desktop
I was wondering that, too.

Re: Direct write or draw on desktop
Its called "Topic Icon"
Normally it's disabled, but you can put one if you are use the phpBB API (HTML POST) directly or over another Program.
Maybe he had a browser Addon or use this while fred upgraded/configured the board. (the to many request problem)
Normally it's disabled, but you can put one if you are use the phpBB API (HTML POST) directly or over another Program.
Maybe he had a browser Addon or use this while fred upgraded/configured the board. (the to many request problem)
Re: Direct write or draw on desktop
There is source code for this on the forum but you need to search for it.
I made a lib for this a while back: https://www.purebasic.fr/english/viewtopic.php?t=77538
I made a lib for this a while back: https://www.purebasic.fr/english/viewtopic.php?t=77538