SwList.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:7k
源码类别:
游戏
开发平台:
Visual C++
- /*///////////////////////////////////////////////////////////////////
- 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:windowsfavorites"
- 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 ("%sn"), 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);
- }