static LPITEMIDLIST _ILReadFromSharedMemory(PCWSTR strField) { LPITEMIDLIST ret = NULL; // Ensure it really is an IDLIST-formatted parameter // Format for IDLIST params: ":pid:shared" if (*strField != L':') return NULL; HANDLE hData = (HANDLE) StrToIntW(strField + 1); PWSTR strSecond = StrChrW(strField + 1, L':'); if (strSecond) { int pid = StrToIntW(strSecond + 1); void* pvShared = SHLockShared(hData, pid); if (pvShared) { ret = ILClone((LPCITEMIDLIST) pvShared); SHUnlockShared(pvShared); SHFreeShared(hData, pid); } } return ret; }
UINT WINAPI SHAppBarMessage(DWORD dwMessage, PAPPBARDATA pabd) { HWND hwndTray; COPYDATASTRUCT cds; TRAYAPPBARDATA tabd; BOOL fret; LPRECT lprc = NULL; hwndTray = FindWindow(c_szTrayClass, NULL); if (!hwndTray || (pabd->cbSize > SIZEOF(tabd.abd))) { return(FALSE); } tabd.abd = *pabd; tabd.dwMessage = dwMessage; tabd.hSharedRect = NULL; tabd.dwProcId = GetCurrentProcessId(); cds.dwData = TCDM_APPBAR; cds.cbData = SIZEOF(tabd); cds.lpData = &tabd; switch (dwMessage) { case ABM_QUERYPOS: case ABM_SETPOS: case ABM_GETTASKBARPOS: tabd.hSharedRect = SHAllocShared(NULL, SIZEOF(RECT), tabd.dwProcId); if (tabd.hSharedRect == NULL) return FALSE; break; } fret = (SendMessage(hwndTray, WM_COPYDATA, (WPARAM)pabd->hWnd, (LPARAM)&cds)); if (tabd.hSharedRect) { lprc = (LPRECT)SHLockShared(tabd.hSharedRect,tabd.dwProcId); if (lprc == NULL) { fret = FALSE; } else { pabd->rc = *lprc; SHUnlockShared(lprc); } SHFreeShared(tabd.hSharedRect,tabd.dwProcId); } return fret; }
// // HandleMessage // LRESULT WINAPI TaskbarListHandler::HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DbgTraceWindowMessage("ITaskbarList", uMsg, wParam, lParam); switch (uMsg) { // Sent by ITaskbarList::ActivateTab and ITaskbarList::SetActiveAlt // ActivateTab will send WM_ShellHook(4, hwnd) immediately after this message. case WM_USER + 50: { // wParam = 0, lParam = hWnd SendMessage(m_hLiteStep, LM_TASK_MARKASACTIVE, lParam, 0); } return 0; // Sent by ITaskbarList2::MarkFullscreenWindow case WM_USER + 60: { // wParam = 1 to mark as fullscreen, 0 to remove marking // lParam = hWnd // TODO::This should be sent to the fullscreen monitor } return 0; // Sent by ITaskbarList3::SetProgressValue case WM_USER + 64: { // wParam = hwnd // lParam = progress, 0 = 0%, 0xFFFE = 100% SendMessage(m_hLiteStep, LM_TASK_SETPROGRESSVALUE, wParam, lParam); } return 0; // Sent by ITaskbarList3::SetProgressState case WM_USER + 65: { // wParam = hwnd // lParam = tbpFlags SendMessage(m_hLiteStep, LM_TASK_SETPROGRESSSTATE, wParam, lParam); } return 0; // Sent by ITaskbarList3::RegisterTab case WM_USER + 67: { // wParam = hwndTab // lParam = hwndMDI SendMessage(m_hLiteStep, LM_TASK_REGISTERTAB, wParam, lParam); } return 0; // Sent by ITaskbarList3::UnregisterTab case WM_USER + 68: { // wParam = hwndTab // lParam = 0 SendMessage(m_hLiteStep, LM_TASK_UNREGISTERTAB, wParam, 0); } return 0; // Sent by ITaskbarList3::SetTabOrder case WM_USER + 71: { // wParam = hwndTab // lParam = hwndInsertBefore SendMessage(m_hLiteStep, LM_TASK_SETTABORDER, wParam, lParam); } return 0; // Sent by ITaskbarList3::SetTabActive case WM_USER + 72: { // wParam = hwndTab // lParam = 0 ??? SendMessage(m_hLiteStep, LM_TASK_SETACTIVETAB, wParam, lParam); } return 0; // Mysterious message, sent by control panel windows case WM_USER + 75: { // wParam = hwnd of the control panel // lParam = 0 ? } return 0; // Sent by ITaskbarList3::ThumbBarAddButtons case WM_USER + 76: { // wParam = hwnd // lParam = SHSharedAlloc(cButtons, pButton) (first 4 bytes is cButtons) LPUINT pData = (LPUINT)SHLockShared((HANDLE)lParam, m_dwLiteStepProc); THUMBBUTTONLIST thumbList; thumbList.cButtons = pData[0]; thumbList.pButton = (THUMBBUTTON*)&pData[1]; SendMessage(m_hLiteStep, LM_TASK_THUMBBARADDBUTTONS, wParam, (LPARAM)&thumbList); SHUnlockShared(pData); } return 0; // Sent by ITaskbarList3::ThumbBarUpdateButtons case WM_USER + 77: { // wParam = hwnd // lParam = SHSharedAlloc(cButtons, pButton) (first 4 bytes is cButtons) LPUINT pData = (LPUINT)SHLockShared((HANDLE)lParam, m_dwLiteStepProc); THUMBBUTTONLIST thumbList; thumbList.cButtons = pData[0]; thumbList.pButton = (THUMBBUTTON*)&pData[1]; SendMessage(m_hLiteStep, LM_TASK_THUMBBARUPDATEBUTTONS, wParam, (LPARAM)&thumbList); SHUnlockShared(pData); } return 0; // Sent by ITaskbarList3::ThumbBarSetImageList case WM_USER + 78: { // wParam = hwnd // lParam = SHSharedAlloc(himl) HIMAGELIST hImageList = (HIMAGELIST)SHLockShared((HANDLE)lParam, m_dwLiteStepProc); SendMessage(m_hLiteStep, LM_TASK_THUMBBARSETIMAGELIST, wParam, (LPARAM)hImageList); if (hImageList) { SHUnlockShared(hImageList); } } return 0; // Sent by ITaskbarList3::SetOverlayIcon case WM_USER + 79: { // wParam = hwnd // lParam = hicon SendMessage(m_hLiteStep, LM_TASK_SETOVERLAYICON, wParam, lParam); } return 0; // Sent by ITaskbarList3::SetThumbnailTooltip case WM_USER + 80: { // wParam = hwnd // lParam = SHSharedAlloc(pszTip) LPWSTR pwzTip = (LPWSTR)SHLockShared((HANDLE)lParam, m_dwLiteStepProc); SendMessage(m_hLiteStep, LM_TASK_SETTHUMBNAILTOOLTIP, wParam, (LPARAM)pwzTip); if (pwzTip) { SHUnlockShared(pwzTip); } } return 0; // Sent by ITaskbarList3::SetThumbnailClip case WM_USER + 81: { // wParam = hwnd // lParam = SHSharedAlloc(prcClip) LPRECT prcClip = (LPRECT)SHLockShared((HANDLE)lParam, m_dwLiteStepProc); SendMessage(m_hLiteStep, LM_TASK_SETTHUMBNAILCLIP, wParam, (LPARAM)prcClip); if (prcClip) { SHUnlockShared(prcClip); } } return 0; // Sent by ITaskbarList3::SetOverlayIcon case WM_USER + 85: { // wParam = hwnd // lParam = SHSharedAlloc(pszDescription) LPWSTR pwzDescription = (LPWSTR)SHLockShared((HANDLE)lParam, m_dwLiteStepProc); SendMessage(m_hLiteStep, LM_TASK_SETOVERLAYICONDESC, wParam, (LPARAM)pwzDescription); if (pwzDescription) { SHUnlockShared(pwzDescription); } } return 0; // Sent by ITaskbarList4::SetTabProperties case WM_USER + 87: { // wParam = hwndTab // lParam = stpFlags SendMessage(m_hLiteStep, LM_TASK_SETTABPROPERTIES, wParam, lParam); } return 0; default: { // AddTab, DeleteTab, and ActivateTab will send WM_ShellHook // TODO::We should consider distinguishing between these and actual WM_SHELLHOOK messages // we may wish to remember that a certain window has been "marked" as deleted, so that we // don't accidentally recreate it (when activated, or on recycles). if (uMsg == WM_ShellHook) { return SendMessage(m_hLiteStep, uMsg, wParam, lParam); } } } return DefWindowProc(hWnd, uMsg, wParam, lParam); }
PIE_THREAD_PARAM_BLOCK ParseSharedPacket(HANDLE hData) { HNFBlock * hnfData; PBYTE block; int pid; PIE_THREAD_PARAM_BLOCK params = NULL; if (!hData) goto cleanup0; pid = GetCurrentProcessId(); block = (PBYTE) SHLockShared(hData, pid); hnfData = (HNFBlock *) block; if (!block) goto cleanup2; if (hnfData->cbSize < sizeof(HNFBlock)) goto cleanup2; params = SHCreateIETHREADPARAM(0, hnfData->offset8, 0, 0); if (!params) goto cleanup2; params->dwFlags = hnfData->offset4; params->offset8 = hnfData->offset8; params->offset74 = hnfData->offsetC; params->offsetD8 = hnfData->offset10; params->offset84 = hnfData->offset14; params->offset88 = hnfData->offset18; params->offset8C = hnfData->offset1C; params->offset90 = hnfData->offset20; params->offset94 = hnfData->offset24; params->offset98 = hnfData->offset28; params->offset9C = hnfData->offset2C; params->offsetA0 = hnfData->offset30; block += sizeof(*hnfData); if (hnfData->directoryPidlLength) { LPITEMIDLIST pidl = NULL; if (*block) pidl = ILClone((LPITEMIDLIST) block); params->directoryPIDL = pidl; block += hnfData->directoryPidlLength; } if (hnfData->pidlSize7C) { LPITEMIDLIST pidl = NULL; if (*block) pidl = ILClone((LPITEMIDLIST) block); params->offset7C = pidl; block += hnfData->pidlSize80; } if (hnfData->pidlSize80) { if (!(params->offset84 & 0x8000)) { params->offset80 = *(LPITEMIDLIST *) block; } else { LPITEMIDLIST pidl = NULL; if (*block) pidl = ILClone((LPITEMIDLIST) block); params->offset80 = pidl; } block += hnfData->pidlSize80; } if (hnfData->pathLength) { CComPtr<IShellFolder> psfDesktop; PWSTR strPath = (PWSTR) block; if (FAILED(SHGetDesktopFolder(&psfDesktop))) { params->directoryPIDL = NULL; goto cleanup0; } if (FAILED(psfDesktop->ParseDisplayName(NULL, NULL, strPath, NULL, ¶ms->directoryPIDL, NULL))) { params->directoryPIDL = NULL; goto cleanup0; } } cleanup2: SHUnlockShared(hnfData); SHFreeShared(hData, pid); cleanup0: if (!params->directoryPIDL) { SHDestroyIETHREADPARAM(params); return NULL; } return params; }
HANDLE MakeSharedPacket(IEThreadParamBlock * threadParams, LPCWSTR strPath, int dwProcessId) { HNFBlock* hnfData; UINT sharedBlockSize = sizeof(*hnfData); UINT directoryPidlLength = 0; UINT pidlSize7C = 0; UINT pidlSize80 = 0; UINT pathLength = 0; LPITEMIDLIST pidl80 = threadParams->offset80; // Count the total length of the message packet // directory PIDL if (threadParams->directoryPIDL) { directoryPidlLength = ILGetSize(threadParams->directoryPIDL); sharedBlockSize += directoryPidlLength; DbgPrint("directoryPidlLength=%d\n", directoryPidlLength); } // another PIDL if (threadParams->offset7C) { pidlSize7C = ILGetSize(threadParams->offset7C); sharedBlockSize += pidlSize7C; DbgPrint("pidlSize7C=%d\n", pidlSize7C); } // This flag indicates the presence of another pidl? if (!(threadParams->offset84 & 0x8000)) { if (pidl80) { pidlSize80 = ILGetSize(pidl80); sharedBlockSize += pidlSize80; DbgPrint("pidlSize80=%d\n", pidlSize7C); } } else { DbgPrint("pidl80 sent by value = %p\n", pidl80); pidlSize80 = 4; sharedBlockSize += pidlSize80; } // The path string if (strPath) { pathLength = 2 * lstrlenW(strPath) + 2; sharedBlockSize += pathLength; DbgPrint("pathLength=%d\n", pidlSize7C); } DbgPrint("sharedBlockSize=%d\n", sharedBlockSize); // Allocate and fill the shared section HANDLE hShared = SHAllocShared(0, sharedBlockSize, dwProcessId); if (!hShared) { DbgPrint("Shared section alloc error.\n"); return 0; } PBYTE target = (PBYTE) SHLockShared(hShared, dwProcessId); if (!target) { DbgPrint("Shared section lock error. %d\n", GetLastError()); SHFreeShared(hShared, dwProcessId); return 0; } // Basic information hnfData = (HNFBlock*) target; hnfData->cbSize = sharedBlockSize; hnfData->offset4 = (DWORD) (threadParams->dwFlags); hnfData->offset8 = (DWORD) (threadParams->offset8); hnfData->offsetC = (DWORD) (threadParams->offset74); hnfData->offset10 = (DWORD) (threadParams->offsetD8); hnfData->offset14 = (DWORD) (threadParams->offset84); hnfData->offset18 = (DWORD) (threadParams->offset88); hnfData->offset1C = (DWORD) (threadParams->offset8C); hnfData->offset20 = (DWORD) (threadParams->offset90); hnfData->offset24 = (DWORD) (threadParams->offset94); hnfData->offset28 = (DWORD) (threadParams->offset98); hnfData->offset2C = (DWORD) (threadParams->offset9C); hnfData->offset30 = (DWORD) (threadParams->offsetA0); hnfData->directoryPidlLength = 0; hnfData->pidlSize7C = 0; hnfData->pidlSize80 = 0; hnfData->pathLength = 0; target += sizeof(*hnfData); // Copy the directory pidl contents if (threadParams->directoryPIDL) { memcpy(target, threadParams->directoryPIDL, directoryPidlLength); target += directoryPidlLength; hnfData->directoryPidlLength = directoryPidlLength; } // Copy the other pidl contents if (threadParams->offset7C) { memcpy(target, threadParams->offset7C, pidlSize7C); target += pidlSize7C; hnfData->pidlSize7C = pidlSize7C; } // copy the third pidl if (threadParams->offset84 & 0x8000) { *(LPITEMIDLIST*) target = pidl80; target += pidlSize80; hnfData->pidlSize80 = pidlSize80; } else if (pidl80) { memcpy(target, pidl80, pidlSize80); target += pidlSize80; hnfData->pidlSize80 = pidlSize80; } // and finally the path string if (strPath) { memcpy(target, strPath, pathLength); hnfData->pathLength = pathLength; } SHUnlockShared(hnfData); return hShared; }