Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to show/hide a button on the taskbar?

Posted on 1999-07-22
10
Medium Priority
?
1,015 Views
Last Modified: 2013-11-20
I have a Dialog based application.  I made a System Tray Icon and I am now trying to remove its icon from the taskbar.

I can do this for a SDI Application, but it dosn't work for a Dialog based application.

Please help!!
0
Comment
Question by:stormp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 1

Expert Comment

by:Whale
ID: 1311039
override the DestroyWindow
BOOL CDlgYourApp::DestroyWindow()
{
              NOTIFYICONDATA tnid;
      tnid.cbSize = sizeof(NOTIFYICONDATA);
      tnid.hWnd = AfxGetApp()->m_pMainWnd->m_hWnd;
      tnid.uID = ID_ICON_SYSTRAY;
      Shell_NotifyIcon(NIM_DELETE, &tnid);

      return CDialog::DestroyWindow();
}

0
 

Expert Comment

by:sirrewob
ID: 1311040
Not sure want to you want to do?

If its removing the icon from the system tray then the example provided by Whale is correct, but if its to remove the applications button from the taskbar then thats a different matter.
0
 

Author Comment

by:stormp
ID: 1311041
> Not sure want to you want to do?
> If its removing the icon from the system tray then the example provided by Whale
> is correct, but if its to remove the applications button from the taskbar then thats
> a different matter.

I need to remove the applications button from the taskbar and still have the window open on the desktop.

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!

 

Expert Comment

by:sirrewob
ID: 1311042
I have the answer for this, but it's a bit difficult and long winded. Not sure if this is the only answer, but I use it and I haven't seen any other solutions.

The method is based on using the ITaskBarList interface, and its corresponding methods, DeleteTab and AddTab. The only problem is that there is no documentation or header files, so you have to create your own.

Please read carfully and i'll try and explain.

1) Add the following to the head of the cpp file that will control the taskbar.
#include "taskbarlist.h"

2) Create taskbarlist.h and add the following.

/* this ALWAYS GENERATED file contains the definitions for the interfaces */


/* File created by MIDL compiler version 5.01.0164 */
/* at Wed Nov 11 14:48:42 1998
 */
/* Compiler settings
    Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: allocation ref bounds_check enum stub_data
*/
//@@MIDL_FILE_HEADING(  )


/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 440
#endif

#include "rpc.h"
#include "rpcndr.h"

#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__

#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/

#ifndef __ITaskbarList_h__
#define __ITaskbarList_h__

#ifdef __cplusplus
extern "C"{
#endif

/* Forward Declarations */

#ifndef __ITaskbarList_FWD_DEFINED__
#define __ITaskbarList_FWD_DEFINED__
typedef interface ITaskbarList ITaskbarList;
#endif       /* __ITaskbarList_FWD_DEFINED__ */


/* header files for imported files */
#include "oaidl.h"
#include "oleidl.h"

void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void __RPC_FAR * );

#ifndef __ITaskbarList_INTERFACE_DEFINED__
#define __ITaskbarList_INTERFACE_DEFINED__

/* interface ITaskbarList */
/* [unique][uuid][object][local] */


EXTERN_C const IID IID_ITaskbarList;

#if defined(__cplusplus) && !defined(CINTERFACE)
   
    MIDL_INTERFACE("BD4FAF8A-E047-11D2-9BC0-0004ACB296D8")
    ITaskbarList : public IUnknown
    {
    public:
        virtual HRESULT STDMETHODCALLTYPE ActivateTab(
            /* [in] */ HWND hWnd) = 0;
       
        virtual HRESULT STDMETHODCALLTYPE AddTab(
            /* [in] */ HWND hWnd) = 0;
       
        virtual HRESULT STDMETHODCALLTYPE DeleteTab(
            /* [in] */ HWND hWnd) = 0;
       
        virtual HRESULT STDMETHODCALLTYPE HrInit( void) = 0;
       
        virtual HRESULT STDMETHODCALLTYPE SetActiveAlt(
            /* [in] */ HWND hWnd) = 0;
       
    };
   
#else       /* C style interface */

    typedef struct ITaskbarListVtbl
    {
        BEGIN_INTERFACE
       
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )(
            ITaskbarList __RPC_FAR * This,
            /* [in] */ REFIID riid,
            /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
       
        ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )(
            ITaskbarList __RPC_FAR * This);
       
        ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )(
            ITaskbarList __RPC_FAR * This);
       
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ActivateTab )(
            ITaskbarList __RPC_FAR * This,
            /* [in] */ HWND hWnd);
       
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *AddTab )(
            ITaskbarList __RPC_FAR * This,
            /* [in] */ HWND hWnd);
       
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *DeleteTab )(
            ITaskbarList __RPC_FAR * This,
            /* [in] */ HWND hWnd);
       
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *HrInit )(
            ITaskbarList __RPC_FAR * This);
       
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *SetActiveAlt )(
            ITaskbarList __RPC_FAR * This,
            /* [in] */ HWND hWnd);
       
        END_INTERFACE
    } ITaskbarListVtbl;

    interface ITaskbarList
    {
        CONST_VTBL struct ITaskbarListVtbl __RPC_FAR *lpVtbl;
    };

   

#ifdef COBJMACROS


#define ITaskbarList_QueryInterface(This,riid,ppvObject)      \
    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)

#define ITaskbarList_AddRef(This)      \
    (This)->lpVtbl -> AddRef(This)

#define ITaskbarList_Release(This)      \
    (This)->lpVtbl -> Release(This)


#define ITaskbarList_ActivateTab(This,hWnd)      \
    (This)->lpVtbl -> ActivateTab(This,hWnd)

#define ITaskbarList_AddTab(This,hWnd)      \
    (This)->lpVtbl -> AddTab(This,hWnd)

#define ITaskbarList_DeleteTab(This,hWnd)      \
    (This)->lpVtbl -> DeleteTab(This,hWnd)

#define ITaskbarList_HrInit(This)      \
    (This)->lpVtbl -> HrInit(This)

#define ITaskbarList_SetActiveAlt(This,hWnd)      \
    (This)->lpVtbl -> SetActiveAlt(This,hWnd)

#endif /* COBJMACROS */


#endif       /* C style interface */



HRESULT STDMETHODCALLTYPE ITaskbarList_ActivateTab_Proxy(
    ITaskbarList __RPC_FAR * This,
    /* [in] */ HWND hWnd);


void __RPC_STUB ITaskbarList_ActivateTab_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);


HRESULT STDMETHODCALLTYPE ITaskbarList_AddTab_Proxy(
    ITaskbarList __RPC_FAR * This,
    /* [in] */ HWND hWnd);


void __RPC_STUB ITaskbarList_AddTab_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);


HRESULT STDMETHODCALLTYPE ITaskbarList_DeleteTab_Proxy(
    ITaskbarList __RPC_FAR * This,
    /* [in] */ HWND hWnd);


void __RPC_STUB ITaskbarList_DeleteTab_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);


HRESULT STDMETHODCALLTYPE ITaskbarList_HrInit_Proxy(
    ITaskbarList __RPC_FAR * This);


void __RPC_STUB ITaskbarList_HrInit_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);


HRESULT STDMETHODCALLTYPE ITaskbarList_SetActiveAlt_Proxy(
    ITaskbarList __RPC_FAR * This,
    /* [in] */ HWND hWnd);


void __RPC_STUB ITaskbarList_SetActiveAlt_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);



#endif       /* __ITaskbarList_INTERFACE_DEFINED__ */


_COM_SMARTPTR_TYPEDEF(ITaskbarList, __uuidof(ITaskbarList));

/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */

#ifdef __cplusplus
}
#endif

#endif

3) Create a RGS file called TaskBarList.rgs and add the following.

HKCR
{
      FTPSubUI.TaskBarList.1 = s 'TaskBarList Class'
      {
            CLSID = s '{15454908-E047-11D2-9BC0-0004ACB296D8}'
      }
      FTPSubUI.TaskBarList = s 'TaskBarList Class'
      {
            CLSID = s '{15454908-E047-11D2-9BC0-0004ACB296D8}'
            CurVer = s 'FTPSubUI.TaskBarList.1'
      }
      NoRemove CLSID
      {
            ForceRemove {15454908-E047-11D2-9BC0-0004ACB296D8} = s 'TaskBarList Class'
            {
                  ProgID = s 'FTPSubUI.TaskBarList.1'
                  VersionIndependentProgID = s 'FTPSubUI.TaskBarList'
                  ForceRemove 'Programmable'
                  LocalServer32 = s '%MODULE%'
                  val AppID = s '{AF2606D7-A096-11D2-9B6F-0004ACB296D8}'
                  'TypeLib' = s '{AF2606D6-A096-11D2-9B6F-0004ACB296D8}'
            }
      }
}
HKCR
{
      FTPSubUI.TaskBarList.1 = s 'TaskBarList Class'
      {
            CLSID = s '{BD4FAF8B-E047-11D2-9BC0-0004ACB296D8}'
      }
      FTPSubUI.TaskBarList = s 'TaskBarList Class'
      {
            CLSID = s '{BD4FAF8B-E047-11D2-9BC0-0004ACB296D8}'
            CurVer = s 'FTPSubUI.TaskBarList.1'
      }
      NoRemove CLSID
      {
            ForceRemove {BD4FAF8B-E047-11D2-9BC0-0004ACB296D8} = s 'TaskBarList Class'
            {
                  ProgID = s 'FTPSubUI.TaskBarList.1'
                  VersionIndependentProgID = s 'FTPSubUI.TaskBarList'
                  ForceRemove 'Programmable'
                  LocalServer32 = s '%MODULE%'
                  val AppID = s '{AF2606D7-A096-11D2-9B6F-0004ACB296D8}'
                  'TypeLib' = s '{AF2606D6-A096-11D2-9B6F-0004ACB296D8}'
            }
      }
}

4) The above .h and .rgs file provide all the information needed for the ITaskBarList Com object. So all you need to do now is create the object and call a method.

4a) Calling the DeleteTab method.
      ITaskbarList*       pTaskBarList       = 0 ;
      
      // Create TaskBarList object
      CoCreateInstance(      CLSID_TaskbarList,
                  NULL,
                  CLSCTX_SERVER,
                           IID_ITaskbarList,
                  reinterpret_cast<void**>(&pTaskBarList)),
                  ITaskBarList );      
            
// Delete the applications button the taskbar.
pTaskBarList->DeleteTab( m_hWnd ) ;
      
      // Release the taskbarlist interface.
      if( pTaskBarList != 0 )
      {
            pTaskBarList->Release() ;
      }

4b) Adding a button to the taskbar. Just replace the deleteTab with AddTab.
pTaskBarList->AddTab( m_hwnd ) ;


Thats all.
If you have any problems then leave a message, also if it makes you life easier I could send you a full working example.

0
 

Accepted Solution

by:
sirrewob earned 480 total points
ID: 1311043
See above
0
 

Author Comment

by:stormp
ID: 1311044
Hi, I think you're getting out of my leage.  I thought there was a simple MFC call or two.   I would really appreciate if you can make a simple DIALOGE Based Application that uses that code and send me the project file!

Thanks a lot!
0
 

Expert Comment

by:sirrewob
ID: 1311045
Where do you want me to send the project?


0
 

Author Comment

by:stormp
ID: 1311046
storm@sfu.ca

0
 

Author Comment

by:stormp
ID: 1311047
Hi sirrewob,

Any idea when you can send the demo project to me?

I appreciate it.

Storm
0
 

Expert Comment

by:sirrewob
ID: 1311048
Sorry about not sending you the project, but I've been out of the office this week.

I'll try and get it to you this weekend.

Sirrewob.

0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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