コード例 #1
0
void PopupManager::Remove(int pos, bool	clicked /* = false*/) {
	bool rButton = (pos & 0x10000) > 0;
	pos = pos & 0xFFFF; // remove the right mouse button bit.
	
	if(popups.empty()) { //seems like we hit a bit of a race condition here
		return;			 //with the autoremove function, ohh well return and no harm done.
	}
	
	//find the correct window
	PopupIter i = popups.begin();

	for(; i != popups.end(); ++i) {
		if((*i)->id == pos)
			break;
	}

	dcassert(i != popups.end());

	//remove the window from the list
	PopupWnd *p = (*i);
	i = popups.erase(i);

	if(p == NULL){
		return;
	}

	//close the window and delete it
	HWND w = p->owner;
	p->SendMessage(WM_CLOSE, 0, 0);
	delete p;

	if( clicked && BOOLSETTING(POPUP_ACTIVATE_ON_CLICK) && !rButton ) {
		SetForegroundWindow(WinUtil::mainWnd);
		if( IsIconic(WinUtil::mainWnd) )
			ShowWindow(WinUtil::mainWnd, SW_RESTORE);
		
		::SendMessage(WinUtil::mdiClient, WM_MDIACTIVATE, (WPARAM)w, NULL);
	}

	//set offset one window position lower
	dcassert(offset > 0);
	offset = offset - height;

	//nothing to do
	if(popups.empty())
		return;

	CRect rc;

	//move down all windows
	for(; i != popups.end(); ++i) {
		(*i)->GetWindowRect(rc);
		rc.top += height;
		rc.bottom += height;
		(*i)->MoveWindow(rc);
	}
}
コード例 #2
0
void PopupManager::Remove(uint32_t pos)
{
	//find the correct window
	auto i = m_popups.cbegin();
	
	for (; i != m_popups.cend(); ++i)
	{
		if ((*i)->id == pos)
			break;
	}
	dcassert(i != m_popups.cend());
	if (i == m_popups.cend())
		return;
	//remove the window from the list
	PopupWnd *p = *i;
	i = m_popups.erase(i);
	
	dcassert(p);
	if (p == nullptr)
	{
		return;
	}
	
	//close the window and delete it, ensure that correct height is used from here
	height = p->height;
	p->SendMessage(WM_CLOSE, 0, 0);
	safe_delete(p);
	
	//set offset one window position lower
	dcassert(offset > 0);
	offset = offset - height;
	
	//nothing to do
	if (m_popups.empty())
		return;
	if (!ClientManager::isShutdown())
	{
		CRect rc;
		//move down all windows
		for (; i != m_popups.cend(); ++i)
		{
			(*i)->GetWindowRect(rc);
			rc.top += height;
			rc.bottom += height;
			(*i)->MoveWindow(rc);
		}
	}
}
コード例 #3
0
void PopupManager::Show(const tstring& aMsg, HWND owner) {
	if(!activated)
		return;

	if (!Util::getAway() && BOOLSETTING(POPUP_AWAY))
		return;

	if(!minimized && BOOLSETTING(POPUP_MINIMIZED)) 
		return;

	
	if( BOOLSETTING(POPUP_DONT_SHOW_ON_ACTIVE) && ( (HWND)::SendMessage(WinUtil::mdiClient, WM_MDIGETACTIVE, NULL, NULL) == owner ) )
		return;
	
	
	CRect rcDesktop;
	
	//get desktop rect so we know where to place the popup
	::SystemParametersInfo(SPI_GETWORKAREA,0,&rcDesktop,0);
	
	int screenHeight = rcDesktop.bottom;
	int screenWidth = rcDesktop.right;

	//if we have popups all the way up to the top of the screen do not create a new one
	if( (offset + height) > screenHeight)
		return;
	
	//compute the window position
	CRect rc(screenWidth - width , screenHeight - height - offset, screenWidth, screenHeight - offset);
	
	//Create a new popup
	PopupWnd *p = new PopupWnd(aMsg, rc, hBitmap, id++);
	p->owner = owner;
			
	//move the window to the top of the z-order and display it
	p->SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);

	//increase offset so we know where to place the next popup
	offset = offset + height;

	popups.push_back(p);
}
コード例 #4
0
void PopupManager::Show(const tstring &aMsg, const tstring &aTitle, int Icon, HICON /*hIcon*/, bool force) {
	if(!activated)
		return;


	if (!AirUtil::getAway() && SETTING(POPUP_AWAY) && !force)
		return;
	
	if(!MainFrame::getMainFrame()->getAppMinimized() && SETTING(POPUP_MINIMIZED) && !force) {
		return;
	}

	tstring msg = aMsg;
	if(int(aMsg.length()) > SETTING(MAX_MSG_LENGTH)) {
		msg = aMsg.substr(0, (SETTING(MAX_MSG_LENGTH) - 3));
		msg += _T("...");
	}

	if(SETTING(POPUP_TYPE) == BALLOON) {
		NOTIFYICONDATA m_nid;
		m_nid.cbSize = sizeof(NOTIFYICONDATA);
		m_nid.hWnd = MainFrame::getMainFrame()->m_hWnd;
		m_nid.uID = 0;
		m_nid.uFlags = NIF_INFO;
		m_nid.uTimeout = (SETTING(POPUP_TIME) * 1000);
		m_nid.dwInfoFlags = Icon;
		_tcscpy(m_nid.szInfo, msg.c_str());
		_tcscpy(m_nid.szInfoTitle, aTitle.c_str());
		Shell_NotifyIcon(NIM_MODIFY, &m_nid);
		return;
	}

	if(PopupImage != SETTING(POPUPFILE) || popuptype != SETTING(POPUP_TYPE)) {
		PopupImage = SETTING(POPUPFILE);
		popuptype = SETTING(POPUP_TYPE);
		hBitmap = (HBITMAP)::LoadImage(NULL, (Text::toT(PopupImage).c_str()), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
		if(hBitmap != NULL && SETTING(POPUP_TYPE) == CUSTOM) {
			BITMAP bm;
			GetObject(hBitmap,sizeof(bm),&bm);
			height = (uint16_t)bm.bmHeight;
			width = (uint16_t)bm.bmWidth;
		} else if(SETTING(POPUP_TYPE) != CUSTOM) {
			height = 90;
			width = 200;
		}
	}
	
	CRect rcDesktop;
	
	//get desktop rect so we know where to place the popup
	::SystemParametersInfo(SPI_GETWORKAREA,0,&rcDesktop,0);
	
	int screenHeight = rcDesktop.bottom;
	int screenWidth = rcDesktop.right;

	//if we have popups all the way up to the top of the screen do not create a new one
	if( (offset + height) > screenHeight)
		return;
	
	//get the handle of the window that has focus
	HWND gotFocus = ::SetFocus(WinUtil::mainWnd);
	
	//compute the window position
	CRect rc(screenWidth - width , screenHeight - height - offset, screenWidth, screenHeight - offset);
	
	//Create a new popup
	PopupWnd *p = new PopupWnd(msg, aTitle, rc, id++, hBitmap);
	p->height = height;	// save the height, for removal
	
	if(SETTING(POPUP_TYPE) != CUSTOM) {
		if(LOBYTE(LOWORD(GetVersion())) >= 5) {
			p->SetWindowLong(GWL_EXSTYLE, p->GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT);
			typedef bool (CALLBACK* LPFUNC)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
			LPFUNC _d_SetLayeredWindowAttributes = (LPFUNC)GetProcAddress(LoadLibrary(_T("user32")), "SetLayeredWindowAttributes");
			_d_SetLayeredWindowAttributes(p->m_hWnd, 0, 200, LWA_ALPHA);
		}
	}
コード例 #5
0
void PopupManager::Show(const tstring &aMsg, const tstring &aTitle, int Icon, bool preview /*= false*/)
{
	dcassert(ClientManager::isStartup() == false);
	dcassert(ClientManager::isShutdown() == false);
	if (ClientManager::isShutdown())
		return;
	if (ClientManager::isStartup())
		return;
		
	if (!m_is_activated)
		return;
		
		
	if (!Util::getAway() && BOOLSETTING(POPUP_AWAY) && !preview)
		return;
		
	if (!MainFrame::isAppMinimized() && BOOLSETTING(POPUP_MINIMIZED) && !preview)
		return;
		
	tstring msg = aMsg;
	if (int(aMsg.length()) > SETTING(MAX_MSG_LENGTH))
	{
		msg = aMsg.substr(0, (SETTING(MAX_MSG_LENGTH) - 3));
		msg += _T("...");
	}
#ifdef _DEBUG
	msg += Text::toT(" m_popups.size() = " + Util::toString(m_popups.size()));
#endif
	
	if (SETTING(POPUP_TYPE) == BALLOON && MainFrame::getMainFrame())
	{
		NOTIFYICONDATA m_nid = {0};
		m_nid.cbSize = sizeof(NOTIFYICONDATA);
		m_nid.hWnd = MainFrame::getMainFrame()->m_hWnd;
		m_nid.uID = 0;
		m_nid.uFlags = NIF_INFO;
		m_nid.uTimeout = (SETTING(POPUP_TIME) * 1000);
		m_nid.dwInfoFlags = Icon;
		_tcsncpy(m_nid.szInfo, msg.c_str(), 255);
		_tcsncpy(m_nid.szInfoTitle, aTitle.c_str(), 63);
		Shell_NotifyIcon(NIM_MODIFY, &m_nid);
		return;
	}
	
	if (m_popups.size() > 10)
	{
		//LogManager::message("PopupManager - m_popups.size() > 10! Ignore");
		return;
	}
	
	if (SETTING(POPUP_TYPE) == CUSTOM && PopupImage != SETTING(POPUPFILE))
	{
		PopupImage = SETTING(POPUPFILE);
		m_popuptype = SETTING(POPUP_TYPE);
		m_hBitmap = (HBITMAP)::LoadImage(NULL, Text::toT(PopupImage).c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	}
	
	height = SETTING(POPUP_H);
	width = SETTING(POPUP_W);
	
	CRect rcDesktop;
	
	//get desktop rect so we know where to place the popup
	::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0);
	
	int screenHeight = rcDesktop.bottom;
	int screenWidth = rcDesktop.right;
	
	//if we have popups all the way up to the top of the screen do not create a new one
	if ((offset + height) > screenHeight)
		return;
		
	//get the handle of the window that has focus
	dcassert(WinUtil::g_mainWnd);
	HWND gotFocus = ::SetFocus(WinUtil::g_mainWnd);
	
	//compute the window position
	CRect rc(screenWidth - width , screenHeight - height - offset, screenWidth, screenHeight - offset);
	
	//Create a new popup
	PopupWnd *p = new PopupWnd(msg, aTitle, rc, m_id++, m_hBitmap);
	p->height = height; // save the height, for removal
	
	if (SETTING(POPUP_TYPE) != /*CUSTOM*/ BALLOON)
	{
		typedef bool (CALLBACK * LPFUNC)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
		LPFUNC _d_SetLayeredWindowAttributes = (LPFUNC)GetProcAddress(LoadLibrary(_T("user32")), "SetLayeredWindowAttributes");
		if (_d_SetLayeredWindowAttributes)
		{
			p->SetWindowLongPtr(GWL_EXSTYLE, p->GetWindowLongPtr(GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT);
			_d_SetLayeredWindowAttributes(p->m_hWnd, 0, SETTING(POPUP_TRANSP), LWA_ALPHA);
		}
	}
	
	//move the window to the top of the z-order and display it
	p->SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
	p->ShowWindow(SW_SHOWNA);
	
	//restore focus to window
	::SetFocus(gotFocus);
	
	//increase offset so we know where to place the next popup
	offset = offset + height;
	
	m_popups.push_back(p);
}