dsafa / CSDeskBand

Windows deskband with C#
MIT License
274 stars 65 forks source link

How to load deskband another program? #41

Closed StevenBaby closed 5 years ago

StevenBaby commented 5 years ago

I registered deskband, but it need click taskbar toolbars to activate, how to activate it automatically?

dsafa commented 5 years ago

you'll have to get an instance of ITrayDeskband and use the methods there. Heres an example

StevenBaby commented 5 years ago

you'll have to get an instance of ITrayDeskband and use the methods there. Heres an example

Thanks, that work.

in the program define ITrayDeskband.cs

[ComImport, Guid("6D67E846-5B9C-4db8-9CBC-DDE12F4254F1"),
     InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ITrayDeskband
    {
      [PreserveSig]
      int ShowDeskBand([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
      [PreserveSig]
      int HideDeskBand([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
      [PreserveSig]
      int IsDeskBandShown([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
      [PreserveSig]
      int DeskBandRegistrationChanged();
    } 

call in program

ITrayDeskband obj = null;
    Type trayDeskbandType = System.Type.GetTypeFromCLSID(new Guid("E6442437-6C68-4f52-94DD-2CFED267EFB9"));
    try
    {
        obj = (ITrayDeskband)Activator.CreateInstance(trayDeskbandType);
        Guid deskbandGuid = new Guid(DESKBAND_GUID)
        obj.DeskBandRegistrationChanged();
        hr = obj.ShowDeskBand(ref deskbandGuid);
        if (hr != 0)
            throw new Exception("Error while trying to show deskband: " + hr);
        obj.DeskBandRegistrationChanged();
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
    finally
    {
        if (obj != null && Marshal.IsComObject(obj))
            Marshal.ReleaseComObject(obj);
    }