Click here to Skip to main content
15,886,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCComboBox "right allign text" option moves the list box selection arrow to the left (VC 6.0 MFC) Pin
Vaclav_2-Apr-10 8:24
Vaclav_2-Apr-10 8:24 
AnswerRe: CComboBox "right allign text" option moves the list box selection arrow to the left (VC 6.0 MFC) Pin
Richard MacCutchan2-Apr-10 9:32
mveRichard MacCutchan2-Apr-10 9:32 
GeneralRe: CComboBox "right allign text" option moves the list box selection arrow to the left (VC 6.0 MFC) Pin
Vaclav_2-Apr-10 15:41
Vaclav_2-Apr-10 15:41 
Questionlimited user in xp Pin
Boost20102-Apr-10 6:49
Boost20102-Apr-10 6:49 
QuestionRe: limited user in xp Pin
David Crow2-Apr-10 8:01
David Crow2-Apr-10 8:01 
AnswerRe: limited user in xp Pin
Boost20102-Apr-10 8:21
Boost20102-Apr-10 8:21 
GeneralRe: limited user in xp Pin
David Crow2-Apr-10 8:24
David Crow2-Apr-10 8:24 
GeneralRe: limited user in xp Pin
Boost20102-Apr-10 8:37
Boost20102-Apr-10 8:37 
Here is code
void CTestDlg::UpdateDevice(PDEV_BROADCAST_DEVICEINTERFACE pDevInf, WPARAM wParam)
{
// pDevInf->dbcc_name: 
// \\?\USB#Vid_04e8&Pid_503b#0002F9A9828E0F06#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// szDevId: USB\Vid_04e8&Pid_503b\0002F9A9828E0F06
// szClass: USB
ASSERT(lstrlen(pDevInf->dbcc_name) > 4);
CString szDevId = pDevInf->dbcc_name+4;
int idx = szDevId.ReverseFind(_T('#'));
ASSERT( -1 != idx );
szDevId.Truncate(idx);
szDevId.Replace(_T('#'), _T('\\'));
szDevId.MakeUpper();

CString szClass;
idx = szDevId.Find(_T('\\'));
ASSERT(-1 != idx );
szClass = szDevId.Left(idx);
CString szLog;
//m_ctrlEdit.GetWindowText(szLog);
CString szTmp;
if ( DBT_DEVICEARRIVAL == wParam )
{
	
	pendrive++;
	if(pendrive==1)
	{

	}
	else
	{
		szTmp.Format(_T("Adding %s\r\n"), szDevId.GetBuffer());
		pendrive=0;
		
szTmp.Trim();
int nPos=szTmp.Find("_");
CString cyt1=szTmp.Left(szTmp.GetLength()-nPos);
CString cyt2=cyt1.Right(cyt1.GetLength()-nPos-1);
CString fi=cyt2;
int rep=fi.Replace("&PROD_"," ");
int nPon1=fi.Find("&");
final=fi.Left(nPon1);

	}
	
	
	
	
	// TRACE("Adding %s\n", szDevId.GetBuffer());
} else
{
	pendrive++;
	if(pendrive==1)
	{

	}
	else
	{
	szTmp.Format(_T("Removing %s\r\n"), szDevId.GetBuffer());
	szDevId.ReleaseBuffer();
	szTmp.Trim();
int nPos=szTmp.Find("_");
CString cyt1=szTmp.Left(szTmp.GetLength()-nPos);
CString cyt2=cyt1.Right(cyt1.GetLength()-nPos-1);
CString fi=cyt2;
int rep=fi.Replace("&PROD_"," ");
int nPon1=fi.Find("&");
CString finalep=fi.Left(nPon1);
 char dateStr [9];
char timeStr [9];
_strdate( dateStr);
_strtime( timeStr );
CString date=dateStr;
CString time=timeStr;
CString datatime=date;
datatime+=" ";
datatime+=time;
	
	
									CStdioFile myFile,myFilereport; 
								CFileException e; 
								if( myFile.Open( ""C:\\Documents and Settings\\All Users\\Documents\\Adminfile.txt"", CStdioFile::modeCreate | CStdioFile::modeWrite | CStdioFile::modeNoTruncate, &e ) )
								{
										myFile.SeekToEnd();
										myFile.WriteString("======================================================================================================\n");
										myFile.WriteString("                                        Disconnect infmation");
										myFile.WriteString("\n");
										myFile.WriteString("======================================================================================================\n");
										myFile.WriteString("USB Devidce ID:");
										myFile.WriteString(finalep);
										myFile.WriteString("\n");
										myFile.WriteString("USB Devidce Connection Time:");
										myFile.WriteString(datatime);
										myFile.WriteString("\n");
										myFile.WriteString("======================================================================================================\n");
										myFile.WriteString("\n");
								}
	}
}
szLog.Append(szTmp);
szLog.Trim();
//m_ctrlEdit.SetWindowText(szLog);

// seems we should ignore "ROOT" type....
if ( _T("ROOT") == szClass ) {
	return;
}

DWORD dwFlag = DBT_DEVICEARRIVAL != wParam ? 
	DIGCF_ALLCLASSES : (DIGCF_ALLCLASSES | DIGCF_PRESENT);
HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL,szClass,NULL,dwFlag);
if( INVALID_HANDLE_VALUE == hDevInfo ) {
	
	return;
}

SP_DEVINFO_DATA spDevInfoData;
if ( FindDevice(hDevInfo, szDevId, spDevInfoData) ) {
	// OK, device found
	DWORD DataT ;
	TCHAR buf[MAX_PATH];
	DWORD nSize = 0;

	// get Friendly Name or Device Description
	if ( SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData, 
		SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize) ) {
	} else if ( SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData, 
		SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize) ) {
	} else {
		lstrcpy(buf, _T("Unknown"));
	}

	HTREEITEM hClass = GetClassItem(&(spDevInfoData.ClassGuid), wParam);
	// hClass can only be NULL for remove device and class node is not found
	if ( NULL == hClass ) return;
	// remove device
	HTREEITEM hChildItem = m_ctrlTree.GetChildItem(hClass);
	BOOL bFound = FALSE;
	while (hChildItem != NULL) {
		CString* pszData = (CString*)m_ctrlTree.GetItemData(hChildItem);
		if ( szDevId == *pszData  ) {
			bFound = TRUE;
			if ( DBT_DEVICEARRIVAL == wParam ) {
				// add device, but seems the device already exists
				break;
			} else {
				// remove device
				delete pszData;
				m_ctrlTree.DeleteItem(hChildItem);
				if ( !m_ctrlTree.ItemHasChildren(hClass) ) {
					HeapFree(GetProcessHeap(), 0, (LPVOID)m_ctrlTree.GetItemData(hClass));
					m_ctrlTree.DeleteItem(hClass);
				}
				break;
			}
		} else {
			hChildItem = m_ctrlTree.GetNextItem(hChildItem, TVGN_NEXT);
		}
	}
	if ( DBT_DEVICEARRIVAL == wParam && !bFound ) {
		// Add device
		int n = GetClassImgIndex(&(spDevInfoData.ClassGuid));
		HTREEITEM hItem = m_ctrlTree.InsertItem(buf, n, n, hClass);
		m_ctrlTree.SetItemData(hItem, (DWORD_PTR)(new CString(szDevId)));
		// set pspDevInfoData to NULL, otherwise it will be HeapFree
		m_ctrlTree.Expand(hClass, TVE_EXPAND);
	}
}

GeneralRe: limited user in xp Pin
David Crow2-Apr-10 8:40
David Crow2-Apr-10 8:40 
GeneralRe: limited user in xp Pin
Boost20102-Apr-10 8:43
Boost20102-Apr-10 8:43 
GeneralRe: limited user in xp Pin
David Crow2-Apr-10 8:46
David Crow2-Apr-10 8:46 
GeneralRe: limited user in xp Pin
Boost20102-Apr-10 8:56
Boost20102-Apr-10 8:56 
QuestionCannot access the ClassView information file, ClassView information will not be available. Pin
includeh102-Apr-10 6:23
includeh102-Apr-10 6:23 
AnswerRe: Cannot access the ClassView information file, ClassView information will not be available. Pin
Maximilien2-Apr-10 6:38
Maximilien2-Apr-10 6:38 
GeneralRe: Cannot access the ClassView information file, ClassView information will not be available. Pin
includeh102-Apr-10 6:51
includeh102-Apr-10 6:51 
AnswerRe: Cannot access the ClassView information file, ClassView information will not be available. Pin
David Crow2-Apr-10 8:02
David Crow2-Apr-10 8:02 
QuestionParallel Port write in VC++ Pin
Sameen12-Apr-10 6:16
Sameen12-Apr-10 6:16 
AnswerRe: Parallel Port write in VC++ Pin
jeron12-Apr-10 7:30
jeron12-Apr-10 7:30 
GeneralRe: Parallel Port write in VC++ Pin
Sameen12-Apr-10 7:53
Sameen12-Apr-10 7:53 
AnswerRe: Parallel Port write in VC++ Pin
«_Superman_»2-Apr-10 15:38
professional«_Superman_»2-Apr-10 15:38 
GeneralRe: Parallel Port write in VC++ Pin
Sameen112-Apr-10 10:46
Sameen112-Apr-10 10:46 
Questionerror C2440 using adjacent_difference stl template function [modified] Pin
fda1002-Apr-10 1:35
fda1002-Apr-10 1:35 
AnswerRe: error C2440 using adjacent_difference stl template function [modified] Pin
Eugen Podsypalnikov2-Apr-10 2:54
Eugen Podsypalnikov2-Apr-10 2:54 
GeneralRe: error C2440 using adjacent_difference stl template function Pin
fda1002-Apr-10 3:20
fda1002-Apr-10 3:20 
QuestionFast 2D drawing Pin
Leif Simon Goodwin2-Apr-10 0:46
Leif Simon Goodwin2-Apr-10 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.