Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show system folders in a form ?

Status
Not open for further replies.

Johnweida

MIS
Apr 29, 2003
91
CN
experts,

I want to show some system folders such as "My omputer","My Documents" and "My favourite" etc. in on my form. How can I do it ? Thanks.

John Satellite
 
Sorry, I made some mistakes.
It should be :
I want to show some system folders such as "My Computer","My Documents" and "My favourite" etc. on my form. How can I do it ? Thanks
 
John

Can you explain what you want to show? Do you want to show the content of the system folders?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

Yes. show them in a container. Is it possible ?

John
 
John

Yes, use a Microsoft web browser activex and point the browser to the appropriate folder.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

Would you show me a small sample to show "My Computer" or "My Documents" please ? Thanks.

John

 
John

Here is a way to show any folders:
Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	ADD OBJECT olecontrol1 AS olecontrol WITH ;
		Top = 24, ;
		Left = 48, ;
		Height = 169, ;
		Width = 241, ;
		Name = "Olecontrol1" ,;
		OleClass = "Shell.Explorer.2"
	ADD OBJECT command1 AS commandbutton WITH ;
		AutoSize = .T., ;
		Top = 216, ;
		Left = 120, ;
		Height = 27, ;
		Width = 114, ;
		Caption = "Get folder content", ;
		Name = "Command1"
	PROCEDURE Init
		this.olecontrol1.oBJECT.Navigate2("c:\")
	ENDPROC
	PROCEDURE command1.Click
		LOCAL cDir
		cDir = GETDIR('','','',2)
		thisform.olecontrol1.navigate2(cDir)
	ENDPROC
ENDDEFINE

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

Great code!
Would you show me how to show the "My Computer","My Documents" and "My FAVORITES" folders please ?
Thank you again and again.

John Satellite
 
John
Since these folders are not considered "special folders" (and "my computer" is not really a folder), the only way to achieve this is to hard code the paths (Which may vary on different OS).


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
John

I believe Celtin gave you your answer in another website but to use his idea an my code (and for the benefit of other members), here is how to show "My Documents " folder on a form without know the actual path:
Code:
Declare short SHGetSpecialFolderPath in Shell32.dll ;
    integer hwndOwner, string @ lpszPath, ;
    integer nFolder, short fCreate
#Define MAX_PATH 267    
lpszPath = Replicate(Chr(0),MAX_PATH)
if SHGetSpecialFolderPath(0,@lpszPath,0x0005,0) # 0
  lcFolder = left(lpszPath,at(chr(0),lpszPath))
ENDIF
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.addobject("ole1","ole1")
oform1.ole1.navigate2(lcFolder)
oform1.Show()
RETURN
DEFINE CLASS form1 AS form
    DoCreate = .T.
    Caption = "My Document Folder"
    Name = "Form1"
    height = 600
    width = 800
ENDDEFINE
DEFINE CLASS ole1 as olecontrol
 OleClass = "Shell.Explorer.2"
 visible = .t.
 height = 500
 width = 700
ENDDEFINE

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

I tried your code below and it works very well.
*********************
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT olecontrol1 AS olecontrol WITH ;
Top = 24, ;
Left = 48, ;
Height = 169, ;
Width = 241, ;
Name = "Olecontrol1" ,;
OleClass = "Shell.Explorer.2"
PROCEDURE Init
machine_name = SYS(0)
usr_name = '#'
cut_spot = ATC(usr_name,machine_name)+2
unamelen = LEN(SYS(0))-cut_spot+1
uname = SUBSTR(ALLTRIM(machine_name),cut_spot,unamelen)
this.olecontrol1.oBJECT.Navigate2("C:\Documents and Settings\"+uname+"\My Documents")
ENDPROC
ENDDEFINE
*********************
I wonder that the navigate path of "My Documents" is different under different version of windows. Am I right ?

Thank you very very much.

John Satellite
 
John,

I wrote a FAQ on getting special folders in VFP including but not limited to the virtual folders "My Documents" and "My Computer"...you may want to check it out.

Get Path To Windows Special Folders (such as Desktop)
faq184-4264

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top