[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Adding new button to windows taskbar

Asked by soulaco in Visual Studio, C# Programming Language, Microsoft Visual C#.Net

Tags: Windows XP, COM, Win32 API, .NET, pinvoke, COM Interop, C++

I am having trouble adding a new button to the windows taskbar. Can anyone help me with this? I have posted some code that is giving me a problem. The SendMessage command with the INSERT_BUTTON constant is crashing explorer and I can't seem to figure out why. Anyone have any ideas?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
        unsafe public void AddButton(ref Win32API.Structs.TBBUTTON theButtonStruct)
        {
            const int BUFFER_SIZE = 0x1000;
 
            if (!FindTaskBar())
                return;
 
            byte[] bytLocalBuffer = new byte[BUFFER_SIZE];
            UInt32 uInt32ProcessID = 0;
 
            UInt32 uInt32ThreadID = (UInt32)Win32API.Functions.User32.GetWindowThreadProcessId(m_TaskbarWindowHandleIntPtr, out uInt32ProcessID);
            IntPtr intPtrProcessHandle = Win32API.Functions.Kernel32.OpenProcess(Win32API.Constants.ProcessRights.ALL_ACCESS, false, uInt32ProcessID);
 
            if (intPtrProcessHandle == IntPtr.Zero)
                return;
 
            IntPtr intPtrRemoteBuffer = Win32API.Functions.Kernel32.VirtualAllocEx(intPtrProcessHandle, IntPtr.Zero, new UIntPtr(BUFFER_SIZE), Win32API.Constants.MemoryAllocationType.COMMIT, Win32API.Constants.MemoryProtection.PAGE_READ_WRITE);
 
            if (intPtrRemoteBuffer == IntPtr.Zero)
                return;
 
            fixed (Win32API.Structs.TBBUTTON* ptrButton = &theButtonStruct)
            {
                IntPtr intPtrButton = new IntPtr(ptrButton);
 
                Int32 int32BytesWritten = 0;
                IntPtr intPtrBytesWritten = new IntPtr(&int32BytesWritten);
 
                uint uIntWrite = 0;
                IntPtr intPtrWrite = new IntPtr(&uIntWrite);
                string strText = "Test";
 
                byte[] byt = Encoding.ASCII.GetBytes(strText);
 
                bool blnReturn = Win32API.Functions.Kernel32.WriteProcessMemory(intPtrProcessHandle, intPtrRemoteBuffer, byt, new UIntPtr((uint)strText.Length), out intPtrBytesWritten);
 
                theButtonStruct.iString = Win32API.Functions.User32.SendMessage(m_TaskbarWindowHandleIntPtr, Win32API.Constants.ToolbarButtonMessages.ADD_STRING, IntPtr.Zero, intPtrRemoteBuffer);
 
                blnReturn = Win32API.Functions.Kernel32.WriteProcessMemory(intPtrProcessHandle, intPtrRemoteBuffer, intPtrButton, new UIntPtr((uint)sizeof(Win32API.Structs.TBBUTTON)), out intPtrBytesWritten);
 
                int intCount = GetButtonCount();
 
                int intTest = Win32API.Functions.User32.SendMessage(m_TaskbarWindowHandleIntPtr, Win32API.Constants.ToolbarButtonMessages.INSERT_BUTTON, (IntPtr)(intCount-1), intPtrRemoteBuffer);
            }
 
            Win32API.Functions.Kernel32.VirtualFreeEx(intPtrProcessHandle, intPtrRemoteBuffer, UIntPtr.Zero, Win32API.Constants.MemoryAllocationType.RELEASE);
            Win32API.Functions.Kernel32.CloseHandle(intPtrProcessHandle);
        }
[+][-]11/04/09 10:15 PM, ID: 25747115Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 04:26 AM, ID: 25748699Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 04:38 PM, ID: 25755724Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 05:03 PM, ID: 25755851Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 08:07 PM, ID: 25756544Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 09:08 PM, ID: 25756729Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 11:24 PM, ID: 25757272Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 04:29 AM, ID: 25758514Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 02:18 PM, ID: 25763574Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 02:34 PM, ID: 25763678Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 05:03 PM, ID: 25764450Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 07:21 PM, ID: 25764836Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 10:04 PM, ID: 25769566Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/20/09 06:16 AM, ID: 25870375Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/20/09 01:30 PM, ID: 25874719Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/20/09 02:09 PM, ID: 25874990Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/21/09 06:56 PM, ID: 25880615Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625