Click here to Skip to main content
14,767,976 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 9:24
MemberVaclav_2-Apr-10 9: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 10:32
mveRichard MacCutchan2-Apr-10 10: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 16:41
MemberVaclav_2-Apr-10 16:41 
Questionlimited user in xp Pin
Boost20102-Apr-10 7:49
MemberBoost20102-Apr-10 7:49 
QuestionRe: limited user in xp Pin
David Crow2-Apr-10 9:01
MemberDavid Crow2-Apr-10 9:01 
AnswerRe: limited user in xp Pin
Boost20102-Apr-10 9:21
MemberBoost20102-Apr-10 9:21 
GeneralRe: limited user in xp Pin
David Crow2-Apr-10 9:24
MemberDavid Crow2-Apr-10 9:24 
GeneralRe: limited user in xp Pin
Boost20102-Apr-10 9:37
MemberBoost20102-Apr-10 9: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 9:40
MemberDavid Crow2-Apr-10 9:40 
GeneralRe: limited user in xp Pin
Boost20102-Apr-10 9:43
MemberBoost20102-Apr-10 9:43 
GeneralRe: limited user in xp Pin
David Crow2-Apr-10 9:46
MemberDavid Crow2-Apr-10 9:46 
GeneralRe: limited user in xp Pin
Boost20102-Apr-10 9:56
MemberBoost20102-Apr-10 9:56 
QuestionCannot access the ClassView information file, ClassView information will not be available. Pin
includeh102-Apr-10 7:23
Memberincludeh102-Apr-10 7:23 
AnswerRe: Cannot access the ClassView information file, ClassView information will not be available. Pin
Maximilien2-Apr-10 7:38
MemberMaximilien2-Apr-10 7:38 
GeneralRe: Cannot access the ClassView information file, ClassView information will not be available. Pin
includeh102-Apr-10 7:51
Memberincludeh102-Apr-10 7:51 
AnswerRe: Cannot access the ClassView information file, ClassView information will not be available. Pin
David Crow2-Apr-10 9:02
MemberDavid Crow2-Apr-10 9:02 
QuestionParallel Port write in VC++ Pin
Sameen12-Apr-10 7:16
MemberSameen12-Apr-10 7:16 
AnswerRe: Parallel Port write in VC++ Pin
jeron12-Apr-10 8:30
Memberjeron12-Apr-10 8:30 
GeneralRe: Parallel Port write in VC++ Pin
Sameen12-Apr-10 8:53
MemberSameen12-Apr-10 8:53 
AnswerRe: Parallel Port write in VC++ Pin
«_Superman_»2-Apr-10 16:38
professional«_Superman_»2-Apr-10 16:38 
GeneralRe: Parallel Port write in VC++ Pin
Sameen112-Apr-10 11:46
MemberSameen112-Apr-10 11:46 
Questionerror C2440 using adjacent_difference stl template function [modified] Pin
fda1002-Apr-10 2:35
Memberfda1002-Apr-10 2:35 
AnswerRe: error C2440 using adjacent_difference stl template function [modified] Pin
Eugen Podsypalnikov2-Apr-10 3:54
MemberEugen Podsypalnikov2-Apr-10 3:54 
GeneralRe: error C2440 using adjacent_difference stl template function Pin
fda1002-Apr-10 4:20
Memberfda1002-Apr-10 4:20 
QuestionFast 2D drawing Pin
Leif Simon Goodwin2-Apr-10 1:46
mvaLeif Simon Goodwin2-Apr-10 1: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.