CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 58

Thread: I need Taskbar APIs

  1. #1
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Question I need Taskbar APIs

    Hello geniuses!

    I'm currently busy with an application which will allow me to change All the XP Taskbar settings through code. In fact, it is finished, but I'm not entirely happy with it.

    The whole problem ( it seems ), is the updating of the settings. For example, I can use the SHAppBarMessage API with some Constants such as ABS_AUTOHIDE, ABS_ALWAYSONTOP To change the Autohide and "Always on Top" settings. I can even use constants such as ABE_LEFT, ABE_RIGHT and so on to set the taskbar's docking. By using this API, the settings get applied immediately.

    Now, if I want to ( for example ) Lock the taskbar, I have to set a registry value :
    Code:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
    "LockTaskbar"=1 (Disable)
    "LockTaskbar"=0 (Enable)
    If I want to Group Similar taskbar buttons, I have to set a registry value :
    Code:
    HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarGlomming
    If I want to show the clock, I also have to set a registry value :
    Code:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\HideClock
    ' 0=show clock, 1=Hide Clock.
    Now, because these ( and the other settings I did not mention ) are stored in the registry, I have to restart explorer.exe, to apply the new changes.
    Isn't there an API which can do this immediately, I mean, If I set one of those properies ( through Right clicking on the Taskbar, Properties ), it does get set immediately - that is what I want

    Or do I rather have to settle with what I have, and which already works

    Any input would be greatly appreciated.
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  2. #2
    Join Date
    Aug 2007
    Location
    Illinois
    Posts
    164

    Re: I need Taskbar APIs

    Playing with Spy++ for a couple minutes. It appears WM_SETTINGCHANGE is in play, wparam=2, lparam=&HC1F23C in the part I trapped. lParam may be a string pointer to a registry key. Maybe googling for "SHAppBarMessage" "WM_SETTINGCHANGE" may shed some light?
    Insomnia is a simple byproduct of "it can't be done"

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Hey, thanx for the advice!
    However, I tried that but it only gives me topics related to Autohide and Always on Top. As I understand it, the Taskbar sends the WM_SETTINGCHANGE notification when its size or position changed.

    I'm starting to think that I will need to use some other API ( or so it seems at this point in time )
    Like for example trying to obtain the "Taskbar's clock" window handle, if possible. I'm thinking, in order to achieve this, I'll need to use the FindWindow API, to first find the "Shell_TrayWnd" window ( which is the taskbar ), then use FindWindowEx to find the clock's window inside it, then ShowWindow

    Let me see if that's going to work...

    EDIT :
    OK, it seems as if the Clock window's name is : TrayClockWClass, so I think I may on the right track with this one.
    At least it may fix one of the issues I have
    Last edited by HanneSThEGreaT; August 28th, 2007 at 08:48 AM.
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  4. #4
    Join Date
    Aug 2007
    Location
    Illinois
    Posts
    164

    Re: I need Taskbar APIs

    I may have not made myself clear. My thinking is that after the registry setting is changed, send a broadcast message, WM_SettingChange, with a string lParam identifying the registry key that changed. Maybe, this message tells the taskbar to refresh from the registry? The link I provided in previous reply may help with coding the broadcast message. When I have more time later tonight I can play too.
    Insomnia is a simple byproduct of "it can't be done"

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Quote Originally Posted by LaVolpe
    I may have not made myself clear. My thinking is that after the registry setting is changed, send a broadcast message, WM_SettingChange, with a string lParam identifying the registry key that changed. Maybe, this message tells the taskbar to refresh from the registry? The link I provided in previous reply may help with coding the broadcast message. When I have more time later tonight I can play too.
    Aah, Now I see, sorry for the confusion. What I'll also try now ( apart from the FindWindow stuff ( for the clock ) ) is to use the SendMessage API or SendMessageTimeOut API along with the HWND_BROADCAST and WM_SETTINGCHANGE flags. I f I can make this work, everything will be working as I want.

    No sleep for me tonight....
    Last edited by HanneSThEGreaT; August 28th, 2007 at 09:15 AM.
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Or can't I just restart explorer.exe, say for example launch it from my program with the WinExec API

    Now all of a sudden I can think....
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  7. #7
    Join Date
    Aug 2007
    Location
    Illinois
    Posts
    164

    Re: I need Taskbar APIs

    Try again. Page errored, so you may get this twice:
    Caution with using SendMessage and broadcasts. If a window does not reply, your app freezes. Recommend considering one of the other in that family: SendNotifyMessage or SendMessageTimeOut. Additionally, since the lParam will be a string (registry key), you may need to store it globally (i.e., SysAllocString) so that all processes can read the string. Just thinking off the top of my head. Also, I'd simply try sending lParam as ByVal 0&, vs a string pointer, initially, just to see if that works

    Edited. RE: Restarting Explorer. May have some side effects you don't want. Not all system icons may reappear for example and/or any active windows on the taskbar may lose their ability to restore/minimize by clicking on their taskbar buttons.

    Edited again.. Wow, I keep thinking broadcast too.... That may not be needed, try sending the WM_SettingChange directly to the tray !
    Last edited by LaVolpe; August 28th, 2007 at 09:28 AM.
    Insomnia is a simple byproduct of "it can't be done"

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    OK, by doing this :
    Code:
    Option Explicit
    
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    
    Private Function HideClock()
      Dim FindClass As Long, FindParent As Long, handle As Long
      FindClass = FindWindow("Shell_TrayWnd", vbNullString)
      FindParent = FindWindowEx(FindClass&, 0, "TrayNotifyWnd", vbNullString)
      handle = FindWindowEx(FindParent&, 0, "TrayClockWClass", vbNullString)
      ShowWindow handle, 0
    End Function
    
    Private Function ShowClock()
      Dim FindClass As Long, FindParent As Long, handle As Long
      FindClass = FindWindow("Shell_TrayWnd", vbNullString)
      FindParent = FindWindowEx(FindClass&, 0, "TrayNotifyWnd", vbNullString)
      handle = FindWindowEx(FindParent&, 0, "TrayClockWClass", vbNullString)
      ShowWindow handle, 1
    End Function
    
    Private Sub Command1_Click()
    ShowClock
    End Sub
    
    Private Sub Command2_Click()
    HideClock
    End Sub
    The clock hides & shows, yeah, although it's funky, it doesn't physically change the setting in the properties ( duhh! ), I'll try sending the broadcast message.
    Thanx LaVolpe, you're really good!
    I'll let you know the progress As soon as I can
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  9. #9
    Join Date
    Aug 2007
    Location
    Illinois
    Posts
    164

    Re: I need Taskbar APIs

    Curiosity got the best of me. You mentioned in 1st post how to toggle locking of the taskbar. I don't think that works, not on my PC anyway. By adding the LockTaskbar registry setting and changing it to 1, the Lock Taskbar menu is disabled on my PC and re-enabled when I change it back to zero or remove the registry string. If this is true, then I would imagine there is a special command to toggle it without modifying the registry. If not, then the setting must be elsewhere in the registry.
    Insomnia is a simple byproduct of "it can't be done"

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Also quite curios on my side. yes, that is what it intended to do. You'll also notice that the HideClock ( to hide the clock ) will also not work as expected. It will disable that item in the Taskbar properties dialog box, I guess I forgot to mention that entirely . So that must also be stored somewhere else in the registry. There's almost no documentation on these. I've always wondered about these settings, and the hows and whys - it should be possible. but how
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  11. #11
    Join Date
    Aug 2007
    Location
    Illinois
    Posts
    164

    Re: I need Taskbar APIs

    Someone actually spent the time to retrieve the menu identifiers of the taskbar and listed most of them. I tested the link's code with the LockTaskbar and it worked as advertised, toggles it each time command is sent.

    However, using this method is unreliable. Will windows keep the same menu identifiers from version to version? Probably, but maybe not. I do recall this is a similar method used to refresh the desktop icons and arrange desktop icons.

    Edited: Forget about that WM_SettingChange. I figured out what that was. It is a broadcast message to all windows letting them know that the desktop workspace dimensions were modified.
    Last edited by LaVolpe; August 28th, 2007 at 10:41 AM.
    Insomnia is a simple byproduct of "it can't be done"

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Great link Thanx!

    Quote Originally Posted by LaVolpe
    Will windows keep the same menu identifiers from version to version?
    Good question, I'll test the exe on Vista tonight as well, but to me it's not a major trainsmash if it might not work there.

    Thanx for all your help. I was totally lost, got to a point and got lost again - I guess things always work like this, and I learnt something useful today.

    I'll update the progress asap
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  13. #13
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Ok, by doing this :
    Code:
     Dim FindClass As Long 
            FindClass = FindWindow("Shell_TrayWnd", vbNullString)
    
            PostMessage(FindClass, WM_COMMAND, 424, vbNullString)
    It does lock the Taskbar As well as setting the "Lock Taskbar" checkmark.

    By using the SHAppBarMessage API, it also Autohides the taskbar as well as change the setting for Always On top, it does set the checkboxes as well.
    What still actually puzzles me is the Clock - there is literally no info on how to change that setting programmatically. ShowWindow only hides it or shows it, but it does not change the physical setting in the Taskbar properties box - this is odd for me, but keep on keeping on, I suppose

    It also turns out, that I do in fact need to use SendMessageTimeout With Broadcast and SettingChange in order to update the "Taskbar Grouping" after setting it's value in the registry.

    I'll keep updating this thread, if I have more info - but if anyone has any further inputs, it would be greatly appreciated!
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  14. #14
    Join Date
    Dec 2001
    Posts
    6,332

    Re: I need Taskbar APIs

    Although I've not tried to do such as what you are looking for, here are a few things which come to mind.

    Some APIs:
    RedrawWindow
    SetWindowPos - NOT using NOSIZE, but using the current values for width and height
    Refreshing the desktop: http://msdn2.microsoft.com/en-us/library/ms723239.aspx
    Another desktop refresh method: http://vbnet.mvps.org/index.html?cod...eenrefresh.htm

    Perhaps something in the above will spark an idea, or not. I recall there's an API to redraw, refresh, or otherwise update the desktop, but whatever it was escapes me ATM. I'll look around later...
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  15. #15
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: I need Taskbar APIs

    Hey thanx for those links, I'll go through them thoroughly
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)