Results 1 to 13 of 13

Thread: [RESOLVED]Show Desktop

  1. #1

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Resolved [RESOLVED]Show Desktop

    Hi guys

    I want to show the dekstop by clicking a button.
    So everything is minimized
    Shell ("C:\blah\Show Desktop.scf") didn't work

    Thanx
    Last edited by Private_sub; Feb 17th, 2006 at 07:58 AM.

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Show Desktop

    no idea, but just give try to send keys of start menu key + d, this will show the desktop.
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Re: Show Desktop

    Good idea!
    I'll post my result

  4. #4

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Red face Re: Show Desktop

    How can I send the start menu/windows key??

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Show Desktop

    Try this
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    4.                                               ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    5. Private Const VK_CONTROL = &H11
    6. Private Const VK_ESCAPE = &H1B
    7. Private Const KEYEVENTF_KEYUP = &H2
    8.  
    9. Private Sub Command1_Click()
    10.     keybd_event VK_CONTROL, 0, 0, 0                 ' Press Control Key
    11.     keybd_event VK_ESCAPE, 0, 0, 0                  ' Press Escape Key
    12.     keybd_event VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0    ' Release Escape Key
    13.     keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0   ' Release Control Key
    14. End Sub

  6. #6

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Re: Show Desktop

    Hmm..
    That's Control and Escape.
    Do you also know something for the Windows key?
    Thanx

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Show Desktop

    you could enumerate all visible windows and minimize them with API

    Enumerate: EnumWindows
    Check if visible: IsWindowVisible
    And then minimze: ShowWindow
    Last edited by bushmobile; Feb 17th, 2006 at 07:32 AM.

  8. #8

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Re: Show Desktop

    Thnx people!

  9. #9
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Show Desktop

    Actually, it seems it's easier.
    Check out this code by Robdog888
    http://www.vbforums.com/showthread.php?t=360571

  10. #10

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Re: Show Desktop

    That rocks!
    Much easier! Thank you jcis (and Robdog)

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

    Re: Show Desktop

    When you click the "Show Desktop" button, explorer actually runs the Shell32.IShellDispatch4.ToggleDesktop() method.

    See the proper way to Programmatically Showing the Desktop (ToggleDesktop) and the VB.NET way.

    But it is not working in VB6.

    Add a reference to Microsoft Shell Control & Automation and in object browser it will showup. (check 'show hidden members'). But I'm unable to create an instance of IShellDispatch4 interface in VB6.

    Apart from the keybd_event method, you can try these,
    Idea 1 - Non-API
    VB Code:
    1. Option Explicit
    2. ' Add a reference to Microsoft Shell Control & Automation
    3. Dim MyShell As New Shell32.shell
    4.  
    5. Private Sub Command1_Click()
    6.     MyShell.MinimizeAll
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10.     MyShell.UndoMinimizeALL
    11. End Sub

    or better,
    Create a new .scf file (or use the default one) and use shell execute to call it.
    Idea 2 - ShellExecute API (better)
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" _
    4.     Alias "ShellExecuteA" _
    5.         (ByVal hwnd As Long, _
    6.          ByVal lpOperation As String, _
    7.          ByVal lpFile As String, _
    8.          ByVal lpParameters As String, _
    9.          ByVal lpDirectory As String, _
    10.          ByVal nShowCmd As Long) As Long
    11.          
    12. Const SW_SHOWNORMAL = 1
    13.  
    14. Private Sub Command1_Click()
    15.  
    16.     ShellExecute Me.hwnd, vbNullString, _
    17.                  App.Path & "\aaa.scf", _
    18.                  vbNullString, "C:\", SW_SHOWNORMAL
    19. End Sub
    Last edited by iPrank; Feb 17th, 2006 at 08:32 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


  12. #12

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Re: [RESOLVED]Show Desktop

    That's even better
    Maybe you can add it to the Codebank?

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

    Re: [RESOLVED]Show Desktop

    Just an update.

    This works in VB6/VBScript:
    vb Code:
    1. Private Sub Command1_Click()
    2.         Dim objShell
    3.        
    4.         Set objShell = CreateObject("Shell.Application")
    5.             objShell.ToggleDesktop
    6.         Set objShell = Nothing
    7. End Sub
    http://msdn2.microsoft.com/en-us/library/ms630442.aspx
    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


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