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

📄 urlftree.cpp

📁 大量windows shell编程例子
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*-------------------------------------------------------------------*/
// Procedure....: AddTreeItem()
// Description..: Add an item to the treeview
/*-------------------------------------------------------------------*/
HTREEITEM CHtmlTree::AddTreeItem( INT iNodeType, LPTSTR szText, 
	INT iImageId ) 
{
	HTREEITEM hItem, hNode;
	TV_ITEM tvI;
	TV_INSERTSTRUCT tvIns;


	// determine the node to add to
	switch( iNodeType )
	{
		case NODE_LINKS:
			hNode = m_nodeLinks;
			break;
		case NODE_APPLETS:
			hNode = m_nodeApplets;
			break;
		case NODE_SCRIPTS:
			hNode = m_nodeScripts;
			break;
		case NODE_OBJECTS:
			hNode = m_nodeObjects;
			break;
		case NODE_IMAGES:
			hNode = m_nodeImages;
			break;
		case NODE_CONTENTS:
			hNode = m_nodeContents;
			break;
		case NODE_FILE:
			hNode = m_nodeFile;
			break;

		default:
			hNode = NULL;
			break;
	}


	// fills out only text, image and selected image
	tvI.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
	tvI.pszText = szText;
	tvI.cchTextMax = lstrlen(szText);
	tvI.iImage = iImageId;
	tvI.iSelectedImage = iImageId;

	ZeroMemory( &tvIns, sizeof(TV_INSERTSTRUCT) );
	tvIns.item = tvI;
	tvIns.hParent = hNode;
	
	// insert the item into the tree
	hItem = TreeView_InsertItem( m_hwndTree, &tvIns );
	return hItem;
}





///////////////////////////////
//
//   CALLBACKS
//   functions
//
///////////////


/*-------------------------------------------------------------------*/
// Procedure....: MyLinkProc()
// Description..: Callback to handle links information
/*-------------------------------------------------------------------*/
BOOL CALLBACK MyLinkProc( IHTMLAnchorElement *pLink, DWORD dwData )
{
	BSTR bstr;
	TCHAR szBuf[MAX_PATH];
				
	// get HREF and translate to ANSI
	pLink->get_href( &bstr );
	BSTR_TO_STRING( bstr, szBuf, MAX_PATH );

	SysFreeString( bstr );
	
	// add to the treeview
	CHtmlTree *pHtmlTree = (CHtmlTree *) dwData;
	pHtmlTree->AddTreeItem( NODE_LINKS, szBuf, ID_ITEM_ELEMENT );
	
	return TRUE;
}




/*-------------------------------------------------------------------*/
// Procedure....: MyImageProc()
// Description..: Callback to handle images information
/*-------------------------------------------------------------------*/
BOOL CALLBACK MyImageProc( IHTMLImgElement *pImage, DWORD dwData )
{
	BSTR bstr;
	TCHAR szBuf[MAX_PATH];
				
	// get HREF and translate to ANSI
	pImage->get_href( &bstr );
	BSTR_TO_STRING( bstr, szBuf, MAX_PATH );

	SysFreeString( bstr );
	
	// add to the treeview
	CHtmlTree *pHtmlTree = (CHtmlTree *) dwData;
	pHtmlTree->AddTreeItem( NODE_IMAGES, szBuf, ID_ITEM_ELEMENT );
	
	return TRUE;
}




/*-------------------------------------------------------------------*/
// Procedure....: MyObjectProc()
// Description..: Callback to handle object information
/*-------------------------------------------------------------------*/
BOOL CALLBACK MyObjectProc( IHTMLElement *pObject, DWORD dwData )
{
	OLECHAR wszAttrib[40];
	HRESULT hr;
	TCHAR szBuf[MAX_PATH], szClsId[30], szDesc[100];

	// the CLASSID attribute is returned via a VARIANT type
	VARIANT varValue;
	VariantInit( &varValue );
				
	// get CLASSID attribute and convert it to ANSI
	STRING_TO_BSTR( "ClassId", wszAttrib, 40 ); 
	hr = pObject->getAttribute( wszAttrib, 0, &varValue );
	BSTR_TO_STRING( varValue.bstrVal, szBuf, MAX_PATH );

	// remove the leading "CLSID:" substring (6 bytes)
	// and brackets between {...}
	SHIFT_STRING( szBuf, 6 );
	wsprintf( szClsId, "{%s}", szBuf );
	
	// retrieve the descriptive name of the object
	if( GetObjectDescription( szClsId, szDesc, 100 ) )
	{
		lstrcat( szClsId, ",  " );
		lstrcat( szClsId, szDesc );
	}

	// add to the treeview: CLSID + description (if any)
	CHtmlTree *pHtmlTree = (CHtmlTree *) dwData;
	pHtmlTree->AddTreeItem( NODE_OBJECTS, szClsId, ID_ITEM_ELEMENT );
	
	return TRUE;
}




/*-------------------------------------------------------------------*/
// Procedure....: MyScriptProc()
// Description..: Callback to handle script information
/*-------------------------------------------------------------------*/
BOOL CALLBACK MyScriptProc( IHTMLElement *pScript, DWORD dwData )
{
	OLECHAR wszAttrib[40];
	BSTR bstr;
	TCHAR szBuf[MAX_PATH], szLang[40], szCode[2048];

	// the LANGUAGE attribute is returned via a VARIANT type
	VARIANT varValue;
	VariantInit( &varValue );
				
	// get LANGUAGE attribute and convert to ANSI
	STRING_TO_BSTR( "Language", wszAttrib, 40 ); 
	pScript->getAttribute( wszAttrib, 0, &varValue );
	BSTR_TO_STRING( varValue.bstrVal, szLang, 40 );

	// get the entire script code and extract the proc name
	pScript->get_innerHTML( &bstr );
	BSTR_TO_STRING( bstr, szCode, 2048 );


	// Assume the proc name is between the first two CRLF
	// and the script code begins with <!--
	

	// first, remove all the leading chars
	LPTSTR psz = strchr( szCode, '<' );
	lstrcpy( szCode, psz );

	// get the first CR
	psz = strchr( szCode, 13 )+2;
	lstrcpy( szCode, psz );
	psz = strchr( szCode, 13 );
	szCode[psz-szCode] = 0;
	lstrcpy( szBuf, szCode );

	// add to the treeview: Proc name and language
	lstrcat( szBuf, " :   " );
	lstrcat( szBuf, szLang );
	CHtmlTree *pHtmlTree = (CHtmlTree *) dwData;
	pHtmlTree->AddTreeItem( NODE_SCRIPTS, szBuf, ID_ITEM_ELEMENT );
	
	return TRUE;
}




/*-------------------------------------------------------------------*/
// Procedure....: MyAppletProc()
// Description..: Callback to handle applet information
/*-------------------------------------------------------------------*/
BOOL CALLBACK MyAppletProc( IHTMLElement *pApplet, DWORD dwData )
{
	OLECHAR wszAttrib[40];
	TCHAR szBuf[MAX_PATH];

	// the NAME attribute is returned via a VARIANT type
	VARIANT varValue;
	VariantInit( &varValue );
				
	// get NAME attribute and convert to ANSI
	STRING_TO_BSTR( "Name", wszAttrib, MAX_PATH ); 
	pApplet->getAttribute( wszAttrib, 0, &varValue );
	BSTR_TO_STRING( varValue.bstrVal, szBuf, MAX_PATH );

	// add to the treeview: Proc name and language
	CHtmlTree *pHtmlTree = (CHtmlTree *) dwData;
	pHtmlTree->AddTreeItem( NODE_APPLETS, szBuf, ID_ITEM_ELEMENT );
	
	return TRUE;
}
 


/*-------------------------------------------------------------------*/
// Procedure....: GetObjectDescription()
// Description..: Helper function to get a CLSID description
/*-------------------------------------------------------------------*/
BOOL GetObjectDescription( LPCTSTR szCLSID, LPTSTR szDesc, DWORD dwBufSize )
{
	// local data
	DWORD dwResult, dwType;
	CHAR szSubKey[MAX_PATH];
	HKEY hkeySub;

	// build up the path for accessing the registry
	lstrcpy( szSubKey, "CLSID\\" );
	lstrcat( szSubKey, szCLSID );

	// try to read from the registry (NAME)
	dwResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, szSubKey, 0, 
		KEY_READ, &hkeySub );
	if( dwResult != ERROR_SUCCESS )
	{
		szDesc[0] = 0;
		return FALSE;
	}

	// It's fundamental that you set the last RegQueryValueEx's
	// argument to the max size of the buffer.

	// read description from the registry
	dwResult = RegQueryValueEx( hkeySub, "", 0, &dwType, 
		(LPBYTE) szDesc, &dwBufSize );
	
	// close
	RegCloseKey( hkeySub );
	return (dwResult==ERROR_SUCCESS);
}




/*-------------------------------------------------------------------*/
// Procedure....: Source_DlgProc()
// Description..: Initialize the source dialog box
/*-------------------------------------------------------------------*/
LRESULT CALLBACK Source_DlgProc( HWND hwnd, UINT uiMsg, WPARAM wParam,
	LPARAM lParam )
{
	switch( uiMsg )
	{
		case WM_INITDIALOG:	
			SetDlgItemText( hwnd, IDC_TEXT, (LPTSTR) lParam );
			break;
		case WM_COMMAND:
			if( wParam==IDCANCEL || wParam==IDOK )
				EndDialog( hwnd, FALSE );
			break;
	}
	
	return 0;
}



⌨️ 快捷键说明

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