⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myicqdlg.cpp

📁 局域网ICQ的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			OnSysMessage();
		else {
			IcqContact *c = findContact(msg->uin);
			if (c)
				onItemDoubleClicked(c);
		}
	}
}

void CIcqDlg::saveGroupInfo()
{
	IcqDB::saveGroupInfo(outbarCtrl);
}

BOOL CIcqDlg::loadGroupInfo()
{
	if (!IcqDB::loadContact(contactList))
		return FALSE;
	
	if (!IcqDB::loadGroupInfo(outbarCtrl) || outbarCtrl.getFolderCount() < 3)
		return FALSE;
	return TRUE;
}

BOOL CIcqDlg::loadPlugins()
{
	CString dir = getApp()->rootDir + "plugins\\*.dll";
	CFileFind finder;
	BOOL cont = finder.FindFile(dir);

	while (cont) {
		cont = finder.FindNextFile();
		HINSTANCE module = AfxLoadLibrary(finder.GetFilePath());
		if (!module)
			continue;

		GETTYPE getType = (GETTYPE) GetProcAddress(module, "getType");
		if (getType) {
			int type = getType();
			IcqPlugin *plugin = NULL;
			if (type == ICQ_PLUGIN_NET) {
				NetPlugin *p = new NetPlugin;
				p->getNameIcon = (GETNAMEICON) GetProcAddress(module, "getNameIcon");
				p->createSession = (CREATESESSION) GetProcAddress(module, "createSession");
				plugin = p;
			} else if (type == ICQ_PLUGIN_TOY) {
				ToyPlugin *p = new ToyPlugin;
				p->getNameIcon = (GETNAMEICON) GetProcAddress(module, "getNameIcon");
				p->init = (INIT) GetProcAddress(module, "init");
				p->configure = (CONFIGURE) GetProcAddress(module, "configure");
				p->about = (ABOUT) GetProcAddress(module, "about");
				plugin = p;
			}

			plugin->type = type;
			plugin->name = finder.GetFileTitle();
			PluginFactory::registerPlugin(plugin);
		}
	}

	HICON icon = AfxGetApp()->LoadIcon(IDI_PLUGIN);

	dir = getApp()->rootDir + "plugins\\*.ini";
	cont = finder.FindFile(dir);
	while (cont) {
		cont = finder.FindNextFile();

		ExePlugin *p = new ExePlugin;
		p->type = ICQ_PLUGIN_EXE;
		p->name = finder.GetFileTitle();
		p->icon = icon;
		const char *name = p->name.c_str();
		CString file = finder.GetFilePath();

		char buf[1024];
		GetPrivateProfileString(name, "name", name, buf, sizeof(buf), file);
		p->locName = buf;
		GetPrivateProfileString(name, "client", NULL, buf, sizeof(buf), file);
		p->clientCmd = buf;
		GetPrivateProfileString(name, "server", NULL, buf, sizeof(buf), file);
		p->serverCmd = buf;

		PluginFactory::registerPlugin(p);
	}

	return TRUE;
}

void CIcqDlg::renamed(int obj, int index, const char *text) 
{
	if (obj == OutBarCtrl::HT_FOLDER)
		saveGroupInfo();
	else if (obj == OutBarCtrl::HT_ITEM) {
		IcqContact *c = outbarCtrl.contact(index);
		if (c) {
			c->nick = text;
			IcqDB::saveContact(*c);
		}
	}
}

void CIcqDlg::itemDragged(int item, int toFolder)
{
	IcqContact *c = outbarCtrl.contact(item);
	int fromFolder = outbarCtrl.getSelFolder();
	int n = outbarCtrl.getFolderCount();

	if (fromFolder >= n - 2 && toFolder < n - 2)
		addFriend(c, toFolder);
	else if (fromFolder < n - 2 && toFolder >= n - 2)
		delFriend(c, toFolder);
	else {
		c->type = (toFolder == n - 1 ? CONTACT_IGNORE : CONTACT_STRANGER);
		outbarCtrl.removeContact(c->uin);
		outbarCtrl.addContact(toFolder, c);
		saveGroupInfo();
	}
}

void CIcqDlg::selFolderChanged(int folder)
{
	options.playSound(SOUND_FOLDER);
}

void CIcqDlg::itemClicked(int item)
{
	curContact = outbarCtrl.contact(item);

	CGfxPopupMenu menu;
	CMenu tmp;

	int sel = outbarCtrl.getSelFolder();
	int n = outbarCtrl.getFolderCount();
	if (sel < n - 2)
		tmp.LoadMenu(IDR_CONTACT);
	else if (sel < n - 1)
		tmp.LoadMenu(IDR_STRANGER);
	else
		tmp.LoadMenu(IDR_IGNORE);
	menu.Attach(*tmp.GetSubMenu(0));

	if (sel < n - 2) {
		UINT id = ID_PLUGIN;
		PtrList &l = PluginFactory::getPluginList();
		PtrList::iterator it;
		for (it = l.begin(); it != l.end(); ++it) {
			IcqPlugin *plugin = (IcqPlugin *) *it;
			string name;
			HICON icon = NULL;
			int type = plugin->type;
			if (type == ICQ_PLUGIN_NET) {
				NetPlugin *p = (NetPlugin *) plugin;
				if (p->getNameIcon)
					icon = (HICON) p->getNameIcon(name);
				else
					name = p->name;
			} else if (type == ICQ_PLUGIN_EXE) {
				ExePlugin *p = (ExePlugin *) plugin;
				name = p->locName;
				icon = (HICON) p->icon;
			} else
				continue;

			menu.AppendMenu(0, id, name.c_str());
			menu.modifyMenu(id++, icon);
		}
	}

	menu.modifyMenu(ID_SEND_MSG, IDB_SEND_MSG);
	menu.modifyMenu(ID_SEND_EMAIL, IDB_SEND_EMAIL);
	menu.modifyMenu(ID_HOMEPAGE, IDB_HOMEPAGE);
	menu.modifyMenu(ID_MSG_HISTORY, IDB_MSG_HISTORY);
	menu.modifyMenu(ID_VIEW_DETAIL, IDB_VIEW_DETAIL);
	menu.modifyMenu(ID_ADD_AS_FRIEND, IDB_ADD);

	menu.EnableMenuItems(&menu, this);

	CPoint pt;
	::GetCursorPos(&pt);
	currentMenu = &menu;
	menu.TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this);
	currentMenu = NULL;
}

void CIcqDlg::rightButtonDown(int obj, int index)
{
	CGfxPopupMenu menu;
	CMenu tmp;
	tmp.LoadMenu(IDR_OUTBAR);
	menu.Attach(*tmp.GetSubMenu(0));

	menu.modifyMenu(ID_GFX_SMALLICON, IDB_SMALLICON);
	menu.modifyMenu(ID_GFX_LARGEICON, IDB_LARGEICON);
	menu.modifyMenu(ID_GFX_ADDGROUP, IDB_ADDGROUP);
	menu.modifyMenu(ID_GFX_FONTCOLOR, IDB_FONTCOLOR);
	menu.modifyMenu(ID_GFX_BACKGROUND, IDB_BACKGROUND);
	menu.appendMenu(ID_GFX_SHOWONLINE, IDB_SHOWONLINE, outbarCtrl.showOnlineOnly() ? IDS_SHOWALL : IDS_SHOWONLINE);

	if (obj == OutBarCtrl::HT_ITEM) {
		menu.AppendMenu(MF_SEPARATOR);
		menu.appendMenu(ID_GFX_REMOVE, IDB_REMOVEITEM, IDS_REMOVEITEM);
		menu.appendMenu(ID_GFX_RENAME, IDB_RENAME, IDS_RENAMEITEM);

	} else if (obj == OutBarCtrl::HT_FOLDER) {
		int n = outbarCtrl.getFolderCount();
		if (index > 0 && index < n - 2) {
			menu.AppendMenu(MF_SEPARATOR);
			menu.appendMenu(ID_GFX_REMOVE, IDB_REMOVEGROUP, IDS_REMOVEGROUP);
			menu.appendMenu(ID_GFX_RENAME, IDB_RENAME, IDS_RENAMEGROUP);
		}
	}

	menu.EnableMenuItems(&menu, this);
	CPoint pt;
	::GetCursorPos(&pt);
	currentMenu = &menu;
	menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this);
	currentMenu = NULL;
}

void CIcqDlg::itemDoubleClicked(int item)
{
	onItemDoubleClicked(outbarCtrl.contact(item));
}

void CIcqDlg::onItemDoubleClicked(IcqContact *c)
{
	int sel = outbarCtrl.getSelFolder();
	int n = outbarCtrl.getFolderCount();
	
	IcqMsg *msg = fetchMsg(c->uin);
	if (msg && msg->type == MSG_TCP_REQUEST) {
		if (sel < n - 2) {
			CSendRequestDlg *dlg = new CSendRequestDlg(msg);
			dlg->Create(IDD_SEND_REQUEST);
			delete msg;
		}
	} else {
		curContact = c;
		
		if (sel < n - 1) {
			if (msg)
				msgList.push_front(msg);
			OnSendMessage();
		} else
			OnViewDetail();
	}
}

HANDLE CIcqDlg::getHostByName(const char *name)
{
	return WSAAsyncGetHostByName(m_hWnd, WM_HOSTFOUND, name, hostBuf, sizeof(hostBuf));
}

void CIcqDlg::DoDataExchange(CDataExchange* pDX)
{
	CCaptionBtnDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIcqDlg)
	DDX_Control(pDX, ID_STATISTICS, m_btnStat);
	DDX_Control(pDX, ID_ABOUT, m_btnAbout);
	DDX_Control(pDX, IDC_MAIN_MENU, m_btnMain);
	DDX_Control(pDX, IDC_STATUS, m_btnStatus);
	DDX_Control(pDX, IDC_SYS_MESSAGE, m_btnSysMsg);
	DDX_Control(pDX, IDC_FIND_CONTACT, m_btnSearch);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIcqDlg, CCaptionBtnDlg)
	//{{AFX_MSG_MAP(CIcqDlg)
	ON_WM_SIZE()
	ON_WM_GETMINMAXINFO()
	ON_COMMAND(ID_SEND_MSG, OnSendMessage)
	ON_COMMAND(ID_VIEW_DETAIL, OnViewDetail)
	ON_BN_CLICKED(IDC_FIND_CONTACT, OnFindContact)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_SYS_MESSAGE, OnSysMessage)
	ON_WM_NCHITTEST()
	ON_BN_CLICKED(IDC_MAIN_MENU, OnMainMenu)
	ON_COMMAND(ID_GFX_SMALLICON, OnGfxSmallIcon)
	ON_UPDATE_COMMAND_UI(ID_GFX_SMALLICON, OnUpdateGfxSmallIcon)
	ON_COMMAND(ID_GFX_LARGEICON, OnGfxLargeIcon)
	ON_UPDATE_COMMAND_UI(ID_GFX_LARGEICON, OnUpdateGfxLargeIcon)
	ON_COMMAND(ID_GFX_FONTCOLOR, OnGfxFontColor)
	ON_COMMAND(ID_GFX_BACKGROUND, OnGfxBackground)
	ON_COMMAND(ID_GFX_ADDGROUP, OnGfxAddGroup)
	ON_UPDATE_COMMAND_UI(ID_GFX_ADDGROUP, OnUpdateGfxAddGroup)
	ON_COMMAND(ID_GFX_REMOVE, OnGfxRemove)
	ON_COMMAND(ID_GFX_RENAME, OnGfxRename)
	ON_COMMAND(ID_MODIFY_INFO, OnModifyInfo)
	ON_COMMAND(ID_GFX_SHOWONLINE, OnGfxShowOnline)
	ON_BN_CLICKED(IDC_STATUS, OnStatus)
	ON_COMMAND(ID_STATUS_ONLINE, OnStatusOnline)
	ON_COMMAND(ID_STATUS_OFFLINE, OnStatusOffline)
	ON_COMMAND(ID_STATUS_INVIS, OnStatusInvis)
	ON_COMMAND(ID_SYS_OPTION, OnSysOption)
	ON_COMMAND(ID_STATUS_AWAY_CUSTOM, OnStatusAwayCustom)
	ON_COMMAND(ID_STATUS_AWAY_NOREPLY, OnStatusAwayNoReply)
	ON_WM_MEASUREITEM()
	ON_COMMAND(ID_REG_WIZARD, OnRegWizard)
	ON_COMMAND(ID_CHANGE_USER, OnChangeUser)
	ON_BN_CLICKED(ID_ABOUT, OnAbout)
	ON_WM_DESTROY()
	ON_WM_MOVING()
	ON_COMMAND(ID_SEND_EMAIL, OnSendEmail)
	ON_COMMAND(ID_HOMEPAGE, OnHomePage)
	ON_COMMAND(ID_ADD_AS_FRIEND, OnAddAsFriend)
	ON_COMMAND(ID_MSG_HISTORY, OnMsgHistory)
	ON_COMMAND(ID_MESSAGE_MGR, OnMessageMgr)
	ON_COMMAND(ID_BROADCAST_MSG, OnBroadcastMsg)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_HOSTFOUND, OnHostFound)
	ON_MESSAGE(WM_HOTKEY, OnHotKey)
	ON_MESSAGE(WM_NOTIFYICON, OnNotifyIcon)
	ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipText)
	ON_COMMAND_RANGE(ID_STATUS_AWAY, ID_STATUS_AWAY + 9, OnStatusAway)
	ON_COMMAND_RANGE(ID_PLUGIN, ID_PLUGIN + 1000, OnPlugin)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIcqDlg message handlers

BOOL CIcqDlg::OnInitDialog()
{
	CCaptionBtnDlg::OnInitDialog();

	toolTip.Create(this);
	CRect rc;
	GetWindowRect(rc);
	ScreenToClient(rc);
	toolTip.AddTool(this, LPSTR_TEXTCALLBACK, rc, ID_TOOLTIP);

	m_btnSearch.SetIcon(IDI_FIND);
	m_btnSysMsg.SetIcon(iconSysMsg);
	m_btnAbout.SetIcon(IDI_ABOUT);
	m_btnStat.SetIcon(IDI_STAT);
	m_btnMain.SetFlat(FALSE, FALSE);

	statusImgList.Create(16, 16, ILC_MASK | ILC_COLOR8, 4, 0);
	UINT id[] = {
		IDB_STATUS_ONLINE,
		IDB_STATUS_OFFLINE,
		IDB_STATUS_AWAY,
		IDB_STATUS_INVIS
	};
	CBitmap bm;
	for (int i = 0; i < 4; i++) {
		bm.LoadBitmap(id[i]);
		statusImgList.Add(&bm, RGB(192, 192, 192));
		bm.DeleteObject();
	}

	m_btnStatus.SetTooltipText(IDS_CHANGE_STATUS);
	m_btnMain.SetTooltipText(IDS_MAINMENU);
	m_btnSearch.SetTooltipText(IDS_SEARCH);
	m_btnSysMsg.SetTooltipText(IDS_SYSMSG);
	m_btnAbout.SetTooltipText(IDS_ABOUT);
	m_btnStat.SetTooltipText(IDS_STATISTICS);

	outbarCtrl.CreateEx(WS_EX_CLIENTEDGE, NULL, NULL, WS_VISIBLE | WS_CHILD,
		CRect(0, 0, 0, 0), this, IDC_OUTBAR);

	loadPlugins();

	if (!doLogin()) {
		EndDialog(IDCANCEL);
		return TRUE;
	}

	outbarCtrl.SetFocus();
	return FALSE;
}

void CIcqDlg::OnSize(UINT nType, int cx, int cy) 
{
	CCaptionBtnDlg::OnSize(nType, cx, cy);

	int y = cy;
	CRect rc;

	m_btnMain.GetWindowRect(rc);
	ScreenToClient(rc);
	y -= rc.Height();
	m_btnMain.MoveWindow(rc.left, y, rc.Width(), rc.Height(), FALSE);
	
	m_btnStatus.GetWindowRect(rc);
	ScreenToClient(rc);
	m_btnStatus.MoveWindow(rc.left, y, cx - rc.left, rc.Height(), FALSE);

	m_btnStat.GetWindowRect(rc);
	ScreenToClient(rc);
	y -= rc.Height() + 2;
	m_btnStat.MoveWindow(rc.left, y, rc.Width(), rc.Height(), FALSE);

	m_btnSysMsg.GetWindowRect(rc);
	ScreenToClient(rc);
	m_btnSysMsg.MoveWindow(rc.left, y, cx - rc.left, rc.Height(), FALSE);

	m_btnAbout.GetWindowRect(rc);
	ScreenToClient(rc);
	y -= rc.Height() + 2;
	m_btnAbout.MoveWindow(rc.left, y, rc.Width(), rc.Height(), FALSE);
	
	m_btnSearch.GetWindowRect(rc);
	ScreenToClient(rc);
	m_btnSearch.MoveWindow(rc.left, y, cx - rc.left, rc.Height(), FALSE);

	y -= 2;
	outbarCtrl.MoveWindow(0, 0, cx, y, FALSE);

	RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
}

void CIcqDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
{
	lpMMI->ptMinTrackSize.x = 95;
	lpMMI->ptMinTrackSize.y = 245;
	lpMMI->ptMaxTrackSize.x = 340;
	
	CCaptionBtnDlg::OnGetMinMaxInfo(lpMMI);
}

UINT CIcqDlg::OnNcHitTest(CPoint point) 
{
	UINT res = CCaptionBtnDlg::OnNcHitTest(point);
	if (res == HTCLIENT)
		return HTCAPTION;

	switch (alignType) {
	case ALIGN_TOP:
		if (res == HTLEFT || res == HTRIGHT || res == HTTOP ||
			res == HTTOPLEFT || res == HTTOPRIGHT)
			res = HTERROR;
		else if (res == HTBOTTOMLEFT || res == HTBOTTOMRIGHT)
			res = HTBOTTOM;
		if (isHide && res == HTBOTTOM)
			hideWindow(FALSE);
		break;
	case ALIGN_LEFT:
		if (res == HTTOP || res == HTBOTTOM || res == HTLEFT ||
			res == HTTOPLEFT || res == HTBOTTOMLEFT)
			res = HTERROR;
		else if (res == HTTOPRIGHT || res == HTBOTTOMRIGHT)
			res = HTRIGHT;
		if (isHide && res == HTRIGHT)
			hideWindow(FALSE);
		break;
	case ALIGN_RIGHT:
		if (res == HTTOP || res == HTBOTTOM || res == HTRIGHT ||
			res == HTTOPRIGHT || res == HTBOTTOMRIGHT)
			res = HTERROR;
		else if (res == HTTOPLEFT || res == HTBOTTOMLEFT)
			res = HTLEFT;
		if (isHide && res == HTLEFT)
			hideWindow(FALSE);
		break;
	}
	return res;
}

BOOL CIcqDlg::PreTranslateMessage(MSG* pMsg) 
{
	if ((myInfo.status != STATUS_OFFLINE) &&
		(pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST) ||
		(pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST) &&
		options.flags.test(UF_AUTO_SWITCH_STATUS)) {

		if (myInfo.status == STATUS_AWAY && options.flags.test(UF_AUTO_CANCEL_AWAY))
			OnStatusOnline();
		if (options.autoStatusTime > 0)
			SetTimer(IDT_AUTO_SWITCH_STATUS, options.autoStatusTime * 60000, NULL);
	}

	if (pMsg->hwnd == m_hWnd)
		toolTip.RelayEvent(pMsg);

	return CCaptionBtnDlg::PreTranslateMessage(pMsg);
}

void CIcqDlg::OnSendMessage() 
{
	IcqContact *c = curContact;
	IcqMsg *msg = fetchMsg(c->uin);

	IcqWindow *win;
	if (c->flags.test(CF_DIALOGMODE) || !msg) {
		outbarCtrl.blinkImage(c->uin, FALSE);

		CSendMsgDlg *pDlg;
		win = findWindow(WIN_SEND_MESSAGE, c->uin);
		if (!win) {
			pDlg = new CSendMsgDlg(c);
			pDlg->Create(IDD_SEND_MESSAGE);
		} else {
			pDlg = (CSendMsgDlg *) win;
			pDlg->ShowWindow(SW_NORMAL);
			pDlg->BringWindowToTop();
		}
		if (c->flags.test(CF_DIALOGMODE)) {
			while (msg) {
				pDlg->onRecvMessage(*msg);
				delete msg;
				msg = fetchMsg(c->uin);
			}
		}
	} else {
		// fake that we have not fetched it.
		msgList.push_front(msg);

		CViewMsgDlg *pDlg;
		win = findWindow(WIN_VIEW_MESSAGE, c->uin);
		if (!win) {
			pDlg = new CViewMsgDlg(c);
			pDlg->Create(IDD_VIEW_MESSAGE);
		} else {
			pDlg = (CViewMsgDlg *) win;
			pDlg->ShowWindow(SW_NORMAL);
			pDlg->BringWindowToTop();
		}
	}
}

void CIcqDlg::OnViewDetail() 
{
	CViewDetailDlg *win = new CViewDetailDlg(curContact->uin);
	win->Create();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -