Click here to Skip to main content
15,888,020 members
Articles / Programming Languages / C++

Windows Switcher Add-In

Rate me:
Please Sign up or sign in to vote.
3.50/5 (2 votes)
4 Jan 20042 min read 45.3K   388   11  
How to speed-up navigating in big workspace using keyboard
// WWWString.cpp : implementation file
//

#include "stdafx.h"
#include "WWWString.h"
#include <process.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWWWString

CWWWString::CWWWString()
{
	font.CreateFont(12, 0, 0, 0, 0, 0, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 0, DEFAULT_QUALITY, 0, "MS Sans Serif");
}

CWWWString::~CWWWString()
{
}


BEGIN_MESSAGE_MAP(CWWWString, CStatic)
	//{{AFX_MSG_MAP(CWWWString)
	ON_WM_MOUSEMOVE()
	ON_WM_SETCURSOR()
	ON_WM_LBUTTONUP()
	ON_WM_CAPTURECHANGED()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWWWString message handlers

void CWWWString::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CWnd* pWnd;  // Finestra attiva
	CWnd* pParent; // Finestra che contiene il bottone
	
	CStatic::OnMouseMove(nFlags, point);

	BOOL m_MouseOnButton=false;
	// If the mouse enter the button with the left button pressed
	// then do nothing
	
	if (nFlags & MK_LBUTTON) return;
	
	pWnd = GetActiveWindow();
	pParent = GetOwner();
	
	if (GetCapture() != this)
	{
		m_MouseOnButton = TRUE;
		//SetFocus();	// Thanks Ralph!
		SetCapture();		
		Invalidate();
	}
	else
	{
	/*
	CRect rc;
	GetClientRect(&rc);
	if (!rc.PtInRect(point))
	{
		*/
		
		POINT p2 = point;
		ClientToScreen(&p2);
		CWnd* wndUnderMouse = WindowFromPoint(p2);
		//		if (wndUnderMouse != this)
		if (wndUnderMouse && wndUnderMouse->m_hWnd != this->m_hWnd)
		{
			// Redraw only if mouse goes out
			if (m_MouseOnButton == TRUE)
			{
				m_MouseOnButton = FALSE;

			}
			// If user is NOT pressing left button then release capture!
			if (!(nFlags & MK_LBUTTON)) 
			{
				ReleaseCapture();
			}
		}
	}

}

BOOL CWWWString::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	CFont *tempFont=GetFont();
	if(tempFont!=staryFont)
	{
		this->SetFont(&font, true);
		staryFont=tempFont;	
		SetCapture();
	}
	
	return CStatic::OnSetCursor(pWnd, nHitTest, message);
}


void CWWWString::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CString oOperationString;
	this->GetWindowText( oOperationString );

	if( oOperationString.Find('@') < 0 )
	{
		oOperationString="start "+oOperationString;
		WinExec(oOperationString, SW_HIDE);
	}
	else
	{
		oOperationString.Insert( 0, "mailto:" );
		ShellExecute( NULL,  "open", oOperationString, "", ".", SW_SHOW );
	}	


	if( GetCapture() == this )
	{
		ReleaseCapture();
	}
	
	CStatic::OnLButtonUp(nFlags, point);
}

void CWWWString::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	if(staryFont!=NULL)
	{
		SetFont(staryFont);
		staryFont=NULL;
	}
	
	CStatic::OnCaptureChanged(pWnd);
}

void CWWWString::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	dc.SelectObject(this->GetFont());
	dc.SetBkColor(GetSysColor(COLOR_3DFACE));

	dc.SetTextColor(RGB(0, 0, 255));
	
	// TODO: Add your message handler code here
	static CString s;
	GetWindowText(s);
	dc.TextOut(0, 0, s);

	// Do not call CStatic::OnPaint() for painting messages
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Poland Poland
Mariusz Wojtysiak started his career as coder on ZX-Spectrum demo-scene under nickname Maniu. He graduated Poznan University of Technology. His skills are: project/develop/maintenance of Oracle and MS SQL databases, programming in C++ (including MFC, ATL, Soap), Oracle Forms, and Assembler.
Currently works in IN-Software as developer. Live in Poznan/Poland.

Comments and Discussions