Link to home
Start Free TrialLog in
Avatar of dds110
dds110

asked on

Write contents directly to desktop window

Hi all,

How would I, using VB, write output (text mainly) directly to the desktop without having to modify the desktop background image?  Is that possible?

Thanks

dds
Avatar of Mark_FreeSoftware
Mark_FreeSoftware
Flag of Netherlands image


you could use active desktop, and then set a webpage as background and alter that
Avatar of Mike Tomlinson
Not the prettiest solution...

But here is how one way to output text directly onto the desktop at a specified location.

Option Explicit

Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () 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 Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Private Sub Timer1_Timer()
    Dim deskWnd As Long
    Dim desktopDC As Long
    Dim curTime As String
   
    deskWnd = GetDesktopWindow()
    desktopDC = GetWindowDC(deskWnd)
    curTime = Format(Now(), "hh:nn:ss")
    TextOut desktopDC, Screen.Width / Screen.TwipsPerPixelX / 2, Screen.Height / Screen.TwipsPerPixelY / 2, curTime, Len(curTime)
    ReleaseDC deskWnd, desktopDC
End Sub
Avatar of dds110
dds110

ASKER

Interesting code Idle_Mind.  Unfortunately, the area behind the text is white.  Not exactly what I was looking for but still interesting.

Mark_FreeSoftware,

Active desktop was my first consideration but I need this to be as seemless as possible.  In other words, I need the user to still be able to choose whatever background image they want.  

Win 98 had a feature where you could display the version of windows on the desktop.  The text was black, the background was transparent, and it didn't mess with the users preferred background image.  That's what I'm after.

Thanks for the help, any other suggestions?
ASKER CERTIFIED SOLUTION
Avatar of List244
List244

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you could get the current desktop image, make ur own copy of it, tell your program to put whatever text you want and then set the desktop background to your program' copy of thta image?
That's exactly what List244s code is doing.  He is using the BitBlt() API to copy a small section of the desktop to a PictureBox.  Then he draws text on top of that and BitBlts the changed image back to the desktop.
Avatar of dds110

ASKER

Just read the recent posts.  I'm not sure if a picture box would do the trick as it would need to be "Click-Through".  I've done this type of thing before with a form and set it's background to transparent using API's and it works.  I was hoping to do something simialar except straight to the desktop.
Well...the PictureBox in this case is just used to "hold" the image of the desktop so you can draw on top of it and copy it back.  You aren't actually putting the PictureBox over the spot where the text is drawn on the desktop.  This would not interfere with clicks in that region.

The problem with using a "transparent" form would be that the form itself would capture the clicks and not the desktop.
DDS, try the code I gave you, all you need to do is put a timer, and a picturebox, then paste the code.
I have written the code to set up all the properties for you.  Try it out and see if it works for you.  It is
just like Idle_Mind's code, except that it will not have a white background.
Avatar of dds110

ASKER

Ok List244.  I'll have to try it out tonight since I don't have VB available to me at work.

Thanks
You're welcome, it should be what you want, if there is a problem with it, let us know, I am sure we can help.
Avatar of dds110

ASKER

I haven't forgotten about this Q, i've been a bit busy.  I should get around to trying out List244's suggestion sometime tonight or tomorrow night.

dds
Thanks for the update.
Avatar of dds110

ASKER

Not exactly what I was looking for.  Then again, I'm not sure exactly what I'm looking for.  I'll definitley be diving more into this code though.

Thanks for the assist and the patience.

dds

if you just want to paint text on the desktop, try the code from this page:

http://www.vbaccelerator.com/home/VB/Tips/Get_The_Desktop_Device_Context/article.asp
Mark, that is the solution that Idle_mind had already given.

dds110, if you can perhaps say where it is lacking I can try to help improve it.  Otherwise good luck to you with that.
>>Mark, that is the solution that Idle_mind had already given.

with one little difference


the solution Idle_Mind gave, is creating a picture, putting text on the picture and putting that on the desktop

the solution i provided puts the text directly on the desktop
No, the solution I gave uses a picture. Idle Mind's is just like what you posted.  The difference between mine and that however,
is that mine does not have a white background nor any background for that matter.
Idle_Mind's solution:

BitBlt Picture1.hdc, 0, 0, 100, 100, DC, 0, 0, vbSrcCopy
'put the desktop (a part of it) in picturebox 1

Picture1.Print "Test"
'print the text "Test" in the upper left corner

BitBlt DC, 0, 0, 100, 100, Picture1.hdc, 0, 0, vbSrcCopy
'put the picture back at the desktop


vbAccelerator example:

DrawText hdc, "vbAccelerator", Len("vbAccelerator"), tR, 0
'draw the text directly on the desktop at a specified position


and it's not about the points i provide this example, just so he has some more reference,
i don't want points for this because it is indeed almost the same as Idle_Mind's solution
Again , that was my solution, not Idle Mind's.  And of course you wont get points, it is a closed question.

Idle Mind:

Option Explicit

Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () 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 Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Private Sub Timer1_Timer()
    Dim deskWnd As Long
    Dim desktopDC As Long
    Dim curTime As String
   
    deskWnd = GetDesktopWindow()
    desktopDC = GetWindowDC(deskWnd)
    curTime = Format(Now(), "hh:nn:ss")
    TextOut desktopDC, Screen.Width / Screen.TwipsPerPixelX / 2, Screen.Height / Screen.TwipsPerPixelY / 2, curTime, Len(curTime)
    ReleaseDC deskWnd, desktopDC
End Sub

Which has the same affect as your solution.  I just don't like when experts add input on an already solved problem, especially input
which does not help any further.  Too many times that is the cause of unfair splits, and certification for people that do not deserve it.
Even worse, most of the time they are too out for points that they do not even review what has already been offered.  In my opinion this
really brings down EE.
>>Which has the same affect as your solution.

ugh now i see it, i'm really tired i think...

sorry





>>Even worse, most of the time they are too out for points that they do not even review what has already been offered.
i don't care about the points, i tried to help....
Avatar of dds110

ASKER

Regardless, thanks to all of you.  I'm designing a desktop calendar (simply because I don't want to shell out big bucks for a commercial one).  I'm not sure If I want to go through the headache of writing text or going through the effort of a see through form with buttons.