正在开发中的游戏有个全屏功能--可以在window桌面背景上运行,就像一些视频播放器在桌面背景上播放一样的,花了个上午整了个Demo放出来留个纪念。

实现功能:显示图标,双击图标执行相应的程序,右击图标弹出该图标对应得菜单,点击非图标区则弹出桌面菜单。需要完整工程可以点此下载:DesktopWindow.rar。程序效果图如下:

模拟window桌面实现_Windows

 在这个程序里,定义了一个XShellItem的数据结构,保持桌面图标的iten id(ITEMIDLiST),图标以及文字图标。

模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    struct XShellItem ...{
模拟window桌面实现_Windows_04        ITEMIDLIST*     itemId;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        int x;
模拟window桌面实现_Windows_04        int y;
模拟window桌面实现_Windows_04        int w;
模拟window桌面实现_Windows_04        int h;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        int nameX;
模拟window桌面实现_Windows_04        int nameY;
模拟window桌面实现_Windows_04        int nameW;
模拟window桌面实现_Windows_04        int nameH;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        BOOL hit;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        CStringW name;
模拟window桌面实现_Windows_04        Bitmap*     icon;
模拟window桌面实现_Windows_04        Bitmap*     nameIcon;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        XShellItem()
模拟window桌面实现_Windows_04        :
模拟window桌面实现_Windows_04        itemId(NULL),
模拟window桌面实现_Windows_04        x(0),
模拟window桌面实现_Windows_04        y(0),
模拟window桌面实现_Windows_04        w(0),
模拟window桌面实现_Windows_04        h(0),
模拟window桌面实现_Windows_04        nameX(0),
模拟window桌面实现_Windows_04        nameY(0),
模拟window桌面实现_Windows_04        nameW(0),
模拟window桌面实现_Windows_04        nameH(0),
模拟window桌面实现_Windows_04        name(L""),
模拟window桌面实现_Windows_04        hit(FALSE),
模拟window桌面实现_Windows_04        icon(NULL),
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        nameIcon(NULL) ...{
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        ~XShellItem() ...{
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_42    };

然后定义一个数组CAtlArray<XShellItem> itemArray;用来保存所有桌面图标对象,在InitShellFolder()中对它进行初始化:

模拟window桌面实现_Windows_43    // 获取桌面图标的相关数据
模拟window桌面实现_Windows_43    BOOL InitShellFolder()
模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    ...{
模拟window桌面实现_Windows_04        HRESULT hRslt = SHGetDesktopFolder(&folder);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (FAILED(hRslt)) ...{
模拟window桌面实现_Windows_04            return FALSE;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        CComPtr<IEnumIDList> ids;
模拟window桌面实现_Windows_04        hRslt = folder->EnumObjects(0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ids);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (FAILED(hRslt)) ...{
模拟window桌面实现_Windows_04            return FALSE;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        CAtlList<XShellItem> items;
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        for (;;) ...{
模拟window桌面实现_Windows_04            ITEMIDLIST*     id = 0;
模拟window桌面实现_Windows_04            ULONG cIds = 0;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            hRslt = ids->Next(1, &id, &cIds);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (hRslt != S_OK) ...{
模拟window桌面实现_Windows_04                break;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            CStringW name;
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            STRRET str = ...{ 0};
模拟window桌面实现_Windows_04            hRslt = folder->GetDisplayNameOf(id, SHGDN_NORMAL | SHGDN_INFOLDER, &str);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (SUCCEEDED(hRslt)) ...{
模拟window桌面实现_Windows_04                LPWSTR pname = 0;
模拟window桌面实现_Windows_04                StrRetToStrW(&str, id, &pname);
模拟window桌面实现_Windows_04                name = pname;
模拟window桌面实现_Windows_04                CoTaskMemFree(pname);
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            XShellItem item;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            item.itemId = id;
模拟window桌面实现_Windows_04            item.name = name;
模拟window桌面实现_Windows_04            items.AddTail(item);
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        SIZE_T iItem = 0;
模拟window桌面实现_Windows_04        SIZE_T cItems = items.GetCount();
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        itemArray.SetCount(cItems);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        POSITION pos = items.GetHeadPosition();
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        while (pos != 0) ...{
模拟window桌面实现_Windows_04            XShellItem&     si = items.GetNext(pos);
模拟window桌面实现_Windows_04            itemArray[iItem] = si;
模拟window桌面实现_Windows_04            iItem++;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        HDC hDC = CreateCompatibleDC(0);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        Graphics g(hDC);
模拟window桌面实现_Windows_04        g.Clear(Color(0, 0, 0, 0));
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        ICONMETRICS im = ...{ 0};
模拟window桌面实现_Windows_04        im.cbSize = sizeof(im);
模拟window桌面实现_Windows_04        SystemParametersInfo(SPI_GETICONMETRICS, sizeof(im), &im, 0);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        SolidBrush br_t(Color(255, 255, 255));
模拟window桌面实现_Windows_04        Font font_i(hDC, &(im.lfFont));
模拟window桌面实现_Windows_04        float fcy = font_i.GetHeight(&g) * 2 + 2;
模拟window桌面实现_Windows_04        DeleteDC(hDC);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        Gdiplus::StringFormat sf(Gdiplus::StringFormat::GenericTypographic());
模拟window桌面实现_Windows_04        sf.SetAlignment(Gdiplus::StringAlignmentCenter);
模拟window桌面实现_Windows_04        sf.SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        iconSpacingWidth = im.iHorzSpacing + OFFSET_WIDTH;
模拟window桌面实现_Windows_04        iconSpacingHeight = im.iVertSpacing + OFFSET_HEIGHT;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        int iconWidth = GetSystemMetrics(SM_CXICON);
模拟window桌面实现_Windows_04        int iconHeight = GetSystemMetrics(SM_CYICON);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        for (SIZE_T i = 0; i < cItems; i++) ...{
模拟window桌面实现_Windows_04            XShellItem&     item = itemArray[i];
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            // SHGetFileInfo
模拟window桌面实现_Windows_04            HICON hIcon = 0;
模拟window桌面实现_Windows_04            HIMAGELIST hImgList;
模拟window桌面实现_Windows_04            SHFILEINFO stSHFileInfo;
模拟window桌面实现_Windows_04            CImageList cImgList;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            // 获取图标
模拟window桌面实现_Windows_04            hImgList = (HIMAGELIST)::SHGetFileInfo(
模拟window桌面实现_Windows_04                    (LPCWSTR) item.itemId,
模拟window桌面实现_Windows_04                    0,
模拟window桌面实现_Windows_04                    &stSHFileInfo,
模拟window桌面实现_Windows_04                    sizeof(SHFILEINFO),
模拟window桌面实现_Windows_04                    SHGFI_PIDL | SHGFI_ICON | SHGFI_LARGEICON | SHGFI_SYSICONINDEX);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            // DIBSection 8bit
模拟window桌面实现_Windows_04            BITMAPINFO bmi;
模拟window桌面实现_Windows_04            BITMAPINFOHEADER&  bmih = bmi.bmiHeader;
模拟window桌面实现_Windows_04            bmih.biSize = sizeof(bmih);
模拟window桌面实现_Windows_04            bmih.biWidth = ICON_WIDTH;
模拟window桌面实现_Windows_04            bmih.biHeight = -ICON_HEIGHT;    // BMP反转
模拟window桌面实现_Windows_04            bmih.biPlanes = 1;
模拟window桌面实现_Windows_04            bmih.biBitCount = 32;
模拟window桌面实现_Windows_04            bmih.biCompression = BI_RGB;
模拟window桌面实现_Windows_04            bmih.biSizeImage = 0;
模拟window桌面实现_Windows_04            bmih.biXPelsPerMeter = 0;
模拟window桌面实现_Windows_04            bmih.biYPelsPerMeter = 0;
模拟window桌面实现_Windows_04            bmih.biClrUsed = 0;
模拟window桌面实现_Windows_04            bmih.biClrImportant = 0;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            HDC memDC = CreateCompatibleDC(0);
模拟window桌面实现_Windows_04            void*  pDib = 0;
模拟window桌面实现_Windows_04            HBITMAP hBmp = CreateDIBSection(memDC, &bmi, DIB_RGB_COLORS, &pDib, 0, 0);
模拟window桌面实现_Windows_04            GdiFlush();
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            HGDIOBJ old = SelectObject(memDC, hBmp);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            // ImageList_Draw WindowsXP
模拟window桌面实现_Windows_04            ImageList_SetBkColor(hImgList, 0x0);
模拟window桌面实现_Windows_04            ImageList_Draw(hImgList, stSHFileInfo.iIcon, memDC, 0, 0, ILD_NORMAL);
模拟window桌面实现_Windows_04            SelectObject(memDC, old);
模拟window桌面实现_Windows_04            DeleteDC(memDC);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            cImgList.Attach(hImgList);
模拟window桌面实现_Windows_04            hIcon = cImgList.ExtractIcon(stSHFileInfo.iIcon);
模拟window桌面实现_Windows_04            cImgList.Detach();
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (hIcon != 0) ...{
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04                // Bitmap::FromHICON 0~255
模拟window桌面实现_Windows_04                item.icon = Bitmap::FromHICON(hIcon);
模拟window桌面实现_Windows_04                item.w = iconWidth;
模拟window桌面实现_Windows_04                item.h = iconHeight;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04                Gdiplus::RectF rc(float(2), float(2), float(iconSpacingWidth - 4), fcy);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04                Gdiplus::Bitmap * nameIcon = new Bitmap(NAME_WIDTH, NAME_HEIGHT, &g);
模拟window桌面实现_Windows_04                Gdiplus::Graphics * g2 = Gdiplus::Graphics::FromImage(nameIcon);
模拟window桌面实现_Windows_04                g2->Clear(Gdiplus::Color(Gdiplus::ARGB(0)));
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04                g2->DrawString(item.name, item.name.GetLength(), &font_i, rc, &sf, &br_t);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04                item.nameIcon = nameIcon;
模拟window桌面实现_Windows_04                item.nameW = NAME_WIDTH;
模拟window桌面实现_Windows_04                item.nameH = NAME_HEIGHT;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04                delete g2;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            DestroyIcon(hIcon);
模拟window桌面实现_Windows_04            DeleteObject(hBmp);
模拟window桌面实现_Windows_04            DestroyIcon(stSHFileInfo.hIcon);
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        return TRUE;
模拟window桌面实现_Windows_42    }

注意这里面并没有设置图标对象的位置,因为当窗口改变大小的时候,相应地也要调整图标的描绘位置,所以图标位置是在SetShellItemPosition()中动态调整的.

模拟window桌面实现_Windows_43    // 根据窗口大小设置图标位置
模拟window桌面实现_Windows_43    void SetShellItemPosition()
模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    ...{
模拟window桌面实现_Windows_04        int iconWidth = GetSystemMetrics(SM_CXICON);
模拟window桌面实现_Windows_04        int iconHeight = GetSystemMetrics(SM_CYICON);
模拟window桌面实现_Windows_04        static const int OFFSET_Y = 20;
模拟window桌面实现_Windows_04        int x = 0;
模拟window桌面实现_Windows_04        int y = OFFSET_Y;
模拟window桌面实现_Windows_04        SIZE_T cItems = itemArray.GetCount();
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        for (SIZE_T i = 0; i < cItems; i++) ...{
模拟window桌面实现_Windows_04            XShellItem&     item = itemArray[i];
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (item.icon) ...{
模拟window桌面实现_Windows_04                item.x = x + (iconSpacingWidth - iconWidth) / 2;
模拟window桌面实现_Windows_04                item.y = y;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (item.nameIcon) ...{
模拟window桌面实现_Windows_04                item.nameX = x;
模拟window桌面实现_Windows_04                item.nameY = y + iconHeight + 2;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            WTL::CRect rect;
模拟window桌面实现_Windows_04            GetClientRect(&rect);
模拟window桌面实现_Windows_04            y += iconSpacingHeight;
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (y + iconSpacingHeight >= rect.bottom) ...{
模拟window桌面实现_Windows_04                x += iconSpacingWidth;
模拟window桌面实现_Windows_04                y = OFFSET_Y;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_42    }

描绘图标就很简单了,呵呵,不贴了,下面来说说弹出图标菜单,执行图标对应的程序以及弹出桌面菜单。

执行图标对应的程序,需要以先前保持的图标itemid作为参数,代码如下:

模拟window桌面实现_Windows_43    void RunShellItem(ITEMIDLIST* pIID)
模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    ...{
模拟window桌面实现_Windows_04        SHELLEXECUTEINFO info;
模拟window桌面实现_Windows_04        info.cbSize = sizeof(SHELLEXECUTEINFO);
模拟window桌面实现_Windows_04        info.fMask = SEE_MASK_INVOKEIDLIST;
模拟window桌面实现_Windows_04        info.hwnd = m_hWnd;
模拟window桌面实现_Windows_04        info.lpVerb = NULL;
模拟window桌面实现_Windows_04        info.lpFile = NULL;
模拟window桌面实现_Windows_04        info.lpParameters = NULL;
模拟window桌面实现_Windows_04        info.lpDirectory = NULL;
模拟window桌面实现_Windows_04        info.nShow = SW_SHOWNORMAL;
模拟window桌面实现_Windows_04        info.hInstApp = NULL;
模拟window桌面实现_Windows_04        info.lpIDList = pIID;
模拟window桌面实现_Windows_04        ShellExecuteEx(&info);
模拟window桌面实现_Windows_42    }

弹出桌面菜单的代码如下:

模拟window桌面实现_Windows_43    // 桌面菜单
模拟window桌面实现_Windows_43    void DesktopMenu()
模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    ...{
模拟window桌面实现_Windows_04        HWND program = FindWindowEx(0, 0, _T("Progman"), _T("Program Manager"));
模拟window桌面实现_Windows_04        HWND view = FindWindowEx(program, 0, _T("SHELLDLL_DefView"), 0);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        //HWND list = FindWindowEx(view, 0, _T("SysListView32"), 0);
模拟window桌面实现_Windows_04        ::SetForegroundWindow(view);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        POINT pt;
模拟window桌面实现_Windows_04        GetCursorPos(&pt);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        LPARAM lp = pt.y << 16 | (pt.x - 32);
模拟window桌面实现_Windows_04        ::PostMessage(view, WM_LBUTTONDOWN, 0, lp);
模拟window桌面实现_Windows_04        ::PostMessage(view, WM_RBUTTONUP, 0, lp);
模拟window桌面实现_Windows_42    }

弹出图标菜单的代码如下,这里定义了两个全局的IContextMenu对象:
static IContextMenu2*  g_pIContext2 = NULL;
static IContextMenu3*  g_pIContext3 = NULL;

以便在消息回调函数中使用。具体代码如下:

模拟window桌面实现_Windows_43    // 图标菜单
模拟window桌面实现_Windows_43    void RightMenu(ITEMIDLIST* pIID)
模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    ...{
模拟window桌面实现_Windows_04        HWND hwnd = m_hWnd;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        LPCONTEXTMENU pContextMenu = NULL;
模拟window桌面实现_Windows_04        LPCONTEXTMENU pCtxMenuTemp = NULL;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        g_pIContext2 = NULL;
模拟window桌面实现_Windows_04        g_pIContext3 = NULL;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        int menuType = 0;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        HRESULT hRslt = folder->GetUIObjectOf(
模拟window桌面实现_Windows_04                hwnd,
模拟window桌面实现_Windows_04                1,
模拟window桌面实现_Windows_04                (LPCITEMIDLIST*) &(pIID),
模拟window桌面实现_Windows_04                IID_IContextMenu,
模拟window桌面实现_Windows_04                0,
模拟window桌面实现_Windows_04                (void**) &pCtxMenuTemp);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (FAILED(hRslt)) ...{
模拟window桌面实现_Windows_04            return;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        POINT pt;
模拟window桌面实现_Windows_04        GetCursorPos(&pt);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (pCtxMenuTemp->QueryInterface(IID_IContextMenu3, (void**) &pContextMenu) == NOERROR) ...{
模拟window桌面实现_Windows_04            menuType = 3;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        else if (pCtxMenuTemp->QueryInterface(IID_IContextMenu2, (void**) &pContextMenu) == NOERROR) ...{
模拟window桌面实现_Windows_04            menuType = 2;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (pContextMenu) ...{
模拟window桌面实现_Windows_04            pCtxMenuTemp->Release();
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        else ...{
模拟window桌面实现_Windows_04            pContextMenu = pCtxMenuTemp;
模拟window桌面实现_Windows_04            menuType = 1;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (menuType == 0) ...{
模拟window桌面实现_Windows_04            return;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        HMENU hMenu = CreatePopupMenu();
模拟window桌面实现_Windows_04        hRslt = pContextMenu->QueryContextMenu(hMenu, 0, 1, 0x7fff, CMF_NORMAL | CMF_EXPLORE);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (FAILED(hRslt)) ...{
模拟window桌面实现_Windows_04            return;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04#ifndef _WIN64
模拟window桌面实现_Windows_04    #pragma warning(disable : 4244 4311)
模拟window桌面实现_Windows_04#endif
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        // subclass window
模拟window桌面实现_Windows_04        WNDPROC oldWndProc = NULL;
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (menuType > 1) ...{
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            // only subclass if it is IID_IContextMenu2 or IID_IContextMenu3
模拟window桌面实现_Windows_04            oldWndProc = (WNDPROC) SetWindowLongPtr(GWL_WNDPROC, (LONG) HookWndProc);
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (menuType == 2) ...{
模拟window桌面实现_Windows_04                g_pIContext2 = (LPCONTEXTMENU2) pContextMenu;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            else ...{
模拟window桌面实现_Windows_04                g_pIContext3 = (LPCONTEXTMENU3) pContextMenu;
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        else ...{
模拟window桌面实现_Windows_04            oldWndProc = NULL;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        int cmd = ::TrackPopupMenu(
模拟window桌面实现_Windows_04                hMenu,
模拟window桌面实现_Windows_04                TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON,
模拟window桌面实现_Windows_04                pt.x,
模拟window桌面实现_Windows_04                pt.y,
模拟window桌面实现_Windows_04                0,
模拟window桌面实现_Windows_04                hwnd,
模拟window桌面实现_Windows_04                0);
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        // unsubclass
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (oldWndProc) ...{
模拟window桌面实现_Windows_04            SetWindowLongPtr(GWL_WNDPROC, (LONG) oldWndProc);
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04#ifndef _WIN64
模拟window桌面实现_Windows_04    #pragma warning(default : 4244 4311)
模拟window桌面实现_Windows_04#endif
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        if (cmd != 0) ...{
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            CMINVOKECOMMANDINFO ci = ...{ 0};
模拟window桌面实现_Windows_04            ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
模拟window桌面实现_Windows_04            ci.hwnd = hwnd;
模拟window桌面实现_Windows_04            ci.lpVerb = (LPCSTR) MAKEINTRESOURCE(cmd - 1);
模拟window桌面实现_Windows_04            ci.nShow = SW_SHOWNORMAL;
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            pContextMenu->InvokeCommand(&ci);
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        pContextMenu->Release();
模拟window桌面实现_Windows_04        g_pIContext2 = NULL;
模拟window桌面实现_Windows_04        g_pIContext3 = NULL;
模拟window桌面实现_Windows_04        ::DestroyMenu(hMenu);
模拟window桌面实现_Windows_42    }
模拟window桌面实现_Windows_43
模拟window桌面实现_Windows_43    static LRESULT CALLBACK HookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
模拟window桌面实现_Windows_02模拟window桌面实现_Windows_03    ...{
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37        switch (message) ...{
模拟window桌面实现_Windows_04        case WM_MENUCHAR:    // only supported by IContextMenu3
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (g_pIContext3) ...{
模拟window桌面实现_Windows_04                LRESULT lResult = 0;
模拟window桌面实现_Windows_04                g_pIContext3->HandleMenuMsg2(message, wParam, lParam, &lResult);
模拟window桌面实现_Windows_04                return(lResult);
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04            break;
模拟window桌面实现_Windows_04        case WM_DRAWITEM:
模拟window桌面实现_Windows_04        case WM_MEASUREITEM:
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (wParam) ...{
模拟window桌面实现_Windows_04                break;    // if wParam != 0 then the message is not menu-related
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        case WM_INITMENUPOPUP:
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            if (g_pIContext2) ...{
模拟window桌面实现_Windows_04                g_pIContext2->HandleMenuMsg(message, wParam, lParam);
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_36模拟window桌面实现_Windows_37            else ...{
模拟window桌面实现_Windows_04                g_pIContext3->HandleMenuMsg(message, wParam, lParam);
模拟window桌面实现_Windows_38            }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04            return(message == WM_INITMENUPOPUP ? 0 : TRUE);
模拟window桌面实现_Windows_04            break;
模拟window桌面实现_Windows_04        default:
模拟window桌面实现_Windows_04            break;
模拟window桌面实现_Windows_38        }
模拟window桌面实现_Windows_04
模拟window桌面实现_Windows_04        return ::CallWindowProc((WNDPROC) GetProp(hWnd, TEXT("oldWndProc")), hWnd, message, wParam, lParam);
模拟window桌面实现_Windows_42    }
jpg改rar 模拟window桌面实现_Windows_436