473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Shell problem

Hello,

My problem concerns the shell. If there's a better forum for this post,
please let me know.

I'm trying to create a ListView control that displays the contents of a
folder with all the appropriate icons etc. I first tried this in c# with
reasonable success, but this is really a job for c++. However I've run into
a problem.

I have pretty much got the code down to do what I need it to do, but if I
access a folder with many items, problems begin. The controls within my
program and the entire windows environment start to not paint themselves
correctly. For example, icons show up in my ListView but no text...text
disappears from the column headers and from the menu, and if you keep going,
entire blocks of Window start paint themselves erraticly. I have a couple
of screen shots.
Here's the code that sets things up:

virtual void OnCreateControl()
{
__super::OnCreateControl();
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
UINT uFlags = SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
HIMAGELIST himl;
SHFILEINFO sfi;
HRESULT hr;
LPMALLOC pMalloc;
LPSHELLFOLDER pDesktopFolder = NULL;
LPSHELLFOLDER pParentFolder = NULL;
hr = SHGetDesktopFolder(&pDesktopFolder); // Desktop's IShellFolder
interface
hr = SHGetMalloc(&pMalloc); // IMalloc interface, for releasing PIDLs
if (SUCCEEDED(hr))
{
// Assisn the Desktop's IShellFolder interface and the IMalloc interface to
global variables
// Calling the above functions and passing in these global variables results
in a compiler
// error; error C2664: : cannot convert parameter 1 from 'LPSHELLFOLDER __gc
* ' to 'IShellFolder ** '
m_pDesktopFolder = pDesktopFolder;
m_pMalloc = pMalloc;
// Set the ListView's SmallImage list to the system's SmallImageList
himl =
(HIMAGELIST)SHGetFileInfo((LPCWSTR)Marshal::String ToCoTaskMemUni(Application
::StartupPath).ToPointer(), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO),
uFlags | SHGFI_SMALLICON);
ListView_SetImageList((HWND)hWnd.ToPointer(), himl, LVSIL_SMALL);
// Set the ListView's LargeImage list to the system's LargeImageList
himl =
(HIMAGELIST)SHGetFileInfo((LPCWSTR)Marshal::String ToCoTaskMemUni(Application
::StartupPath).ToPointer(), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO),
uFlags | SHGFI_LARGEICON);
ListView_SetImageList((HWND)hWnd.ToPointer(), himl, LVSIL_NORMAL);
} //if (SUCCEEDED(hr))
} //OnCreateControl

This is the code that enumerates a folder and stores the relevant info. I
wanted this to be simpler. Originally I only wanted to store the PIDL for
each item and use that to retrieve the info needed (icon index, display
text, file type etc.) but I found that when I did that the same problem also
happens, only sooner. The problem seems to be in the repeated calls to
SHGetFileInfo.

virtual int GetFiles(LPITEMIDLIST pidl)
{
int retVal = -1;
IEnumIDList* pEnumIDList = NULL;
HRESULT hr = NULL;
LPITEMIDLIST apidl = NULL;
LPITEMIDLIST fullPidl = NULL;
SHCONTF grfFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS |
SHCONTF_INCLUDEHIDDEN;
UINT uFlags = SHGFI_PIDL | SHGFI_ICON | SHGFI_USEFILEATTRIBUTES |
SHGFI_TYPENAME | SHGFI_DISPLAYNAME | SHGFI_OVERLAYINDEX;
SHFILEINFO sfi;
m_fileList = new ArrayList();
// m_pParentFolder is a global variable for the current folder's
IShellFolder interface
hr = m_pParentFolder->EnumObjects(NULL, grfFlags, &pEnumIDList);
if (SUCCEEDED(hr))
{
while (HRESULT_CODE(pEnumIDList->Next(1, &apidl, NULL)) == NOERROR)
{
// PIDL is a class with static methods for working with PIDLs, Append joins
two PIDLs into one,
// taking a relative PIDL and its parent, and making a fully qualified PIDL
// (code for Append is from the Microsoft help file)
fullPidl = PIDL::Append(m_currentFolderPidl, apidl);
hr = SHGetFileInfo((LPCWSTR)fullPidl, FILE_ATTRIBUTE_NORMAL, &sfi,
sizeof(SHFILEINFO), uFlags);
if (SUCCEEDED(hr))
{
// ShellItem is a class that holds the shell object's PIDL, name, type,
image index and image overlay index
// ShellItem's destructor frees the PIDL using the IMalloc interface.
m_fileList is an ArrayList of ShellItems.
m_fileList->Add(new ShellItem(apidl, sfi.szDisplayName, sfi.szTypeName,
sfi.iIcon & 0x00FFFFFF, sfi.iIcon >24));
} //if (SUCCEEDED(hr))
m_pMalloc->Free(fullPidl);
} //while (HRESULT_CODE(pEnumIDList->Next(1, &apidl, NULL)) == NOERROR)
pEnumIDList->Release();
m_fileList->Sort(NULL); // ShellItem implements the IComparable interface.
ShellItems are sorted by their PIDLs
retVal = m_fileList->Count;
} //if (SUCCEEDED(hr))
return retVal;
} //GetFiles
The base class is a virtual ListView meaning that the ListView doesn't store
any info about the items it contains. The client is responsible for that
and the ListView calls back the client when it needs to know how to display
an item. This is the code that gets called.

virtual void OnGetInfo(VirtualList::GetInfoEventArgs* e)
{
HRESULT hr = NULL;
ULONG rgfInOut = SFGAO_GHOSTED;
LPITEMIDLIST apidl =
static_cast<ShellItem*>(m_fileList->Item[e->Index])->ItemIdList;
e->ImageIndex =
static_cast<ShellItem*>(m_fileList->Item[e->Index])->ImageIndex;
e->OverlayIndex =
static_cast<ShellItem*>(m_fileList->Item[e->Index])->OverlayIndex;
// m_pParentFolder is a global variable for the current folder's
IShellFolder interface
hr = m_pParentFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&apidl, &rgfInOut);
if (SUCCEEDED(hr))
{
e->Ghosted = (rgfInOut & SFGAO_GHOSTED) == SFGAO_GHOSTED;
} //if (SUCCEEDED(hr))
switch (e->Column)
{
case 0:
e->Text = static_cast<ShellItem*>(m_fileList->Item[e->Index])->Text;
break;
case 1:
e->Text = static_cast<ShellItem*>(m_fileList->Item[e->Index])->TypeName;
break;
} //switch (e->Column)
} //OnGetInfo

Thank you for reading this. Any help would be appreciated.

Paul
Feb 10 '07 #1
2 1804
"Paul W" <no****@vbtips.netwrote in message
news:Ad******************************@comcast.com. ..
My problem concerns the shell. If there's a better forum for this post,
please let me know.
If your task is to extend the shell in some way then

microsoft.public.platformsdk.shell

is where you find the shell experts.

If your question is about using the List View control in a more ordinary
application the

microsoft.public.win32.programmer.ui

is better.

That said, the regulars of this group have an extensive set of specialties
so it is possible that you will get a reply here so it's wise to check in
occaisionally.

Regards,
Will
www.ivrforbeginners.com
Feb 11 '07 #2
Thanks Will.

"William DePalo [MVP VC++]" <wi***********@mvps.orgwrote in message
news:uZ**************@TK2MSFTNGP04.phx.gbl...
"Paul W" <no****@vbtips.netwrote in message
news:Ad******************************@comcast.com. ..
My problem concerns the shell. If there's a better forum for this post,
please let me know.

If your task is to extend the shell in some way then

microsoft.public.platformsdk.shell

is where you find the shell experts.

If your question is about using the List View control in a more ordinary
application the

microsoft.public.win32.programmer.ui

is better.

That said, the regulars of this group have an extensive set of specialties
so it is possible that you will get a reply here so it's wise to check in
occaisionally.

Regards,
Will
www.ivrforbeginners.com


Feb 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When...
10
by: Nick Craig-Wood | last post by:
I'm trying to avoid using shell metacharacters in os.popen in a portable fashion. os.popen() only seems to take a string as the command which would need tricky quoting. os.popen2() can take a...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
12
by: Dixie | last post by:
Is there a way to shell to Microsoft Word from Access and load a specific template - using VBA? dixie
8
by: Mike | last post by:
Am trying to open a Microsoft Word .doc file using Access 2000 with Shell function (on Windows XP Operating system) Here is the code : Shell "C:\Program Files\Microsoft...
3
by: George Sakkis | last post by:
I'm trying to figure out why Popen captures the stderr of a specific command when it runs through the shell but not without it. IOW: cmd = if 1: # this captures both stdout and stderr as...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
3
by: Shafiq | last post by:
Hi, I am trying to insert a new toolbar button to the windows explorer menu. I an able to locate the correct ToolbarWindow32, and inserted a button using the code snippet shown below. However...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.