Beispiel #1
0
LRESULT CALLBACK PopupMenuWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case WM_MEASUREITEM:
		if (Menu_MeasureItem((LPMEASUREITEMSTRUCT)lParam)) return TRUE;
		break;
	case WM_DRAWITEM:
		if (Menu_DrawItem((LPDRAWITEMSTRUCT)lParam)) return TRUE;
		break;
	case WM_COMMAND:
		if (Menu_ProcessCommandById(wParam, GetWindowLongPtr(hwnd, GWLP_USERDATA)))
			return TRUE;
		break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
Beispiel #2
0
CJabberProto* JabberChooseInstance(bool bIsLink)
{
    if (g_Instances.getCount() == 0)
        return NULL;

    if (g_Instances.getCount() == 1) {
        if (g_Instances[0]->m_iStatus != ID_STATUS_OFFLINE && g_Instances[0]->m_iStatus != ID_STATUS_CONNECTING)
            return g_Instances[0];
        return NULL;
    }

    if (bIsLink)
        for (int i = 0; i < g_Instances.getCount(); i++)
            if (g_Instances[i]->m_options.ProcessXMPPLinks)
                return g_Instances[i];

    int nItems = 0, lastItemId = 0;
    for (int i = 0; i < g_Instances.getCount(); i++) {
        CJabberProto *ppro = g_Instances[i];
        if (ppro->m_iStatus != ID_STATUS_OFFLINE && ppro->m_iStatus != ID_STATUS_CONNECTING) {
            ++nItems;
            lastItemId = i + 1;
            Menu_ModifyItem(ppro->m_hChooseMenuItem, NULL, Skin_LoadProtoIcon(ppro->m_szModuleName, ppro->m_iStatus));
        }
        else Menu_ShowItem(ppro->m_hChooseMenuItem, false);
    }

    if (nItems > 1) {
        POINT pt;
        GetCursorPos(&pt);

        HMENU hMenu = CreatePopupMenu();
        Menu_Build(hMenu, hChooserMenu);
        int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, pcli->hwndContactList, NULL);
        DestroyMenu(hMenu);

        if (res) {
            CJabberProto* pro = NULL;
            Menu_ProcessCommandById(res, (LPARAM)&pro);
            return pro;
        }

        return NULL;
    }

    return lastItemId ? g_Instances[lastItemId - 1] : NULL;
}