• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Draw text on Windows desktop

Hello everyone.

How can I draw text directly on to the Windows desktop? Presumably there is an API function to do this?

  • 2
  • 2
1 Solution
no i don't think so, but you need to get the bmp file and then write on it, and refresh the desktop (I think).
yes it's possible(i did it), you need to use api functions, let me find my code samples. (desktop - is a window so you can use api functions to work with it).
mmmmmmmmm... seems true.
actually it should be true, not always you have a wallpaper.
found it ....
just add a commnad button name : cmdpaint and common dialog control - name : dialog

best books on api functions :

Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long

Private Sub cmdpaint_Click()
Dim sText As String
Dim x As Long
Dim y As Long
Dim lcolor As Long

sText = InputBox$("Give me the string")
Form1.Dialog.Action = 3
x = 100
y = 100

Call ShowText(x, y, sText)
End Sub

Public Sub ShowText(x As Long, y As Long, sText As String)
Dim lcolor As Long
Dim hdc As Long
Dim hW As Long
hW = GetDesktopWindow()
hdc = GetWindowDC(hW)
lcolor = SetTextColor(hdc, Form1.Dialog.Color) 'RGB(255, 0, 0))
Call TextOut(hdc, x, y, sText, Len(sText))
Call SetTextColor(hdc, lcolor)
Call ReleaseDC(hW, hdc)
End Sub
DapperDanAuthor Commented:
Thanks for that. That works great. :o)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now