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

Thread: I need Taskbar APIs

  1. #46
    Join Date
    Dec 2001
    Posts
    6,332

    Re: I need Taskbar APIs

    Well, this topic finally got my curiosity up enough to do some poking around. Using an API monitoring tool, I watched the calls being made when the clock is hidden or shown. Turns out, it's nothing more than ShowWindow, though it seems a value of 5 is used to show it. I didn't investigate why, or if it actually matters. AFAIK it's taken as a Boolean.

    So I'm wondering; since you know how to change the registry setting, and you know how to show and hide the clock with ShowWindow, why not combine the two, thus achieving your goal?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  2. #47
    Join Date
    Apr 2007
    Posts
    66

    Re: I need Taskbar APIs

    Quote Originally Posted by WizBang
    Well, this topic finally got my curiosity up enough to do some poking around. Using an API monitoring tool, I watched the calls being made when the clock is hidden or shown. Turns out, it's nothing more than ShowWindow, though it seems a value of 5 is used to show it. I didn't investigate why, or if it actually matters. AFAIK it's taken as a Boolean.

    So I'm wondering; since you know how to change the registry setting, and you know how to show and hide the clock with ShowWindow, why not combine the two, thus achieving your goal?

    WOW THANK YOU SOOOOOOOOOOOOO MUCH!!!!!!!!! I have just solved the problem.

    Explorer.exe wont update its clock until it is hidden.

    Here is what you have to do:
    Call ShowWindow with the paramater of SW_HIDE which = 5.

    Then update explorer with sending it WM_SETTINGCHANGE

    Example:
    Call SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, ByVal 0)

    You can use any method you like to send the message, Ex: SendMessage, SendMessageTimeout, SendNotifyMessage.

    Difference here:
    http://blogs.msdn.com/oldnewthing/ar...19/266664.aspx



    Wow problem Solved!
    I think we are some of the first to know how this works besides the programmers of explorer.exe :P.

    I have never seen anyone else do something like this on google or anwhere =]

    I feel happy.


    Ok now WizBang, how did you know that this message was being send to explorer?

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

    Re: I need Taskbar APIs

    WizBang you are a genius.!

    AltF4, mind sharing a small example with our fellow members
    I'm not on my pc now, so I can't test what you've mentioned in your last post.
    This thing kept us busy for 1 and a half months, but it sure is worth it! I think this thread is one of the best so far on the forums, it is amazing how these things work.

    Thanx LaVolpe ( for all your wonderful comments )
    Thanx WoF ( for the continued interest )
    Thanx AltF4 ( for bringing this thread back to life, and to show me to always be curios )
    Thanx WizBang ( for all your input, and helping us solve this )

    And if our friend AltF4 can just supply a small sample here (which will benefit many many people in the future ), this thing will be finally resolved.
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  4. #49
    Join Date
    Dec 2001
    Posts
    6,332

    Re: I need Taskbar APIs

    Quote Originally Posted by AltF4
    Ok now WizBang, how did you know that this message was being send to explorer?
    Well actually, the ShowWindow message I referred to is being sent to the window for the clock. I saw it with an API spy type of tool called API Monitor. I don't believe it's the best available, but it was free. Spy++ might work just as well, though I just haven't taken the time to become familiar with it.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #50
    Join Date
    Apr 2007
    Posts
    66

    Re: I need Taskbar APIs

    Wow I am dumb, I just relized I could have used a nice tool (needs work but lets u see what messages and stuff are being sent to the window) called Winspector (Its free too)

    Anyways, I found a lot of messages being sent to the clock while this happens. I am going to look into this more.

    I also found out, when making this demo for everyone that I will post a little bit later, that this doesn't make explorer.exe reload the structrect2 key, but just updates itself. Basically since the clock is hidden, it probably says "oops that window does not contain WS_VISIBLE, I better fully hide it"

    So Ill continue working on this update. (I am trying to what other ways I can make explorer.exe update this besides sending WM_SETTINGCHANGE to all windows which makes the system lag for a few seconds.

  6. #51
    Join Date
    Apr 2007
    Posts
    66

    Re: I need Taskbar APIs

    Add a checkbox to your form.


    General - Form
    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 SendNotifyMessage Lib "user32" Alias "SendNotifyMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any) As Long
        
        Private Const HWND_BROADCAST = &HFFFF
        Private Const WM_SETTINGCHANGE = &H1A
        
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    
        Public Enum eWindowFocus
            SW_Hide = 0
            SW_Normal = 1
            SW_Maximize = 3
            SW_Minimize = 6
            SW_Show = 5
            SW_Restore = 9
        End Enum


    Form:
    Code:
    Private Sub Check1_Click()
        'Toggle clock setting:
        Call ToggleClock(CBool(Check1.Value))
    End Sub
    
    
    '----------
    'Events:
    '----------
    
        Private Function ToggleClock(ByVal bShow As Boolean)
            'Show/Hide clock window:
            If bShow = True Then Call ShowWindow(GetTrayClock, SW_Show) Else Call ShowWindow(GetTrayClock, SW_Hide)
        
            
            'Update explorer:
            Call UpdateExplorer
        End Function
    
    
        Private Function UpdateExplorer()
            
            'Update explorer shell: (Start menu, files, some policies etc)
            Call SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, ByVal 0)
        
        End Function
    
    '-----------------
    'Special Windows:
    '-----------------
    
    
        '---[<< Taskbar Window: >>]---
        Public Function GetTaskbarWindow() As Long
            GetTaskbarWindow = FindWindow("shell_traywnd", "")
        End Function
        
        '---[<< Taskbar -> System Tray: >>]---
        Public Function GetSystemTray() As Long
            Dim hWindow As Long
            hWindow = GetTaskbarWindow
            hWindow = FindWindowEx(hWindow, 0, "TrayNotifyWnd", "")
            GetSystemTray = hWindow
        End Function
        
        '---[<< Taskbar -> Tray -> Clock: >>]---
        Public Function GetTrayClock() As Long
            Dim hWindow As Long
            hWindow = GetSystemTray
            hWindow = FindWindowEx(hWindow, 0, "TrayClockWClass", vbNullString)
            GetTrayClock = hWindow
        End Function


    Enjoy.


    The only thing that can be imporoved is the long delay it takes. If you use process explorer, you will see your CPU spike to max for a second or 2 when you broadcast the message.

    If you have any imporvements, let me know or post em.

    The thing that annoys me most though, is that this does not cause explorer.exe to reload the registry key in StructRect2, which was what we wanted, so this is just a work around until I can find that out.

    Any obviously when explorer.exe updates this, it does take so long, lag as bad, and spike so much.

    So please post your seggestions / ideas.
    Last edited by AltF4; October 28th, 2007 at 09:04 AM.

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

    Re: I need Taskbar APIs

    Great Code AltF4, it just shows, you're ( me ) never too old to learn.
    Just a query though, I don't know if it just me being stupid, but running this program doesn't seem to change the "Show the clock" checkbox in the Taskbar properties - it just hides the clock and show it. Must I execute those reg files while running this program as well
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  8. #53
    Join Date
    Apr 2007
    Posts
    66

    Re: I need Taskbar APIs

    Quote Originally Posted by HanneSThEGreaT
    Great Code AltF4, it just shows, you're ( me ) never too old to learn.
    Just a query though, I don't know if it just me being stupid, but running this program doesn't seem to change the "Show the clock" checkbox in the Taskbar properties - it just hides the clock and show it. Must I execute those reg files while running this program as well

    Yes that is correct. Apparently explorer.exe reads that key to check that checkbox or not.

    What you could do though, if you wanted to lock it down is use the group policy key to disable the checkbox, and regardless of the value, be disabled, and have the clock always hidden no matter what (once explorer.exe is restarted of course)

    But you can see the checkbox effect instantly by sending the WM_SETTINGCHANGE out and opening the taskbar properties.

    Key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer
    OR
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

    Value:
    HideClock (dword) 1 = Enabled (Clock always hidden) 0 = Disabled (Not affected)

  9. #54
    Join Date
    Feb 2020
    Posts
    5

    Re: I need Taskbar APIs

    Quote Originally Posted by HanneSThEGreaT View Post
    Update as promised..

    The Show the Clock setting in the Taskbar properties, seem to be controlled by this registry key :
    HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Stuckrects2\Settings

    Now, you have to understand that other Taskbar properties are also controlled by this key, and they are :
    AutoHide
    Always on Top
    Show Small Icons

    These 4 options, store different things into this registry key, as I'll demonstarte with the following :
    Code:
    '                                    Auto   Always  Show Small  Hide
    '                   Binary  Dec Hex  Hide   On Top    Icons     Clock
    '                 ----------------------------------------------------
    '                 | 00000000 00 00 |      |        |           |     |
    
    '                 | 00000001 01 01 |  x   |        |           |     |
    
    '                 | 00000010 02 02 |      |   x    |           |     |
    
    '                 | 00000011 03 03 |  x   |   x    |           |     |
    
    '                 | 00000100 04 04 |      |        |    x      |     |
    
    '                 | 00000101 05 05 |  x   |        |    x      |     |
    
    '                 | 00000110 06 06 |      |   x    |    x      |     |
    
    '                 | 00000111 07 07 |  x   |   x    |    x      |     |
    
    '                 | 00001000 08 08 |      |        |           |  x  |
    
    '                 | 00001001 09 09 |  x   |        |           |  x  |
    
    '                 | 00001010 10 0A |      |   x    |           |  x  |
    
    '                 | 00001011 11 0B |  x   |   x    |           |  x  |
    
    '                 | 00001100 12 0C |      |        |    x      |  x  |
    
    '                 | 00001101 13 0D |  x   |        |    x      |  x  |
    
    '                 | 00001110 14 0E |      |   x    |    x      |  x  |
    
    '                 | 00001111 15 0F |  x   |   x    |    x      |  x  |
    
    '                 | --------------------------------------------------
    Also, keep in mind 9 if it's not already obvious ) that we are dealing with Binary values here, and not strings / Dwords, so to be able to identify the current setting / to change the setting will be quite tough. There is a thread here about reading binary values from the registry ( can't remember the precise location - but the thread dealt with determining if we are in Classic mode / or XP Mode ).

    And yes, we will definitely need to use SendMessageTimeOut to reload explorer.exe to immediately see the changes.
    Hi and thank for the topic
    I'm going to change show/hide icon settings with changing registry key:
    Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3\Settings

    but the problem is I can't to restart explorer.exe in my program and these changes just apply when the explorer.exe restarts
    I read the topic but I'm not good at English and didn't understand that does the topic have an answer to my question or not?!

    would you please help me on my problem? I'm working on it about 1.5 months

  10. #55
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,114

    Re: I need Taskbar APIs

    Why can't you use SendMessageTimeOut() to reload explorer.exe as stated in the referenced post above? Changing those settings only takes effect after a restart of explorer.exe.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

  11. #56
    Join Date
    Feb 2020
    Posts
    5

    Re: I need Taskbar APIs

    Quote Originally Posted by 2kaud View Post
    Why can't you use SendMessageTimeOut() to reload explorer.exe as stated in the referenced post above? Changing those settings only takes effect after a restart of explorer.exe.
    Thanks for answer
    because I don't know how to use it
    I changed the registry value with C/C++, after RegCloseKey() function I call SendMessageTimeout like this:
    Code:
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"TraySettings", SMTO_ABORTIFHUNG, 5000, 0);
    but it wasn't useful, I don't know I'm doing it wrong or it doesn't work in my case

  12. #57
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,274

    Re: I need Taskbar APIs

    This thread is 13 years old. At this point it is considered bad form for a program to alter user settings (not to mention that the program will now need elevated permissions to be able to make registry changes).

    Rather than tacking on to this old thread, why not start a new thread in one of the c++ forums that describes what you are actually trying to do in general terms and then we can help you find a modern programmatic solution?

  13. #58
    Join Date
    Feb 2020
    Posts
    5

    Re: I need Taskbar APIs

    Quote Originally Posted by Arjay View Post
    This thread is 13 years old. At this point it is considered bad form for a program to alter user settings (not to mention that the program will now need elevated permissions to be able to make registry changes).

    Rather than tacking on to this old thread, why not start a new thread in one of the c++ forums that describes what you are actually trying to do in general terms and then we can help you find a modern programmatic solution?
    I started some topic in another websites before, but no useful answer... they all told me it's not possible and you have to restart explorer.exe and so on...
    today I starts another topic in this site, hope they help (I need Taskbar APIs)

Page 4 of 4 FirstFirst 1234

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)