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

📄 swlist.cpp

📁 <VC++网络游戏建摸与实现>源代码
💻 CPP
字号:
/*///////////////////////////////////////////////////////////////////

Copyright(c) 2000, Masoud Samimi - All Rights Reserved.

File:		FavorList.cpp - implementation file of favorite list box

History:	Created 14/12/2000 (dd/mm/yyyy)

Used for:	Loads all your favorites URLs from the 
			windows favorites directory "C:\windows\favorites"
			and adds/displays them inside the list box

Deriving:	This class can be used as a base class to your own 
			derived class inorder to have your own specialized
			AddString(you rown stuff) by just overriding one 
			virtual function the PreSubclassWindow() funtion.

Notes:		This class and the code is freely destributed, you
			cannot sell it. You can modify to fit your own
			style, but you will have to mention your changes and
			your name here in the changes log below!

			Whatever you do, please do not remove this info header
			from the files.
			

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Changes:	---->
By:			---->

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
	List of further enhancements:
	
	1. To add all the subdiretctory URLs as well.
	  
	2. To add a tree control! if possible, to have
	     the top level directories as expandable parents 
		 and the URLs files as children.
		 ( Something like the Windows Explorer! )
	3. Add your wishes! :)

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


//////////////////////////////////////////////////////////////////*/

#include "stdafx.h"
//#include "MyFavourites.h"
#include "swList.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFavorList

CFavorList::CFavorList()
{

	backBrush.CreateSolidBrush(RGB(0,0,0));
	hCursor = AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(32649));//IDC_HAND);
	
	hFind = NULL;

}

CFavorList::~CFavorList()
{
}


BEGIN_MESSAGE_MAP(CFavorList, CListBox)
	//{{AFX_MSG_MAP(CFavorList)
	ON_WM_CTLCOLOR_REFLECT()
	ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange)
	ON_WM_DESTROY()
	ON_WM_MOUSEMOVE()
	ON_CONTROL_REFLECT(LBN_DBLCLK, OnDblclk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFavorList message handlers

HBRUSH CFavorList::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	
	pDC->SetTextColor(RGB(205,205,0));
	pDC->SetBkMode(TRANSPARENT);

	return (HBRUSH) backBrush;

}


void CFavorList::OnSelchange() 
{

	return;
	SetCursor(hCursor);

	CString url = _T("");	
	int index = GetCurSel();
	GetText(index, url);
	//
	// Create and initialize a tooltip control.
	//
    m_ctlTT.Create (this);

	CRect rect;
	GetWindowRect(&rect);
	int url_length = url.GetLength(); 
	int width = rect.Width()/7+50;

	if(url_length > width){
		m_ctlTT.AddWindowTool(this,
				url.GetBuffer(1024));	
		}

	url.ReleaseBuffer();
	

}

void CFavorList::OnDestroy() 
{
	CListBox::OnDestroy();
	
	backBrush.DeleteObject();	// delete background brush
		
}

void CFavorList::OnMouseMove(UINT nFlags, CPoint point) 
{
	

	SetCursor(hCursor);
		
	CListBox::OnMouseMove(nFlags, point);

}

void CFavorList::OnDblclk() 
{
	return;

	CString url = _T("");	
	int index = GetCurSel();
	GetText(index, url);

	iReturn = (int) ShellExecute(NULL, "open", url, NULL, NULL, 0);

          // If ShellExecute returns an error code, let the user know.

     if (iReturn <= 32)
     {
          wsprintf (szBuffer, 
                    "Cannot launch browser and cannot continue! "
                    "(ShellExecute error code is %i)", iReturn) ;
          MessageBox (szBuffer, "Error!", MB_OK | MB_ICONEXCLAMATION) ;
     }

	 if(url.GetLength()==0){
		  wsprintf (szBuffer, 
                    "This is an empty entry! Try clicking a filled link! "
					"(ShellExecute error code is %i)", iReturn) ;

          MessageBox (szBuffer, "Error!", MB_OK | MB_ICONEXCLAMATION) ;
	}

 
	

	 url.ReleaseBuffer();
	 
}

void CFavorList::PreSubclassWindow() 
{

	GetFavoritesDirectory();
	LoadFiles();
	
	SetCurSel(0);


	CListBox::PreSubclassWindow();
}


int CFavorList::GetFavoritesDirectory()
{
return 0;
	lReturn = RegOpenKeyEx(HKEY_CURRENT_USER,
		"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
		0, KEY_QUERY_VALUE, &hKey);

	if(lReturn != ERROR_SUCCESS)
		{
			MessageBox("Cannot obtain Favourites directory and cannot continue!",
				"Error!", MB_OK|MB_ICONEXCLAMATION);

			return 0;

		}


	dwLength = sizeof(szFavoritesDir);

	 lReturn = RegQueryValueEx (hKey, "Favorites", NULL,
                                &dwType, szFavoritesDir, &dwLength) ;


	if(lReturn != ERROR_SUCCESS)
		{
			MessageBox("Cannot obtain Favourites directory and cannot continue!",
				"Error!", MB_OK|MB_ICONEXCLAMATION);

			return 0;

		}

	return 0;

}


void CFavorList::LoadFiles()
{

	::SetCurrentDirectory((const char*) szFavoritesDir);
	
	hFind = ::FindFirstFile (_T ("*.url"), &fd);

	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			AddString(fd.cFileName);
			} while (::FindNextFile (hFind, &fd));
			::FindClose (hFind);

	}

}

void CFavorList::EnumerateFolders ()
{
    
	hFind = ::FindFirstFile (_T ("*.*"), &fd);

    if (hFind != INVALID_HANDLE_VALUE) {
        do {
            if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                CString name = fd.cFileName;
                if (name != _T (".") && name != _T ("..")) {
                    TRACE (_T ("%s\n"), fd.cFileName);
                    ::SetCurrentDirectory (fd.cFileName);
				    EnumerateFolders ();
                    ::SetCurrentDirectory (_T (".."));
					
                }
            }
        } while (::FindNextFile (hFind, &fd));
        ::FindClose (hFind);
    }

}


/////////////////////////////////////////////////////////////////////////////
// CMyToolTipCtrl

CMyToolTipCtrl::CMyToolTipCtrl()
{
}

CMyToolTipCtrl::~CMyToolTipCtrl()
{
}


BEGIN_MESSAGE_MAP(CMyToolTipCtrl, CToolTipCtrl)
	//{{AFX_MSG_MAP(CMyToolTipCtrl)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyToolTipCtrl message handlers

BOOL CMyToolTipCtrl::AddWindowTool(CWnd *pWnd, LPCTSTR pszText)
{
    TOOLINFO ti;
    ti.cbSize = sizeof (TOOLINFO);
    ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
    ti.hwnd = pWnd->GetParent ()->GetSafeHwnd ();
    ti.uId = (UINT) pWnd->GetSafeHwnd ();
    ti.hinst = AfxGetInstanceHandle ();
    ti.lpszText = (LPTSTR) pszText;

    return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti);
}

⌨️ 快捷键说明

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