Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Treeview & windows explorer
Message
De
21/02/2017 11:10:38
 
 
À
20/02/2017 17:30:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Divers
Thread ID:
01648235
Message ID:
01648277
Vues:
48
Problem solved !
any comments are welcome.
*oledradrop operation with a treeview (from a textbox,a listbox and windows explorer)
*note: vfp9 must run as level priveleges to permit the operation oledrgdrop.its forbidden (barred ixon) if administrator 
*priveleges.(explorer can run at administrator privelege here [tested]).
*  https://blogs.msdn.microsoft.com/patricka/2010/01/28/q-why-doesnt-drag-and-drop-work-when-my-application-is-running-elevated-a-mandatory-integrity-control-and-uipi/
*if dont want to see the complet path issue in code justfname (cfilename).



Publi yform
yform=Newobject("yoledd")
yform.Show
Read Events
Retu
*
Define Class yoledd As Form
	Top = 0
	Left = 0
	Height = 562
	Width = 288
	ShowWindow = 2
	OLEDragMode = 1
	Caption = "OLE Drag And Drop from explorer to vfp textbox,listbox,treeview"
	Name = "Form1"

	Add Object olecontrol1 As OleControl With ;
		oleclass="MSComctlLib.TreeCtrl.2" , ;
		anchor=15, ;
		Top = 60, ;
		Left = 0, ;
		Height = 348, ;
		Width = 288, ;
		Name = "Olecontrol1"

	Add Object text1 As TextBox With ;
		anchor=768,;
		OLEDragMode = 1, ;
		OLEDropMode = 1, ;
		FontName = "MS Sans Serif", ;
		FontSize = 8, ;
		Value = "Drag drop me to treeview", ;
		Height = 33, ;
		Left = 7, ;
		Top = 5, ;
		Width = 277, ;
		Name = "Text1"

	Add Object lstfiles As ListBox With ;
		Anchor=768,;
		OLEDragMode = 1, ;
		OLEDropMode = 1, ;
		FontName = "MS Sans Serif", ;
		FontSize = 8, ;
		Height = 108, ;
		Left = 1, ;
		TabIndex = 2, ;
		Top = 415, ;
		Width = 283, ;
		ItemTips = .T., ;
		Name = "lstFiles"

	Add Object command1 As CommandButton With ;
		anchor=768,;
		Top = 531, ;
		Left = 12, ;
		Height = 25, ;
		Width = 204, ;
		FontBold = .T., ;
		Caption = "Add listbox contents  to treeview", ;
		BackColor = Rgb(128,255,0), ;
		Name = "Command1"

	Add Object label1 As Label With ;
		Anchor=768,;
		AutoSize = .T., ;
		FontBold = .T., ;
		FontSize = 16, ;
		Caption = "?", ;
		Height = 27, ;
		Left = 240, ;
		MousePointer = 15, ;
		Top = 528, ;
		Width = 15, ;
		ForeColor = Rgb(255,0,0), ;
		Name = "Label1"

	Procedure Destroy
	Clea Events
	Endproc

	Procedure Load
	_Screen.WindowState=1
	Local m.o
	m.o=Home(1)
	Run/N explorer  &o
	Endproc

	Procedure olecontrol1.OLEDragOver
	Lparameters oDataObject, effect, Button, Shift, x, Y, state
	Local loNode
	Do Case
	Case  oDataObject.GetFormat(1) Or oDataObject.GetFormat(15) && 1=text  variant  15 list of files
		loNode = This.HitTest( 15*x, 15*Y )
		effect = 1
		This.DropHighlight = loNode
	Otherwise
		effect=0
	Endcase
	Endproc

	Procedure olecontrol1.OLEDragDrop
*** ActiveX Control Event ***
	Lparameters oDataObject, effect, Button, Shift, x, Y
	#Define CF_FILES              15     && A list of files
	#Define CF_HDROP              15     && A list of files
	Local lcData, loNode
	Thisform.LockScreen = .T.
	Do Case
	Case  oDataObject.GetFormat(1) && text-format
		Wait Window "text"  Nowait
		This.DropHighlight = .Null.
		effect =1
		lcData = oDataObject.GetData(1) && text-format
		loNode = This.HitTest( 15*x,15*Y )
		If Vartype(loNode)='O'
			This.nodes.Add( loNode, 4, "A" + Sys(3), lcData )
			loNode.expanded = .T.
		Else
			This.nodes.Add( .Null., 0, "A" + Sys(3), lcData )
		Endi

	Case oDataObject.GetFormat(CF_FILES)	&&as  Files CF_DROP 15
*CF_FILES or CF_HDROP  15  A handle that identifies a list of files, such as a set of files dragged
*from the Windows Explorer.
		oo=Thisform.olecontrol1
*DIMENSION aValues[1]
*oDataObject.GetData(CF_FILES, @aValues )    &&this is a problem !

		Local cfilename
		For Each cfilename In oDataObject.Files   FoxObject
			This.DropHighlight = .Null.
			effect =1
			loNode = This.HitTest( 15*x,15*Y )
			If Vartype(loNode)='O'
				This.nodes.Add( loNode, 4, "A" + Sys(3), cfilename )
				loNode.expanded = .T.
			Else
				This.nodes.Add( .Null., 0, "A" + Sys(3), cfilename )
			Endi
			Inkey( .5 )
		Next
******************************************************
	Endcase
	Thisform.LockScreen = .F.
	Endproc

	Procedure olecontrol1.Init
	This.Object.OLEDropMode = 1
	This.nodes.Add( .Null., 0, "A1", "Drop any text here" )
	Endproc

	Procedure text1.OLEDragOver
	Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState
	Do Case
	Case nState == 0		&&DRAG_ENTER
		Do Case
		Case oDataObject.GetFormat("OLE Variant Array")	&& Array
			This.OLEDropHasData = 1		&&DROPHASDATA_USEFUL
			This.OLEDropEffects = 1+2	&&DROPEFFECT_COPY + DROPEFFECT_MOVE

		Case oDataObject.GetFormat(1)				&& Text
			This.OLEDropHasData = 1		&&DROPHASDATA_USEFUL
			This.OLEDropEffects = 1+2	&&DROPEFFECT_COPY + DROPEFFECT_MOVE

		Case oDataObject.GetFormat(15)				&& Files CF_HDROP
			This.OLEDropHasData = 1		&&DROPHASDATA_USEFUL
			This.OLEDropEffects = 4		&&DROPEFFECT_LINK
		Otherwise
			This.OLEDropHasData = 0		&&DROPHASDATA_NOTUSEFUL
		Endcase
	Case nState == 1	&& Drag Leave
	Case nState == 2	&& Drag Over
	Endcase
	Endproc

	Procedure text1.OLEDragDrop
	Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
	Local i, cText, cNewStr

	If oDataObject.GetFormat(1)	&&CF_TEXT
		cText = oDataObject.GetData(1)
		This.Value =cText     && cNewStr
	Endif

	If oDataObject.GetFormat(15)	&&CF_TEXT
		Local aFiles[1]
		oDataObject.GetData(15,@aFiles)  &&can be sorted here
		effect =2  &&copy
		This.Value =aFiles(1)   &&retain only first file if selection
		This.Refresh
	Endif
	Endproc

	Procedure text1.Click
	Keyboard "{CTRL+A}"  &&select all
	Endproc

	Procedure lstfiles.OLEDragDrop
	Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
	Local aValues, i, cText, nOperation

*-- Check to see whether the user wants to copy or move
	If nShift == 1
		nOperation = 1	&&DROPEFFECT_COPY
	Else
		nOperation = 2	&&DROPEFFECT_MOVE
	Endif
	Thisform.LockScreen = .T.

	Do Case
	Case oDataObject.GetFormat("OLE Variant Array")
		Dimension aValues[ 1 ]
		oDataObject.GetData("OLE Variant Array", @aValues )

*-- Add each array element as
		For i = 1 To Alen(aValues,1)	&& for each row in the array
			If (Alen(aValues,2) > 1)
				This.AddItem( aValues[m.i,1])
			Else
				This.AddItem( aValues[m.i])
			Endif
		Next

	Case oDataObject.GetFormat(1)		&& Text
		cText = oDataObject.GetData(1)

*-- Add the text as a new item in the list
		This.AddItem( cText )


	Case oDataObject.GetFormat(15)	&& Files CF_DROP
		Dimension aValues[1]
		oDataObject.GetData(15, @aValues )

*-- Add each filename as a new item in the list
		For i = 1 To Alen(aValues)
			This.AddItem(aValues[m.i])
		Next
	Endcase
	Thisform.LockScreen = .F.

*-- Set the nEffect parameter for communication back to the source object
	nEffect = nOperation
	Endproc

	Procedure lstfiles.OLEDragOver
	Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState

	Do Case
	Case nState == 0		&&DRAG_ENTER
		Do Case
		Case oDataObject.GetFormat("OLE Variant Array")	&& Array
			This.OLEDropHasData = 1		&&DROPHASDATA_USEFUL
			This.OLEDropEffects = 1+2	&&DROPEFFECT_COPY + DROPEFFECT_MOVE

		Case oDataObject.GetFormat(1)				&& Text
			This.OLEDropHasData = 1		&&DROPHASDATA_USEFUL
			This.OLEDropEffects = 1+2	&&DROPEFFECT_COPY + DROPEFFECT_MOVE

		Case oDataObject.GetFormat(15)				&& Files CF_HDROP
			This.OLEDropHasData = 1		&&DROPHASDATA_USEFUL
			This.OLEDropEffects = 4		&&DROPEFFECT_LINK
		Otherwise
			This.OLEDropHasData = 0		&&DROPHASDATA_NOTUSEFUL
		Endcase
	Case nState == 1	&& Drag Leave
	Case nState == 2	&& Drag Over
	Endcase
	Endproc

	Procedure command1.Click
	With Thisform.olecontrol1
		Messagebox( " files to add to treeview="+Trans(Thisform.lstfiles.ListCount),0+32+4096,'',1200)

		For i=1 To Thisform.lstfiles.ListCount
			m.x=Thisform.lstfiles.List(i)
			.nodes.Add(Null,4, Sys(2015),m.x)
		Endfor
	Endwith
	Endproc

	Procedure label1.Click
	Local m.myvar
	TEXT to m.myvar pretext 7 noshow
		this code runs a treeview and windows explorer for oledragdrop operation.
		adjust position of explorer and select a file,list of files

		-dragdrop to the textbox (1 element retained-preferably work with one file at once for textbox (one line))
		-dragdrop to the lisbox: this is fill by the selected list of files.
		  if click on below button then fill treeview with this list (external method not oledragDrop one)
		-dragdrop from textbox to treeview: text is added as tree child (if click on on node area) or as
		 tree main(if click outside the node).

		-the treeview works now directly from the windows explorer.select anyfile,any files selection and oledragdrop
		to the treeview. problem solved.
		Note :oDataObject.Getformat(15,@files) returns always error.replaced by an OOP collection files syntax
        successfully.
        Yousfi Benameur 21 of february 2017.
	ENDTEXT
	Messagebox(m.myvar,"summary help")
	Endproc

Enddefine
*
*-- EndDefine: yoledd
can see this code in my blog
http://yousfi.over-blog.com/preview/37e28c96da8a60750533fc44e41225c0df97fe15
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform