Simple transparent sticky reminder message

Share your advanced PureBasic knowledge/code with the community.
OgreVorbis
User
User
Posts: 76
Joined: Thu Jan 16, 2020 10:47 pm

Simple transparent sticky reminder message

Post by OgreVorbis »

I just made a very short program to display reminders on my desktop. It hovers a transparent text string on an always on top window. It also uses a hidden window to disable the taskbar button. I call it OnTopMessage.exe. Yeah, it's kind of big and annoying, but that's the point, cause you'll finish what it says.
You can learn a few things from this even if you use it for a different purpose.

(Made for dark theme users. Size optimized for 1080p or 1200p monitor. Left-click to drag. Double click to terminate.)

Code: Select all

TheMessage.s = ""

If CountProgramParameters() <> 0
	For i = 0 To CountProgramParameters()
		TheMessage + ProgramParameter() + " "
	Next
EndIf

OpenWindow(0, 0, 0, 50, 50, "HiddenWindow", #PB_Window_Invisible)
OpenWindow(1, 0, 0, 1900, 66, "My Message", #PB_Window_BorderLess | #PB_Window_ScreenCentered, WindowID(0))
SetWindowColor(1, #Magenta)
SetWindowLong_(WindowID(1), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
SetLayeredWindowAttributes_(WindowID(1), #Magenta, 0, #LWA_COLORKEY)
StickyWindow(1, #True)

LoadFont(0, "Millenium BdEx BT", 28)
If TheMessage = "" : TheMessage = "Let out the cat!!!" : EndIf
TextGadget(0, 0, 0, 1900, 50, TheMessage)
SetGadgetFont(0, FontID(0))
SetGadgetColor(0, #PB_Gadget_FrontColor, #White)
SetGadgetColor(0, #PB_Gadget_BackColor, #Magenta)

Repeat
	Event = WaitWindowEvent(100)
	
	Select Event
		Case #WM_LBUTTONDOWN
			SendMessage_(WindowID(1), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
		Case #PB_Event_LeftDoubleClick
			Break
	EndSelect
ForEver
Launcher batch file to place in the same folder. I make a shortcut to it and place it in the windows quick launch taskbar so it's always accessible.

Code: Select all

@echo off
color 0b
echo ***************************
echo * Welcome to OnTopMessage *
echo ***************************
echo.
echo This program will display a draggable reminder message on your desktop.
echo.
set /p message=Enter your message:
start OnTopMessage.exe %message%
The font I'm using: https://drive.google.com/file/d/1YDElmZ ... RpmGg/view

It has a tiny glitch around the edges of the font. I guess they are antialiased and are blending with the magenta background. I chose this font because those artifacts make it look cool anyway.
My blog/software site: http://dosaidsoft.com/
User avatar
Blue
Addict
Addict
Posts: 863
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple transparent sticky reminder message

Post by Blue »

This isi very good, OgreVorbis !
I had been wondering how I could produce such a nice trick.
Thank you.

If I may, I'd like to humbly offer some suggestions :

Code: Select all

Case #WM_LBUTTONDOWN
   SetGadgetColor(0, #PB_Gadget_FrontColor, #Red)                ;<<——— addition
   SendMessage_(windowID(1), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
   SetGadgetColor(0, #PB_Gadget_FrontColor, #White)              ;<<——— addition
The above modifications simply add a visible cue that your little gem is being moved.

As for the artifacts, they simply disappear if you use, for hiding the background, a color just slightly different to the text color.
For instance,

Code: Select all

#textColor = $CED3D3              ;<<——— addition
#hideColor = #textColor-2         ;<<——— addition
provides a good effect. Of course; in your code, you'd have to replace #Magenta with #hideColor everywhere, and #White with #textColor.

Anyway, thanks for a good idea and an excellent contribution.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
Post Reply