1 Attachment(s)
How to make a form stick to the desktop?
Hi folks (correct to say so? I learned this in my english lesson in school :p ),
I have developed a small utility that reads out my outlook calendar appointments and displays it on a four weeks calendar form (I attached a screenshot, does it work?). The form is part of the autostart and so whenever i boot my pc I get informed about my appointments (mainly soccer appointments, by the way). Theform has no boarder and so it looks like it sticks to the desktop, or like it is part of my wallpaper.
Now the problem: when I click on the desktop icon (left at the bottom of the screen, beneath the start button) my form disappears. But I want to have it stick there, whatever do. I know, there are programs which work as i want but I don't know how to code such a behaviour. Can someone help me?
Thanks, Gerd
Re: How to make a form stick to the desktop?
well when you click any icon on desktop you app. would lose the focus hence making it "dissapear" what you would like to do is always have it on top :) so add the following code to your project and it should stay on top always :p
VB Code:
'Put following in a module
Public Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
'Following code is to be on a Form...
'Place this in the Form_load:
SetWindowPos hwnd, HWND_TOPMOST, _
0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
'Place this in the Form_QueryUnload:
SetWindowPos hwnd, HWND_NOTOPMOST, _
0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
I think that should do it good luck! :wave:
Re: How to make a form stick to the desktop?
That looks like a nice application. :thumb: When you are done you could post the code in the UtilityBank. I know I'd be one of the people who'd be interested in it.
Re: How to make a form stick to the desktop?
i don't think he wants it always on top, it should be 'stuck to the desktop'
the reason it's disappearing must have to do with the way you're hiding the rest of your form.
this can probably be solved, but another option might be to have the program create an .html or even a .bmp file that reflects the wallpaper + the clander.
1 Attachment(s)
Re: How to make a form stick to the desktop?
Hi,
thanks for your help. In the meantime my little prog got a bit more completed. It now can navigate through the calendar using the buttons at the right (one week or one month back and forth and home to the current week). It now runs well, rather fast and the size of the exe is surprising 60 KB (less than 200 lines of VB code). It prints birthdays colored and important appointments in a definable color (both hard coded at the moment, not configurable).
But there are some problems left. First the "sticky" problem. Since the program window has no frame it cannot be moved to another place on the desktop. That's ok so far. But when I press the desktop icon near to the start button (see 1) it loses focus and disappears. But I want it to have stuck on the desktop, like part of the wallpaper (as dis1411 said, not topmost as ej12n said).
Another problem is that i use the label element of the MS Forms 2.0 Object Library because the standard label does always wrap and not truncate (see 2). And I heared that progs which do not use the standard lib may not be distributed freely.
A third problem is the dotted line at the navigation button (see 3). I dont want to have it anywhere. Furthermore I dont want to allow keyboard use anyway. All my buttons have TabStop = False but the dotted line doesnt disappear.
Any help out there?
Of course, I will post the code when I am ready.
So long, Gerd
Re: How to make a form stick to the desktop?
Hi.. almost after a year i came across this application of urs
infact i am working on building a smiliar one for my desktop too... (darn i am a year late)
do tell us if u have completed and sucessfully executed the application
i am trying to develop this in Vb 2005 express edition..
gr8 job..
Re: How to make a form stick to the desktop?
Just in case this hasn't been resolved yet, see the thread Behind Desktop icons....
Re: How to make a form stick to the desktop?
You can restrict a form's "movablity" either by setting "Movable=False" at desigintime or by subclassing the form and trapping WM_WINDOWPOSCHANGING message.
Here is a code in VB6:
VB Code:
Option Explicit
' [b]Inside Form[/b]
'================================================================
Private Sub Form_Load()
'set the form as BottomMost ->
FormAlwaysAtBottom Me.hwnd
'
'set custom position/size ->
Me.Move Screen.Width - 6000, 100, 6000, 3000
'
' Subclass the form ->
pOldWindPoc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
'==================================================================
Private Sub Form_Unload(Cancel As Integer)
' Un-subclass the form
SetWindowLong Me.hwnd, GWL_WNDPROC, pOldWindPoc
End Sub
VB Code:
'[b]Inside a Module[/b]
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Public Declare Function SetParent Lib "user32" ( _
ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
lParam As WINDOWPOS) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Type WINDOWPOS
hwnd As Long
hWndInsertAfter As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type
Public pOldWindPoc As Long ' A pointer to the old window procedure
Public Const GWL_WNDPROC& = (-4)
Public Const WM_WINDOWPOSCHANGING As Long = &H46
Public Const SWP_NOMOVE As Long = &H2
' Our new window procedure
Public Function WndProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
lParam As WINDOWPOS) As Long
If uMsg = WM_WINDOWPOSCHANGING Then
lParam.flags = lParam.flags Or SWP_NOMOVE 'restrict form movement
End If
' Pass the message to original WinProc
WndProc = CallWindowProc(pOldWindPoc, hwnd, uMsg, wParam, lParam)
End Function
Public Sub FormAlwaysAtBottom(hwnd As Long)
' Original code by Bushmobile
' [url]http://www.vbforums.com/showpost.php?p=2420562&postcount=10[/url]
Dim ProgMan&, shellDllDefView&, sysListView&
ProgMan = FindWindow("progman", vbNullString)
shellDllDefView = FindWindowEx(ProgMan&, 0&, "shelldll_defview", vbNullString)
sysListView = FindWindowEx(shellDllDefView&, 0&, "syslistview32", vbNullString)
SetParent hwnd, sysListView
End Sub
I don't know VB.NET.
Here is C# subclassing example written by me. There is a link to a VB.NET example.
For the "behind icon" stuff, I'm looking for the answer too. :D
Re: How to make a form stick to the desktop?
Quote:
Originally Posted by iPrank
For the "behind icon" stuff, I'm looking for the answer too. :D
I don't understand, what's wrong with this: http://www.vbforums.com/showpost.php...4&postcount=24
I tried it, it works....
Re: How to make a form stick to the desktop?
Quote:
Originally Posted by CVMichael
Oh..well...I was hoping to do without the html stuff.
edit:
As my code in the other thread works with webview, to apply it, we just need to enable ActiveDesktop. No ocx is needed. ;)
But I don't want to change user's desktop setting.
Re: How to make a form stick to the desktop?
Despite the PMs, I'll put this link in anyway...Form ALWAYS on Bottom :)