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);
}
|