?
Solved

Write contents directly to desktop window

Posted on 2006-05-16
22
Medium Priority
?
237 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:dds110
  • 7
  • 6
  • 5
  • +2
22 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16693655

you could use active desktop, and then set a webpage as background and alter that
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16693789
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
0
 
LVL 8

Author Comment

by:dds110
ID: 16694670
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Accepted Solution

by:
List244 earned 1000 total points
ID: 16695580
DDs110, try this:

Add a timer (Timer1) and a picturebox (Picture1) to your form.  Paste the following code:

Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Picture1.AutoRedraw = True
Picture1.Visible = False
Picture1.ForeColor = vbRed
End Sub
Private Sub Timer1_Timer()
Picture1.Cls
Dim DW As Long, DC As Long
DW = GetDesktopWindow()
DC = GetWindowDC(DW)
BitBlt Picture1.hdc, 0, 0, 100, 100, DC, 0, 0, vbSrcCopy
Picture1.Print "Test"
BitBlt DC, 0, 0, 100, 100, Picture1.hdc, 0, 0, vbSrcCopy
ReleaseDC DW, DC
End Sub

This should do what you want.
0
 
LVL 10

Expert Comment

by:sakuya_su
ID: 16697594
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?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16698390
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.
0
 
LVL 8

Author Comment

by:dds110
ID: 16698681
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16698737
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.
0
 
LVL 8

Expert Comment

by:List244
ID: 16700029
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.
0
 
LVL 8

Author Comment

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

Thanks
0
 
LVL 8

Expert Comment

by:List244
ID: 16701266
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.
0
 
LVL 8

Author Comment

by:dds110
ID: 16737182
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
0
 
LVL 8

Expert Comment

by:List244
ID: 16737189
Thanks for the update.
0
 
LVL 8

Author Comment

by:dds110
ID: 16776882
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
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16776913

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
0
 
LVL 8

Expert Comment

by:List244
ID: 16776944
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.
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16776972
>>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
0
 
LVL 8

Expert Comment

by:List244
ID: 16776978
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.
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16776992
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
0
 
LVL 8

Expert Comment

by:List244
ID: 16777006
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.
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16777044
>>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....
0
 
LVL 8

Author Comment

by:dds110
ID: 16777572
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question