craigsboyd
IS-IT--Management
There was a question here somewhere about displaying the folders from outlook into a treeview control...I'll be darned if I can find it now (perhaps it was deleted?) Anyways, here is some code I worked up to do just that...cut-n-paste the code below into a prg and run it from within VFP to see how it works.
craig1442@mchsi.com
Code:
PUBLIC goForm
goForm = CREATEOBJECT("form1")
goform.show()
**************************************************
*-- Form: form1 (f:\temp\form3.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 09/07/04 05:09:01 PM
*
DEFINE CLASS form1 AS form
Top = 3
Left = 0
Height = 450
Width = 285
DoCreate = .T.
Caption = "Outlook Folders Enumerated"
nextkey = "1_"
Name = "Form1"
lastkey = .F.
ADD OBJECT olecontrol1 AS olecontrol WITH ;
Top = 10, ;
Left = 20, ;
Height = 396, ;
Width = 240, ;
Name = "Olecontrol1", ;
OleClass= "MSComctlLib.TreeCtrl.2"
ADD OBJECT command1 AS commandbutton WITH ;
Top = 415, ;
Left = 12, ;
Height = 27, ;
Width = 84, ;
Caption = "Load Me", ;
Name = "Command1"
PROCEDURE loadtreeview
LOCAL loOutlook, loNameSpace, loFolders, lcKey, loNode, lnCounter
loOutlook = CreateObject('Outlook.Application')
loNameSpace = loOutlook.GetNameSpace('MAPI')
loFolders = loNameSpace.Folders
FOR lnCounter = 1 TO loFolders.COUNT
lcKey = THISFORM.NewKey()
loNode = THISFORM.olecontrol1.Nodes.ADD(,, lcKey, loFolders.ITEM(lnCounter).NAME, 0)
loNode.Expanded = .T.
IF TYPE("loFolders.ITEM(lnCounter).Folders.count") = "N"
IF loFolders.ITEM(lnCounter).Folders.COUNT > 0
THISFORM.GetChildren(loFolders.ITEM(lnCounter).folders, lcKey)
ENDIF
ENDIF
ENDFOR
loNameSpace = NULL
loOutlook = NULL
RELEASE loNameSpace
RELEASE loOutlook
ENDPROC
PROCEDURE getchildren
LPARAMETERS toFolder, tcKey
LOCAL loNode, lnCounter
FOR lnCounter = 1 TO toFolder.COUNT
lcKey = THISFORM.NewKey()
loNode = THISFORM.olecontrol1.Nodes.ADD(tcKey, 4, lcKey, toFolder.ITEM(lnCounter).NAME, 0)
loNode.Expanded = .T. && Take this line out to speed display
IF TYPE("toFolder.ITEM(lnCounter).Folders.count") = "N"
IF toFolder.ITEM(lnCounter).Folders.COUNT > 0
THISFORM.GetChildren(toFolder.ITEM(lnCounter).folders, lcKey)
ENDIF
ENDIF
ENDFOR
ENDPROC
PROCEDURE newkey
*!* Procedure Borrowed from VFP example in Solution
lcKey = THIS.NextKey
THIS.NextKey = ALLTRIM(STR(VAL(THIS.NextKey) + 1) + "_")
RETURN lcKey
ENDPROC
PROCEDURE command1.Click
this.Visible = .f.
thisform.loadtreeview()
ENDPROC
ENDDEFINE
*
*-- EndDefine: form1
**************************************************

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon