Results 1 to 11 of 11

Thread: How to make a form stick to the desktop?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Question How to make a form stick to the desktop?

    Hi folks (correct to say so? I learned this in my english lesson in school ),

    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
    Attached Images Attached Images  

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367

    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

    VB Code:
    1. 'Put following in a module
    2. Public Declare Function SetWindowPos Lib "user32" _
    3.   (ByVal hwnd As Long, _
    4.   ByVal hWndInsertAfter As Long, _
    5.   ByVal x As Long, ByVal y As Long, _
    6.   ByVal cx As Long, ByVal cy As Long, _
    7.   ByVal wFlags As Long) As Long
    8.  
    9. Public Const SWP_NOMOVE = &H2
    10. Public Const SWP_NOSIZE = &H1
    11. Public Const HWND_TOPMOST = -1
    12. Public Const HWND_NOTOPMOST = -2
    13.  
    14. 'Following code is to be on a Form...
    15.  
    16. 'Place this in the Form_load:
    17. SetWindowPos hwnd, HWND_TOPMOST, _
    18.    0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    19.  
    20.  
    21. 'Place this in the Form_QueryUnload:
    22. SetWindowPos hwnd, HWND_NOTOPMOST, _
    23.    0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

    I think that should do it good luck!
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: How to make a form stick to the desktop?

    That looks like a nice application. 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.

  4. #4
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    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
    Attached Images Attached Images  

  6. #6
    Lively Member
    Join Date
    Mar 2006
    Posts
    70

    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..

  7. #7
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    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....

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. Option Explicit
    2. ' [b]Inside Form[/b]
    3. '================================================================
    4. Private Sub Form_Load()
    5.     'set the form as BottomMost ->
    6.     FormAlwaysAtBottom Me.hwnd
    7.     '
    8.     'set custom position/size ->
    9.     Me.Move Screen.Width - 6000, 100, 6000, 3000
    10.     '
    11.     ' Subclass the form ->
    12.     pOldWindPoc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WndProc)
    13. End Sub
    14. '==================================================================
    15. Private Sub Form_Unload(Cancel As Integer)
    16.     ' Un-subclass the form
    17.     SetWindowLong Me.hwnd, GWL_WNDPROC, pOldWindPoc
    18. End Sub
    VB Code:
    1. '[b]Inside a Module[/b]
    2. Option Explicit
    3. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    4.                 ByVal lpClassName As String, _
    5.                 ByVal lpWindowName As String) As Long
    6.                
    7. Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    8.                 ByVal hWnd1 As Long, _
    9.                 ByVal hWnd2 As Long, _
    10.                 ByVal lpsz1 As String, _
    11.                 ByVal lpsz2 As String) As Long
    12.                
    13. Public Declare Function SetParent Lib "user32" ( _
    14.                 ByVal hWndChild As Long, _
    15.                 ByVal hWndNewParent As Long) As Long
    16.  
    17. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    18.                           (ByVal lpPrevWndFunc As Long, _
    19.                            ByVal hwnd As Long, _
    20.                            ByVal msg As Long, _
    21.                            ByVal wParam As Long, _
    22.                             lParam As WINDOWPOS) As Long
    23.                            
    24. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    25.                           (ByVal hwnd As Long, _
    26.                            ByVal nIndex As Long, _
    27.                            ByVal dwNewLong As Long) As Long
    28.  
    29. Public Type WINDOWPOS
    30.     hwnd As Long
    31.     hWndInsertAfter As Long
    32.     x As Long
    33.     y As Long
    34.     cx As Long
    35.     cy As Long
    36.     flags As Long
    37. End Type
    38.  
    39. Public pOldWindPoc As Long ' A pointer to the old window procedure
    40.  
    41. Public Const GWL_WNDPROC& = (-4)
    42.  
    43. Public Const WM_WINDOWPOSCHANGING As Long = &H46
    44. Public Const SWP_NOMOVE As Long = &H2
    45.  
    46. ' Our new window procedure
    47. Public Function WndProc(ByVal hwnd As Long, _
    48.        ByVal uMsg As Long, _
    49.        ByVal wParam As Long, _
    50.        lParam As WINDOWPOS) As Long
    51.    
    52.     If uMsg = WM_WINDOWPOSCHANGING Then
    53.         lParam.flags = lParam.flags Or SWP_NOMOVE 'restrict form movement
    54.     End If
    55.    
    56.     ' Pass the message to original WinProc
    57.     WndProc = CallWindowProc(pOldWindPoc, hwnd, uMsg, wParam, lParam)
    58.      
    59. End Function
    60.  
    61. Public Sub FormAlwaysAtBottom(hwnd As Long)
    62.     ' Original code by Bushmobile
    63.     ' [url]http://www.vbforums.com/showpost.php?p=2420562&postcount=10[/url]
    64.     Dim ProgMan&, shellDllDefView&, sysListView&
    65.    
    66.     ProgMan = FindWindow("progman", vbNullString)
    67.     shellDllDefView = FindWindowEx(ProgMan&, 0&, "shelldll_defview", vbNullString)
    68.     sysListView = FindWindowEx(shellDllDefView&, 0&, "syslistview32", vbNullString)
    69.    
    70.     SetParent hwnd, sysListView
    71. 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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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.
    I don't understand, what's wrong with this: http://www.vbforums.com/showpost.php...4&postcount=24

    I tried it, it works....

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to make a form stick to the desktop?

    Quote Originally Posted by CVMichael
    I don't understand, what's wrong with this: http://www.vbforums.com/showpost.php...4&postcount=24

    I tried it, it works....
    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.
    Last edited by iPrank; Aug 25th, 2006 at 09:29 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: How to make a form stick to the desktop?

    Despite the PMs, I'll put this link in anyway...Form ALWAYS on Bottom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width