The taskbar hates me messing around!

This is a discussion on The taskbar hates me messing around! within the C++ Programming forums, part of the General Programming Boards category; Every time I capture the taskbar's HWND, then create a child window on it, it destroys my window. Every time ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation The taskbar hates me messing around!

    Every time I capture the taskbar's HWND, then create a child window on it, it destroys my window. Every time I do somthing to it, it puts everything back! How can I prevent this? I know it can be done because one of Google's programs can do it. Please give me some advice, thanks, August.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    MSDN reference: The Taskbar

    With Internet Explorer 4.0 and later, the Shell notifies applications that the taskbar has been created. When the taskbar is created, it registers a message with the TaskbarCreated string and then broadcasts this message to all top-level windows. When your taskbar application receives this message, it should assume that any taskbar icons it added have been removed and add them again. This feature generally applies only to services that are already running when the Shell begins execution. The following example shows a very simplified method for handling this case.
    This is windows specific. I'm sure you've made 5+ threads here. Come now, be sensible.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Hmm... So what can I do to get around it?

  4. #4
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    Maybe I'm being stupid(I haven't really done any Windows programming), but it would appear, that upon the arrival of the "TaskbarCreated" message, you have your program put whatever its putting on the taskbar back on the taskbar

    Thats also what they appear to do in the code example.
    Programming Your Mom. http://www.dandongs.com/

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    But the code is putting icons on, I want an edit box and a button, besides, when I try to compile some of the example script I get 20 errors.

  6. #6
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    Do whatever you do to create the edit box and the button every time you get the "TaskbarCreated" message. Then, restore the text that was in it. The fact that the entire setup was just recreated will be completely transparent to the user. (If you recreate everything before the "paint" event/message/whatever occurs, the user will never see it dissapear and reappear. Rerun the code that runs when your program starts each time you get the "TaskbarCreated" message. Post your code and maybe I can figure it out if you can't.
    Programming Your Mom. http://www.dandongs.com/

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, here s my code, no errors. It's just not working.
    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <windowsx.h>
    #include <commctrl.h>
    #include <mmsystem.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    /*  Make the paint variable available globally  */
    HDC hdc;
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        int winX = 544;
        int winY = 375;
    
        /* Get the window's DC */
        hdc = GetDC(hwnd);
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows Application",       /* Title Text */
               WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOX,
               GetSystemMetrics(SM_CXSCREEN)/2-winX/2,       /* Windows decides the position */
               GetSystemMetrics(SM_CYSCREEN)/2-winY/2,       /* where the window ends up on the screen */
               winX,                 /* The programs width */
               winY,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
    
    DWORD AddTaskbarWindows()
    {
      HWND hwndMother = FindWindow("Shell_TrayWnd", 0);  
      CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE, 0,0,180,17,hwndMother,(HMENU)29,0,0);
    }
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static UINT s_uTaskbarRestart;
    
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
                s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
                break;
    
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
    
            default:  
                if(message == s_uTaskbarRestart)
                    AddTaskbarWindows();
                break;
        }
        
        return DefWindowProc (hwnd, message, wParam, lParam);
    }

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can't just shove your own controls on a window belonging to another process. If you want a custom taskbar, then create your own.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting all window handles on taskbar
    By Yuri in forum Windows Programming
    Replies: 1
    Last Post: 06-17-2006, 05:31 PM
  2. Replies: 0
    Last Post: 11-08-2005, 02:28 AM
  3. Problem with an icon in the TaskBar status area
    By dit6a9 in forum Windows Programming
    Replies: 2
    Last Post: 08-16-2004, 11:33 PM
  4. How do I show the taskbar without activating it?
    By avn in forum Windows Programming
    Replies: 1
    Last Post: 02-22-2003, 09:21 PM
  5. Systray and Taskbar control
    By tkb4u in forum C++ Programming
    Replies: 1
    Last Post: 12-24-2001, 08:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21