CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2011
    Posts
    6

    Question how to hide application icon from windows Task bar

    I am opening another application (e.g Notepad) from my VB program. I need to hide the TaskBar icon. I dont want it it the system Tray. I was checking the ShowWindow and SetWindowPos API funtions but both of them hide the icon as well as the actual application from screen. I only want to hide the icon from task bar. Below is the code that i used for testing:
    ---------------------------------------------------------------------------------
    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private 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
    Private Const SWP_SHOWWINDOW = &H40
    Private Const SWP_HIDEWINDOW = &H80
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOACTIVATE = &H10
    Private Const SW_HIDE = 0
    Private Const SW_SHOW = 5

    Sub HideMyApp()
    Dim hwd As Long

    hwd = FindWindow(vbNullString, "Untitled - Notepad")
    If hwd > 0 Then
    'ShowWindow hwd, SW_HIDE
    SetWindowPos hwd, 1, 0, 0, 0, 0, SWP_HIDEWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    End If
    End Sub

    Sub ShowMyApp()
    Dim hwd As Long
    hwd = FindWindow(vbNullString, "Untitled - Notepad")
    If hwd > 0 Then
    'ShowWindow hwd, SW_SHOW
    SetWindowPos hwd, 1, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    End If
    End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to hide application icon from windows Task bar

    Sure you mean NOTEPAD?

    Why try to hide from the taskbar, when C-A-D brings it up? And, before you ask the next question...

    Please explain your actions a little better.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2011
    Posts
    6

    Arrow Re: how to hide application icon from windows Task bar

    NOTEPAD was just an example.

    I just need to remove the icon of the application from task bar. C-A-D is not a problem here.
    I am NOT trying to hide the application permenantly. The application will be running on the screen but only no icon in the taskbar. I also dont want to hide/remove taskbar as i need to access other applications.

    So does anyone know how to remove the application icon from Taskbar without hiding the application itself?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to hide application icon from windows Task bar

    Just making sure. Here's some code that I had:

    Code:
    Option Explicit
    
    ' Add: 1 imagelist, 1 picturebox, 1 command button
    ' JCIS
    
    Private Type NotifyIconData
        Size              As Long
        Handle            As Long
        ID                As Long
        Flags             As Long
        CallBackMessage   As Long
        Icon              As Long
        Tip               As String * 64
    End Type
    
    Private Declare Function Shell_NotifyIcon _
        Lib "shell32" Alias "Shell_NotifyIconA" ( _
        ByVal Message As Long, Data As NotifyIconData) As Boolean
    
    Private Const AddIcon = &H0
    Private Const ModifyIcon = &H1
    Private Const DeleteIcon = &H2
    Private Const WM_MOUSEMOVE = &H200
    Private Const WM_LBUTTONDBLCLK = &H203
    Private Const MessageFlag = &H1
    Private Const IconFlag = &H2
    Private Const TipFlag = &H4
    
    Private Data      As NotifyIconData
    Private mNumTray  As Long 'Just to add a number
    
    Private Sub Command1_Click()
        Randomize
        Picture1.Cls
        Picture1.BackColor = vbBlue * Rnd(10000)
        Picture1.ForeColor = vbWhite * Rnd(10000)
        mNumTray = mNumTray + 1
        Picture1.Print CStr(mNumTray)
        ImageList1.ListImages.Remove 1
        ImageList1.ListImages.Add 1, , Picture1.Image
        AddIconToTray (ModifyIcon)
    End Sub
    
    Private Sub Form_Load()
        mNumTray = 0
        Picture1.ScaleMode = vbPixels
        Picture1.AutoRedraw = True
        Picture1.Width = 1200
        Picture1.Height = 1200
        Picture1.BackColor = vbBlue
        Picture1.ForeColor = vbWhite
        Picture1.Font.Size = 52
        Picture1.CurrentX = 10
        Picture1.CurrentY = 1
        Picture1.Print CStr(mNumTray)
        ImageList1.ListImages.Add 1, , Picture1.Image
        AddIconToTray (AddIcon)
        Visible = False
    End Sub
    
    Private Sub Form_Terminate()
        DeleteIconFromTray
    End Sub
    
    Private Sub AddIconToTray(pEvent As Long)
        Data.Size = Len(Data)
        Data.Handle = hWnd
        Data.ID = vbNull
        Data.Flags = IconFlag Or TipFlag Or MessageFlag
        Data.CallBackMessage = WM_MOUSEMOVE
        Data.Icon = ImageList1.ListImages(1).ExtractIcon
        Data.Tip = "Dynamic Systray Icon" & vbNullChar
        Call Shell_NotifyIcon(pEvent, Data)
    End Sub
    
    Private Sub DeleteIconFromTray()
        Call Shell_NotifyIcon(DeleteIcon, Data)
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, _
            Shift As Integer, X As Single, Y As Single)
        
        Dim Message As Long
        Message = X / Screen.TwipsPerPixelX
        
        Picture1.BackColor = ImageList1.MaskColor
        Select Case Message
            Case WM_LBUTTONDBLCLK
                Visible = Not Visible
                WindowState = Abs(Not Visible)
        End Select
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jan 2011
    Posts
    6

    Red face Re: how to hide application icon from windows Task bar

    Thanks for your code but this does not solve my problem. The example moves the icon from task bar to system tray. My requirement is to show no icon anywhere on screen.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to hide application icon from windows Task bar

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jan 2011
    Posts
    6

    Unhappy Re: how to hide application icon from windows Task bar

    I did test the code before replying. The code you sent moves the Program icon from TASKBAR to SYSTEM TRAY (task bar status area)....

    The Shell_NotifyIcon API does this and beow is the definintion from the link:
    "Sends a message to the system to add, modify, or delete an icon from the taskbar status area"

    My requirement again is NOT to move the program icon from TASKBAR to SYSTEM TRAY (task bar status area) but show NO ICON in any area of screen while keep the application interface available for user interation...

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to hide application icon from windows Task bar

    Create a SERVICE and deploy that?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jan 2011
    Posts
    6

    Unhappy Re: how to hide application icon from windows Task bar

    Thanks for the suggestion but I can make my VB program as service but this wont help since i need to call other 3rd party exe file which cant be changed to a service.

    For example if iam calling a notepad.exe from my VB program then i can not change the Notepad.exe to a service.

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to hide application icon from windows Task bar

    Well, I'm glad you can't install (and then HIDE) a program on MY pc...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Jan 2011
    Posts
    6

    Exclamation Re: how to hide application icon from windows Task bar

    I failed to understand this comment "Well, I'm glad you can't install (and then HIDE) a program on MY pc... " and how it relates to my question........ I CAN install any program on my computer and i DONT WANT TO HIDE the program itself...I just need to get rid of program icon of the target exe file from task bar...

    I think there is no solution for this...

Tags for this Thread

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

Featured