March 28, 2024, 06:23:49 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


(Shell) IShellView Interface

Started by fasecero, November 07, 2010, 01:36:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

Hello. I am having problems trying to implement this method:
pIShellView->CreateViewWindow(...)

This is the sample code:

$INCLUDE "WindowsSDK.inc"
$INCLUDE "shlobj.inc"

pointer pidlDesktop = 0
IShellFolder folderDesktop = 0
IShellView desktopView = 0
IShellBrowser browser

CONST LISTVIEW_1 = 1
DIALOG d1
CREATEDIALOG d1,0,0,926,513,0x80C80080,0,"Caption",&d1_handler
'CONTROL d1,@LISTVIEW,"",15,9,895,488,0x50800000,LISTVIEW_1

DOMODAL d1

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
OnInit()
CASE @IDCLOSEWINDOW
OnFinish()
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE LISTVIEW_1
/* respond to control notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB

SUB OnInit()
string pszPath = ""
FOLDERSETTINGS fs
WINRECT rc
pointer phWinLV

' get the desktop PIDL
SHGetSpecialFolderLocation(d1.hwnd, CSIDL_DESKTOP, &pidlDesktop)
' get the desktop folder
SHGetDesktopFolder(folderDesktop)
' create a shell view
folderDesktop->CreateViewObject(d1.hwnd, _IID_IShellView, desktopView)

' browser = ... how do I get the IShellBrowser interface?

fs.ViewMode = FVM_ICON
fs.fFlags = 0
browser->AddRef()
desktopView->CreateViewWindow(NULL, &fs, browser, &rc, phWinLV ) ' what's wrong in this line?
ENDSUB

SUB OnFinish()
desktopView->DestroyViewWindow()
desktopView->Release()

folderDesktop->Release()

CoTaskMemFree(pidlDesktop)
ENDSUB

Shell "stuff" is new to me, so this may destroy the planet or something, please carefully :)

sapero

Hello,

It is safe while it doesn't delete or write outside the app :)
Check out the fixed version. I had also to fix some headers to compile it, so I'm attaching all files.

fasecero

Hello Sapero. Thank you once again, your help is invaluable (and my apologies for taking so long to respond).
There are many things I want to develop, things that need shell/COM, so I'll go step by step (I am studying all the samples that you have already posted).
This particular example works fine except on Win7. The CreateViewObject(...) method returns desktopView = NULL, so I get a segmentation fault in GetCurrentInfo(...). Perhaps this interface is not supported anymore on this operating system.

sapero

Maybe CoInitialize is required in Win7? You should always call this function before creating interfaces, and CoUninitialize at the end, after releasing all objects.
Use Ole{Un}initialize instead if you need drag-drop functioning.

Check errors. Save return values in a variable of type HRESULT (signed), or better use UINT if you are planning to PRINT it:
UINT hr = folderDesktop->CreateViewObject(d1.hWnd, _IID_IShellView, &desktopView)
if (FAILED(hr)) ' or if (hr < 0)
print "CreateViewObject failed with eror 0x",HEX$(hr)
else

fasecero

Using CoInitialize/CoUninitialize it works like a charm.

Cheers.