CSDeskBand icon indicating copy to clipboard operation
CSDeskBand copied to clipboard

Keep deskband after restart

Open dsafa opened this issue 6 years ago • 27 comments

Not sure if this can be done or not but something to look into.

dsafa avatar Jan 22 '18 01:01 dsafa

This is done by other deskbands but I am not sure how or what is missing

dsafa avatar Jan 25 '18 07:01 dsafa

Not sure if its just a bug in the current windows 10 version but toolbars only persist sometimes when resizing or moving a deskband. Even for the built in toolbars.

dsafa avatar Jan 28 '18 03:01 dsafa

Did you find out what caused it,I also find that it must be moved to leftside and then move back (horizontal mode),after that it will possibly remains open when restart

Y-Theta avatar Jan 17 '19 15:01 Y-Theta

Never found out the cause, but in my experience now, it works properly if you just leave it for a bit. I know windows writes the current toolbars to the registry so maybe theres some delays or it does it every set interval.

dsafa avatar Jan 22 '19 03:01 dsafa

I find another DeskBand Project on Github and its Sample works fun : sharpshell .I compared your codes and that one(sharpshell) ,and find that some of your [COMImprot] functions do not have return as that does,so I copied his [COMImport] interfaces,and now it can keep alive when restart. My english is not well,I don't know how to express it clearly,but I think it might be the return values lets system konw the DeskBand item is alredy opened. this is my test project :https://github.com/20154530/DeskBandTest

Y-Theta avatar Jan 22 '19 04:01 Y-Theta

Your English is fine. Thanks for looking into it. Do you have a link to which COM interfaces are different?

dsafa avatar Jan 22 '19 05:01 dsafa

I think Probably these interfaces IDeskBand2, IPersistStream, IObjectWithSite, IInputObject ,they are all with return type 'int' in SharpShell, I remembered I have change All the interfaces expect those used to create ContextMenu.

Y-Theta avatar Jan 22 '19 05:01 Y-Theta

I updated the interfaces and it works fine for me. I checked the registry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Desktop after selecting a toolbar and it appears to be saved properly

dsafa avatar May 09 '19 20:05 dsafa

I spent a lot of time exploring the root causes of this problem. It's worth celebrating that I found a solution. First of all it is caused by the BUG of the system itself. Secondly, the problem lies in the language status bar. Third, the toolbar of the system itself has similar problems.

Windows7's language status bar is on the left, where deskband is currently located. But the initial restart state of Windows10 is actually the same as that of Windows7. The language status bar still defaults to the left and then automatically moves to the right. This process creates the problem of blocking the toolbar.

In fact, toolbars still exist, deskband is working, but they are invisible. So we just need to force the task bar to refresh at the right time. For example:

SendNotifyMessage((IntPtr)HWND_BROADCAST, (uint)WindowsMessage.WM_SETTINGCHANGE, UIntPtr.Zero, "TraySettings");

Personally, I suggest that the above code can be sent several times after the system startup. The problem of keeping deskband after restart has been solved, and the project should be excellent now.

xmoer avatar Sep 20 '19 16:09 xmoer

Since there are many self-startup programs when the operating system is booted, it is not recommended that the author build the above solution in "CSDeskBand" under such complicated circumstances.

xmoer avatar Sep 20 '19 16:09 xmoer

Interesting. Thanks for the details. Let me pin this issue for visibility.

dsafa avatar Sep 20 '19 22:09 dsafa

I currently have this problem. The deskband does indeed start, it's just invisible. I tried the SendNotifyMessage method (confirmed a true boolean was returned), but the deskband stayed invisible. Right now the only thing working is to restart explorer through task manager and then it's visible.

MattBlessinger avatar Sep 26 '19 23:09 MattBlessinger

I currently have this problem. The deskband does indeed start, it's just invisible. I tried the SendNotifyMessage method (confirmed a true boolean was returned), but the deskband stayed invisible. Right now the only thing working is to restart explorer through task manager and then it's visible.

I have tested several versions of Windows10, and all of the above methods are effective. You should send a "SendNotifyMessage" when the toolbar is not visible, but we don't know when the toolbar will disappear. So you can use "Timer()" to send messages continuously within five minutes of the Windows10 startup. It must be noted that sending only once is absolutely not enough.

xmoer avatar Sep 27 '19 17:09 xmoer

I have tested several versions of Windows10, and all of the above methods are effective. You should send a "SendNotifyMessage" when the toolbar is not visible, but we don't know when the toolbar will disappear. So you can use "Timer()" to send messages continuously within five minutes of the Windows10 startup. It must be noted that sending only once is absolutely not enough.

I made a standalone application that I ran at startup. Every 2 seconds it sends the "SendNotifyMessage" command. I let that run for a couple of minutes, but the deskband still did not appear. Can you share your code so that I may test it?

MattBlessinger avatar Sep 27 '19 22:09 MattBlessinger

I made a standalone application that I ran at startup. Every 2 seconds it sends the "SendNotifyMessage" command. I let that run for a couple of minutes, but the deskband still did not appear. Can you share your code so that I may test it?

I'm sure you didn't quote my code, but wrote your own global "BROADCAST", right? The key to success is not the number of messages sent, but the parameters I set. Your "SendNotifyMessage" code must be the same as mine. This is a message code that is only valid for Windows10, and Windows10 has a large number of Undocumented APIs.

xmoer avatar Sep 28 '19 10:09 xmoer

I made a standalone application that I ran at startup. Every 2 seconds it sends the "SendNotifyMessage" command. I let that run for a couple of minutes, but the deskband still did not appear. Can you share your code so that I may test it?

I just wrote a simple "Timer()" and sent messages every 15 seconds, a total of 12 times. There is no doubt that the problem is not a timer. I tested almost all Windows10 versions and they worked perfectly.

xmoer avatar Sep 28 '19 10:09 xmoer

I'm sure you didn't quote my code, but wrote your own global "BROADCAST", right? The key to success is not the number of messages sent, but the parameters I set. Your "SendNotifyMessage" code must be the same as mine. This is a message code that is only valid for Windows10, and Windows10 has a large number of Undocumented APIs.

This is what I did. What values did you use for HWND_BROADCAST and WM_SETTINGCHANGE?

private const int HWND_BROADCAST = 0xffff;
private const int WM_SETTINGCHANGE = 0x001a;
bool retVal = SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, UIntPtr.Zero, "TraySettings");

MattBlessinger avatar Sep 29 '19 12:09 MattBlessinger

This is what I did. What values did you use for HWND_BROADCAST and WM_SETTINGCHANGE?

Yeah, it seems all right. The most important "TraySettings" parameter settings are fine. It seems that we need to discuss our respective development environments.

I used: CSDeskBand Version 3.1 + WPF + VS2017. If you don't mind, could you provide me with your file to help you find out the cause of the failure?

xmoer avatar Sep 29 '19 12:09 xmoer

I used: CSDeskBand Version 3.1 + WPF + VS2017. If you don't mind, could you provide me with your file to help you find out the cause of the failure?

I used CSDeskBand v3.1, WPF .NET Framework 4.7.2, VS2019. I attached the separate program I'm using to send the broadcast. I run the .exe in /bin/debug at startup. It sends the broadcast every 5 seconds until you press a key in the console window. Thank you for your help! ConsoleApp2.zip

MattBlessinger avatar Sep 29 '19 13:09 MattBlessinger

I used CSDeskBand v3.1, WPF .NET Framework 4.7.2, VS2019. I attached the separate program I'm using to send the broadcast. I run the .exe in /bin/debug at startup. It sends the broadcast every 5 seconds until you press a key in the console window. Thank you for your help!

It's strange that it works well on my computer.

xmoer avatar Sep 29 '19 14:09 xmoer

It's strange that it works well on my computer.

Well that's unfortunate for me then. The deskband stays invisible unless I restart explorer.exe

MattBlessinger avatar Sep 29 '19 14:09 MattBlessinger

Well that's unfortunate for me then. The deskband stays invisible unless I deselect and reselect it from the menu or restart explorer.exe

Restarting the desktop process is effective, which shows that my point of view is correct. I even tested Windows Server 2016 on a virtual machine, and your program is still worked well. So maybe the error originated from your DLL file?

xmoer avatar Sep 29 '19 14:09 xmoer

So maybe the error originated from your DLL file?

Potentially. Did you add anything extra to your deskband in terms of window visiblity, etc., that could affect it? I attached my deskband so you may try it on your computer.

MattBlessinger avatar Sep 29 '19 14:09 MattBlessinger

Potentially. Did you add anything extra to your deskband in terms of window visiblity, etc., that could affect it? I attached my deskband so you may try it on your computer.

This DLL file may have problems. There is no "TaskbarInfo" event in your code, and I guess that's why it can't receive messages. The DLL file can't even work after Windows Server 2016 system restart. I think you should study the author's demo carefully.

public class Deskband : CSDeskBandWpf
{
    ……
}

Don't let the content here be empty. The author of "CSDeskBand" has another excellent project that you can refer to: https://github.com/dsafa/audio-band

xmoer avatar Sep 29 '19 15:09 xmoer

I found the issue after adding my code piece by piece to the ExampleWpf until it stopped working after reboot. It turns out it was this line I was using in UserControl to programmatically set the height to be the taskbar height. this.Height = System.Windows.SystemParameters.PrimaryScreenHeight - System.Windows.SystemParameters.WorkArea.Height; FYI, I was using this instead of TaskbarInfo.Size.Height, because TaskbarInfo does not account for resolution scaling.

Since the deskband is just for myself I have hard coded the height of the UserControl, and now the deskband is visible after rebooting! The reason it wasn't working after reboot is that the taskbar did not exist by the time the deskband started so it set the UserControl height to 0.

To confirm it was user error and there are no problems with CSDeskBand. Thank you for the help.

MattBlessinger avatar Sep 29 '19 22:09 MattBlessinger

@MattBlessinger I think it could help, overriding the event callbacks OnInitialized and OnRenderSizeChanged, like I mentioned in https://github.com/dsafa/CSDeskBand/issues/51.

Thanks for you comment by the way, which was helpful for me. :)

kevinglier avatar Mar 03 '20 12:03 kevinglier

So there is any solution? My issue is not that the toolbar is now shown after restart but is not selected. When I open the toolbar selection I don't see the checkmark (v) nearby.

eladpotok avatar Dec 22 '20 15:12 eladpotok