Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 Tags
Subject: drop any image on form & listbox
Thread ID: 232560 Message ID: 232560 # Views: 84 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Active X Controls & OLE Automation
Date: Wednesday, June 24, 2009 1:08:44 PM         
   


How to drop any image file into a form or in a listbox ?
this question went to me in the sample provided for download in Message ID: 232474 for the first time.i never use it.
this code permit to drop any picture from the windows explorer into a form property or as an item in a listbox.The picture is viewed automatically on the form and typed with entier path.
Here only jpg,bmp,gif and png are coded.I share it with all.

*--Author Yousfi Benameur El Bayadh Algeria
*--Time stamp mercredi 24 juin 2009; 10:58:49
*--Subject :Drop name image file into a form
*-- Refrence: VFP solutions

PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form
	Top = 93
	Left = 185
	Height = 231
	Width = 543
	ShowWindow = 2
	DoCreate = .T.
	OLEDropMode = 1
        alwaysonTop=.t.
        showtips=.t.
	Caption = "Drop pictures files into a listbox & form"
	ypict = ""
	Name = "form1"

	ADD OBJECT list1 AS listbox WITH ;
		OLEDragMode = 1, ;
		OLEDropMode = 1, ;
		FontName = "MS Sans Serif", ;
		FontSize = 8, ;
		Height = 24, ;
		Left = 11, ;
		TabIndex = 2, ;
		Top = 48, ;
		Width = 324, ;
		ItemTips = .T., ;
		AutoHideScrollbar = 1, ;
		Name = "List1"

	ADD OBJECT image1 AS image WITH ;
		Stretch = 2, ;
		Height = 120, ;
		Left = 348, ;
		Top = 48, ;
		Visible = .F., ;
		Width = 180, ;
		Name = "Image1"

	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 12, ;
		Left = 12, ;
		Height = 25, ;
		Width = 73, ;
		Caption = "Explorer", ;
		Name = "Command2"

	ADD OBJECT label1 AS label WITH ;
		FontSize = 8, ;
		BackStyle = 0, ;
		Caption = "", ;
		Height = 25, ;
		Left = 12, ;
		Top = 180, ;
		Width = 529, ;
		ForeColor = RGB(0,0,255), ;
		Name = "Label1"

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 0, ;
		Left = 480, ;
		Height = 37, ;
		Width = 37, ;
		FontBold = .T., ;
		FontSize = 11, ;
		Caption = "?", ;
		ForeColor = RGB(0,255,0), ;
		Name = "Command1"

	PROCEDURE OLEDragDrop
		LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
		LOCAL aValues, i, cText, nOperation
		nshift=0
		this.list1.clear
		Thisform.LockScreen = .T.

			DIMENSION aValues[1]
			oDataObject.GetData(15, @aValues )
			FOR i = 1 to alen(aValues)
		if inlist(lower(justext(aValues[m.i])),"jpg","bmp","gif","png")
		        xval=(aValues[m.i] )
				thisform.ypict=xval
				thisform.image1.picture=xval
				thisform.image1.visible=.t.
				thisform.label1.caption=xval
		wait window (xval)	 timeout 0.5

		else

		thisform.ypict=""
		thisform.image1.visible=.f.
		thisform.label1.caption=""

		endi


		NEXT

		Thisform.LockScreen = .F.

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


	PROCEDURE 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 Destroy
		clea events
	ENDPROC


	PROCEDURE list1.OLEDragDrop
		LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
		LOCAL aValues, i, cText, nOperation
		Thisform.LockScreen = .T.
		**oDataObject.GetFormat(15)	&& Files CF_DROP
			DIMENSION aValues[1]
			oDataObject.GetData(15, @aValues )
		this.clear   
			*-- Add picture as a new item in the list
			FOR i = 1 to alen(aValues)
		if inlist(lower(justext(aValues[m.i])),"jpg","bmp","gif","png")
		xval=(aValues[m.i] )
				This.AddItem( xval )
			thisform.label1.caption=xval
				thisform.ypict=xval
				thisform.image1.picture=xval
				thisform.image1.visible=.t.
		wait window (xval)	 timeout 0.5

		else
		thisform.ypict=""
		thisform.image1.visible=.f.
		thisform.label1.caption=""
		endi

		NEXT

		Thisform.LockScreen = .F.

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

	PROCEDURE list1.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 image1.Init
		if file(thisform.ypict)
				this.visible=.t.
			else
				this.visible=.f.
		endi
	ENDPROC


	PROCEDURE command2.Click
		run/n "explorer"
	ENDPROC

	PROCEDURE command1.Click
		text to myvar noshow
Drop any image (jpg,bmp,gif,png) file from the Windows Explorer into 
the form or listbox.
The listbox  or the property form.ypict is filled with only the last image 
and with complet path and shown in the control image.
Instead making a button with getpict()....you can drop from the explorer
directly to the form and retain only the last picture for using.
    
    *--Author Yousfi Benameur El Bayadh Algeria
	*--Time stamp mercredi 24 juin 2009; 11:46:27
	*--Subject :Drop an image into a form or listbox
		endtext
		messagebox(myvar,0+32+4096,"Drop images")
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1


Dont rate please.its only for the pleasure to help.Give me only a feed back.
Yousfi Benameur



COMPLETE THREAD
drop any image on form & listbox Posted by Yousfi Benameur @ 6/24/2009 1:08:44 PM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/25/2009 1:54:50 AM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/25/2009 2:36:18 AM
RE: drop any image on form & listbox Posted by Cesar @ 6/25/2009 3:22:04 AM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/25/2009 11:17:22 AM
RE: drop any image on form & listbox Posted by Cesar @ 6/25/2009 3:12:09 PM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/29/2009 5:49:47 PM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/29/2009 7:17:56 PM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/30/2009 2:25:34 AM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/30/2009 10:02:36 AM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/30/2009 2:04:41 PM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/30/2009 10:37:14 AM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/29/2009 5:40:21 PM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/29/2009 5:37:03 PM
RE: drop any image on form & listbox Posted by Glen Villar @ 6/25/2009 1:59:12 AM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/30/2009 10:51:52 AM
RE: drop any image on form & listbox Posted by Bernard Bout @ 6/30/2009 2:10:01 PM
RE: drop any image on form & listbox Posted by Yousfi Benameur @ 6/30/2009 10:24:53 PM