passendes Dateisymbol vor jeder Datei anzeigen?

Diese Zeile dürfte problematisch sein:
Code:
HDC hDC = ::GetDC(HWND(this->GetActiveWindow()));
Teste mal den Rückgabewert von GetActiveWindow() ab.

Da du ja schon ein CDC-Objekt zu haben scheinst, warum schreibst du dann nicht:
Code:
DrawIconEx( pDC->GetSafeHdc(), // handle to dc
            rect.left, // xLeft
            rect.top, // yTop
            fileicon, // HICON
            5, // cxWidth
            5, // cyWidth
            NULL,
            NULL,
            DI_NORMAL
          );
 
An einer anderen Codestelle klappt es leider nicht. Die Variable des Dateipfades enthält kein "\" am Ende und das scheint der "DrawIconEx" Ärger zu machen.
So tut das Ganze nicht, da zeigt er mir dann ein falsches oder gar kein Symbol an:

Code:
// get the devicename
CString devicename = m_deviceArray.GetAt(i);
devicename.Insert(2,"\\");

// draw the file symbol
SHFILEINFO sfi;             

SHGetFileInfo(devicename, // path of the file of which the symbol should be found
		     NULL, // file attribute flags
		     &sfi, // address of a SHFILEINFO structure to receive the file information
                     sizeof(SHFILEINFO), // size, in bytes
		     SHGFI_ICON | SHGFI_USEFILEATTRIBUTES); // flags

HICON fileicon = sfi.hIcon;

int proof = DrawIconEx (pDC->GetSafeHdc(), // handle to dc
				   rect.left - 18, // xLeft
			           rect.top, // yTop
				   fileicon, // HICON
				   14, // cxWidth
			           14, // cyWidth
				   NULL, // specifies the index of the frame to draw
				   NULL, // handle to a brush
				   DI_NORMAL // specifies the drawing flags
				   );


wohl aber so:


Code:
// get the devicename
CString devicename = m_deviceArray.GetAt(i);

// draw the file symbol
SHFILEINFO sfi;             

SHGetFileInfo("a:\\", // path of the file of which the symbol should be found
		     NULL, // file attribute flags
		     &sfi, // address of a SHFILEINFO structure to receive the file information
                     sizeof(SHFILEINFO), // size, in bytes
		     SHGFI_ICON | SHGFI_USEFILEATTRIBUTES); // flags

HICON fileicon = sfi.hIcon;

int proof = DrawIconEx (pDC->GetSafeHdc(), // handle to dc
				   rect.left - 18, // xLeft
			           rect.top, // yTop
				   fileicon, // HICON
				   14, // cxWidth
			           14, // cyWidth
				   NULL, // specifies the index of the frame to draw
				   NULL, // handle to a brush
				   DI_NORMAL // specifies the drawing flags
				   );

Versteh ich nicht, ist das was anderes?!
 
Hi.

Ich denke du solltest (wenn du SHGFI_USEFILEATTRIBUTES benutzt) auch das FILE_ATTRIBUTE_NORMAL bzw. FILE_ATTRIBUTE_DIRECTORY als dwFileAttributes Parameter übergeben, sonst ist nicht klar ob ein Verzeichnis oder eine Datei gemeint ist, wenn kein Schrägstrich am Ende ist.

Außerdem solltest du generell lieber normale Schrägstriche statt umgekehrte Schrägstriche verwenden. (siehe C++ FAQ 15.14)
 
Hallo,
vielleicht liegt es auch nur daran, daß du am Ende eines Strings etwas einfügen willst. Vielleicht reicht ja
Code:
devicename+="\\";
Ich habs aber nicht ausprobiert.

Mfg

langer
 
Beide Tipps haben leider nichts gebracht. Es funktioniert zwar, weil es in dem Fall immer um Laufwerke geht, ich also ein Laufwerk statisch angeben kann um das richtige Symbol angezeigt zu bekommen. Allerdings wollt ich halt für die Zukunft gern wissen, was ich falsch gemacht habe. Wenn jemand ne Idee hat...
Sonst lass ichs einfach mal so.

Grüße Rave
 
Ob du die Pfad- oder Laufwerksbezeichnung direkt in SHGetFileInfo() einträgst oder vorher einer CString-Variablen zuweist macht eigentlich keinen Unterschied.
Hast du mal debuggt, ob in "devicename" überhaupt das Richtige drinsteht?
 
Also wenn ich nichts an dem String "devicename" manipuliere steht "A:" und C:" drin
Wenn ich aber devicename+="\\"; anhänge, dann steht ein "A:
\"
drin. Mit diesem Zeilenumbruch!!
 
Hmm, also durch das Anhängen sollte kein Zeilenumbruch entstehen. Wie erzeugst du denn die Einträge in deinem Array?

Funktioniert sowas?
Code:
CString devicename = "A:";
devicename += "\\";
 
Ja das funktioniert.
So erzeuge ich meine Einträge:
Code:
void CFileExplorerSideView::GetAllDevices()
{
	TCHAR g_szDrvMsg[] = _T("A:\n");
	ULONG uDriveMask = _getdrives();

	if (uDriveMask == 0){
		printf("_getdrives() failed with failure code: %d\n", GetLastError());
	}
	else 
	{
		while (uDriveMask) 
		{
			if (uDriveMask & 1)
			{
				// convert TCHAR to CString
				CString devicename = CString(g_szDrvMsg);
				// fill an array with all devices
				m_deviceArray.Add(devicename);
			}
			++g_szDrvMsg[0];
			uDriveMask >>= 1;			
		}
	}
}
 

Neue Beiträge

Zurück