Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 To: prasanna kunder
  Where is prasanna kunder?
 mumbai
 India
 prasanna kunder
 Tags
Subject: RE: can we change background of TreeCtr12
Thread ID: 311041 Message ID: 311094 # Views: 45 # Ratings: 1
Version: Visual FoxPro 9 Category: Classes and Objects
Date: Tuesday, June 28, 2011 7:44:37 PM         
   


> >
> > the api you pointed set a backcolor of treeview but its a bad one because the oleObject is not rendered as well.its maybe better to render the forecolor.
> > for answering you and in my knowledge, there is no way to do that (backcolor) in a top right way with the object MSComctlLib.TreeCtrl.2
> >
> > see this thread, there is many capabities of treeview (i believe its an exe).it set backcolor,forecolor,transparency,font...and a picture.
> >
> > https://www.foxite.com/archives/treeview-picturebackcolor-forecolor-0000232640.htm
> >
> > see also this
> > https://www.foxite.com/archives/0000305626.htm
> > here you can add a button for backcolor,forecolor,transparency...
> >
> > update: you can read these two articles on treeview here
> > http://doughennig.blogspot.com/2008/11/setting-background-color-of-treeview.html
> > http://doughennig.blogspot.com/2009/08/disabling-treeview-control.html
> >
> > Regards
> > Yousfi Benameur
>
>
> hello Yousfi
> yes your first link, have transparency treeview, but that is executable file
> i goggled, but i didn't govt any solution,
>
> thanks and waiting for your response
> prasanna

i take the second example i pointed above and added a button for transparency (with a spinner to change it interactively) and another disabled button for backcolor (because the result is bad to render the oleObject surface, i disable it in code).
the transparency is set to the form (the treeview have a handle but i cannot make it transparent itself).
the code ask you to point to your prefered images folder (its an image viewer here,can adapt for any thing else-see method yaction()).
you can learn many things in the code below. Simply copy the code in command window ,select all and run selection (rightclic).

publi yform
yform=newObject("asup")
yform.show
read events
return

DEFINE CLASS asup AS form
	Height = 570
	Width = 953
	ShowWindow = 2
	AutoCenter = .T.
	Caption = "Treeview as menu"
	MaxButton = .F.
	fnnodenbr = 0
	fimaxrows = 100
	fcreporttitle = ""
	fcreportformname = ""
	fcreportname = ""
	nIcon=0
	Name = "TREEX"
	DIMENSION fareport[100]

	ADD OBJECT txtselection AS textbox WITH ;
		FontBold = .T., ;
		FontSize = 10, ;
		Alignment = 2, ;
		Enabled = .F., ;
		Height = 24, ;
		Left = 19, ;
		TabIndex = 4, ;
		Top = 506, ;
		Width = 310, ;
		DisabledBackColor = RGB(192,192,192), ;
		DisabledForeColor = RGB(0,128,0), ;
		Name = "txtSelection"
		
	ADD OBJECT oleimagelist AS olecontrol WITH ;
	   oleclass="MSComctlLib.ImageListCtrl.2", ;
		Top = 444, ;
		Left = 324, ;
		Height = 100, ;
		Width = 100, ;
		Name = "oleImageList"

	ADD OBJECT oletreeview AS olecontrol WITH ;	    
	     oleclass="MSComctlLib.TreeCtrl.2", ;
		Top = 10, ;
		Left = 18, ;
		Height = 494, ;
		Width = 310, ;
		Name = "oleTreeView"
	
	ADD OBJECT image1 AS image WITH ;
		Stretch = 2, ;
		Height = 516, ;
		Left = 356, ;
		Top = 7, ;
		Visible = .F., ;
		Width = 589, ;
		Name = "Image1"		
		
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 535,;
		Left = 72,;
		Height = 25,;
		Width = 84,;
		FontBold = .T.,;
		Caption = "Collapse all",;
		MousePointer = 15,;
		BackColor = RGB(0,255,0),;
	    Name = "Command1"		
	
	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 536, ;
		Left = 192, ;
		Height = 25, ;
		Width = 97, ;
		enabled=.f.,;
		Caption = "Backcolor", ;
		BackColor = RGB(255,128,0), ;
		Name = "Command2"

	ADD OBJECT command3 AS commandbutton WITH ;
		Top = 537, ;
		Left = 311, ;
		Height = 25, ;
		Width = 109, ;
		Caption = "transparency", ;
		BackColor = RGB(0,255,255), ;
		Name = "Command3"

	ADD OBJECT spinner1 AS spinner WITH ;
		Height = 25, ;
		KeyboardHighValue = 255, ;
		KeyboardLowValue = 140, ;
		Left = 442, ;
		SpinnerHighValue = 255.00, ;
		SpinnerLowValue = 140.00, ;
		ToolTipText = "opacity 140-255", ;
		Top = 537, ;
		Width = 61, ;
		Value = 190, ;
		Name = "Spinner1"

	PROCEDURE yaction
		sele ycurs
			if eof()
			locate
			else
			skip
			endi
			
			with 	thisform
			if file(image)
			.image1.visible=.t.
			.image1.picture=(image)
			.txtSelection.value=justfname(image)
			.txtSelection.Refresh()
			endi
			endwith
	ENDPROC

	PROCEDURE Init		
	    this.setall("mousepointer",15,"commandbutton")
		this.setall("mousepointer",15,"spinner")
	THISFORM.ybuild()
		ENDPROC
		
PROCEDURE YBUILD
thisform.oletreeview.nodes.clear
	********************************************************************************
		* NOTE:  This example uses an array as the data source for oleTreeView, but
		* Init() could be easily modified to use a table.
		********************************************************************************
		LOCAL m.liSub1, m.lcChild, m.lcParent, m.lcName, m.loNode
		*                     0        1         2         3         4         5         6         7     
		*                     1234567890123456789012345678901234567890123456789012345678901234567890123456
		WITH ThisForm
			.faReport[001] = '000 Business management reports                        xxxxxxxxxx xxxxxxxxxx'
			.faReport[002] = '001 Week-to-date Business                              R_Bus      R_BusWk   '
			.faReport[003] = '001 Month-to-date Business                             R_Bus      R_BusMon  '
			.faReport[004] = '001 Quarter-to-date Business                           R_Bus      R_BusQtr  '
			.faReport[005] = '001 Half-to-date Business                              R_Bus      R_BusHaf  '
			.faReport[006] = '001 Year-to-date Business                              R_Bus      R_BusYr   '
			.faReport[007] = '001 Last Six Months Business                           R_Bus      R_BusHaf  '

			.faReport[008] = '000 Training, attendance, promotion reports            xxxxxxxxxx xxxxxxxxxx'
			.faReport[009] = '008 Attendance Statistics                              R_Tra      R_TraAtt  '
			.faReport[010] = '008 Absentee Roster                                    R_Abs      R_AbsRos  '
			.faReport[011] = "008 Training Director's Report                         R_Dir      R_DirTra  "
			.faReport[012] = '008 Monthly Training Matrix                            R_Tra2     R_Matrix  '
			.faReport[013] = '008 Pre-test Checklist                                 R_Pro      R_ProPre  '

			.faReport[014] = '000 Contract reports                                   xxxxxxxxxx xxxxxxxxxx'
			.faReport[015] = '014 Open Contracts                                     R_Con      R_ConOpen '
			.faReport[016] = '014 Paid Off Contracts                                 R_Con      R_ConOff  '
			.faReport[017] = '014 Canceled Contracts                                 R_Con      R_ConCan  '
			.faReport[018] = '014 Past Due Contracts                                 R_Con      R_ConPas  '
			.faReport[019] = '014 Expiring Contracts by Family                       R_Con      R_ConExp  '
			.faReport[020] = '014 Expiring Contracts by Student                      R_Con2     R_ConEx2  '
			.faReport[021] = '014 Unpaid Down Payments                               R_Con      R_ConUDP  '
			.faReport[022] = '014 Open Contracts Aging                               R_Con3     R_ConAge  '

			.faReport[023] = '000 Inquiry reports                                    xxxxxxxxxx xxxxxxxxxx'
			.faReport[024] = '023 Daily Appointments                                 R_Inq      R_InqApp  '
			.faReport[025] = '023 Inquiry Statistics                                 R_Inq      R_InqSta  '
			.faReport[026] = '023 Inquiry Sources                                    R_Inq      R_InqSou  '
			.faReport[027] = '023 Student Referrals                                  R_Inq      R_InqRef  '

			.faReport[028] = '000 Miscellaneous reports                              xxxxxxxxxx xxxxxxxxxx'
			.faReport[029] = '028 Student Roster (Alphabetical)                      R_Mis      R_MisRos  '
			.faReport[030] = '028 Data Analysis - Families                           R_Dat      R_DatFam  '
			.faReport[031] = '028 Data Analysis - Students                           R_Dat      R_DatStu  '
			.faReport[032] = '028 Data Analysis - Contracts                          R_Dat      R_DatCon  '
			.faReport[033] = '028 Data Analysis - Classes                            R_Dat      R_DatTra  '
			.faReport[034] = '028 Data Analysis - Promotion Groups                   R_Dat      R_DatPro  '

			FOR m.liSub1 = 035 TO .fiMaxRows
				.faReport[m.liSub1] = 'XXX'
			ENDFOR

			FOR m.liSub1 = 1 TO .fiMaxRows
				IF .faReport[m.liSub1] <> 'XXX'
					m.lcChild	= RIGHT(STR(1000 + m.liSub1,  4), 3) + '_'
					m.lcParent	= SUBSTR(.faReport[m.liSub1], 1, 3) + '_'
					m.lcName	= ALLTRIM(SUBSTR(.faReport[m.liSub1], 5, 50))
					IF m.lcParent = '000_'											&& Root.
		***				m.loNode = .oleTreeView.Nodes.Add(          , 1, m.lcChild, m.lcName, 1)
						m.loNode = .oleTreeView.Nodes.Add(          , 1, m.lcChild, m.lcName, 'ClsdFold')
						.oleTreeView.Nodes(m.liSub1).ExpandedImage	= 'OpenFold'
					ELSE
		***				m.loNode = .oleTreeView.Nodes.Add(m.lcParent, 4, m.lcChild, m.lcName, 3)
		gnLower = 3
		gnUpper = THISFORM.nIcon
					   	m.loNode = .oleTreeView.Nodes.Add(m.lcParent, 4, m.lcChild, m.lcName,  INT((gnUpper - gnLower + 1) * RAND( ) + gnLower))  &&random icon here
					ENDIF
				ENDIF
			ENDFOR
		ENDWITH
		
		*****************
	 &&expand all nodes
   n=thisform.oletreeview.nodes.Count
   if n>0
  for i=1 to n
   thisform.oletreeview.nodes(i).expanded=.t.
  endfor  
  thisform.oletreeview.nodes(2).selected=.t.
   thisform.oletreeview.nodeclick(thisform.oletreeview.nodes(2))
   endi	
		RETURN .T.
ENDPROC		


	PROCEDURE oletreeview.NodeClick
		LPARAMETERS Node
		LOCAL m.lcParent

		WITH ThisForm
			.fnNodeNbr			= Node.Index
			m.lcParent			= SUBSTR(.faReport[.fnNodeNbr], 1, 3)
			IF m.lcParent = '000'
				.fcReportTitle		= ''
				.fcReportFormName	= ''
				.fcReportName		= ''
		thisform.image1.visible=.f.
			ELSE
				.fcReportTitle		= ALLTRIM(SUBSTR(.faReport[.fnNodeNbr], 05, 50))
				.fcReportFormName	= ALLTRIM(SUBSTR(.faReport[.fnNodeNbr], 56, 10))
				.fcReportName		= ALLTRIM(SUBSTR(.faReport[.fnNodeNbr], 67, 10))
			thisform.yaction()
		  ENDI
		ENDWITH
		RETURN .T.
	ENDPROC
		
	Procedure oleimagelist.Init
    lcIconPath = addbs(Home(4)+'Icons\Win95')
    With This
      .ImageHeight =32  && 16
      .ImageWidth  =32  && 16
     gnbre=adir(gabase,lciconpath +"*.ico")
     thisform.nIcon=gnbre
  
   .ListImages.Add(,"OpenFold",LoadPicture(lcIconPath+"Openfold.ico"))
   .ListImages.Add(,"ClsdFold",LoadPicture(lcIconPath+"ClsdFold.ico"))
    
     for i=1 to gnbre
     if  !inlist(i,5,14)
          .ListImages.Add(,juststem(gabase(i,1)),LoadPicture(lcIconPath+gabase(i,1)))
	 endi          
     endfor
    Endwith
  Endproc

	PROCEDURE oletreeview.Init  
		This.Object.ImageList = Thisform.oleImageList.Object
		RETURN .T.
	ENDPROC
	
	PROCEDURE LOAD
	DECLARE INTEGER GetWindowLong IN user32;
				        INTEGER hWnd, INTEGER nIndex
				    DECLARE INTEGER SetWindowLong IN user32;
				        INTEGER hWnd, INTEGER nIndex, INTEGER dwNewLong
				    DECLARE INTEGER SetLayeredWindowAttributes IN user32;
				        INTEGER hwnd, INTEGER crKey,;
			        SHORT bAlpha, INTEGER dwFlags
	local yrep
	yrep=getdir("","","Select a folder of your prefered images")
		if empty(yrep)
		return
		endi
		yrep=addbs(yrep)
		gnbre=adir(gabase,yrep+"*.jpg")
		create cursor ycurs (image c(200))
		for i=1 to gnbre
		insert into ycurs values (yrep+gabase(i,1))
		endfor
		*brow
		locate		
	LOCAL OSHELL
	oshell=newoBject("shell.application")
	oshell.toggleDesktop()
	ENDPROC
	
	PROCEDURE ytranspa
		lparameters opacity
				#DEFINE LWA_COLORKEY 1
				#DEFINE LWA_ALPHA 2
				#DEFINE GWL_EXSTYLE -20
				#DEFINE WS_EX_LAYERED 0x80000
				LOCAL nExStyle, nRgb, nAlpha, nFlags
				nExStyle = GetWindowLong(THISform.HWnd, GWL_EXSTYLE)
				nExStyle = BITOR(nExStyle, WS_EX_LAYERED)
				= SetWindowLong(THISform.HWnd, GWL_EXSTYLE, nExStyle)
				= SetLayeredWindowAttributes(THISform.HWnd, rgb(0,255,0),opacity,LWA_COLORKEY+LWA_ALPHA)
	ENDPROC

	PROCEDURE yopaque
		#DEFINE LWA_COLORKEY 1
				#DEFINE LWA_ALPHA 2
				#DEFINE GWL_EXSTYLE -20
				#DEFINE WS_EX_LAYERED 0x80000
				LOCAL nExStyle
				nExStyle = GetWindowLong(THISform.HWnd, GWL_EXSTYLE)
				nExStyle = BITXOR(nExStyle, WS_EX_LAYERED)
				 = SetWindowLong(THISform.HWnd, GWL_EXSTYLE, nExStyle)
				 thisform.cls
				thisform.backcolor=thisform.backcolor   
				 thisform.refresh
	ENDPROC

	
	PROCEDURE command1.Click
		do case
		case this.caption="Collapse all"
		this.caption="Expand all"
		 &&expand all nodes
		   n=thisform.oletreeview.nodes.Count
		   if n>0
		  for i=1 to n
		   thisform.oletreeview.nodes(i).expanded=.f.
		  endfor  
		  endi
		case this.caption="Expand all" 
		this.caption="Collapse all"
		 &&collapse all nodes
		   n=thisform.oletreeview.nodes.Count
		   if n>0
		  for i=1 to n
		   thisform.oletreeview.nodes(i).expanded=.t.
		  endfor  
		  endi
		endcase
	ENDPROC
	
		PROCEDURE command2.Click
		Treeview=thisform.oletreeview
		local xcolor
		xcolor=getcolor()
		#define TVM_SETBKCOLOR 4381
		DECLARE INTEGER SendMessage IN WIN32API INTEGER hWnd,INTEGER wMsg,  INTEGER wParam, INTEGER lParam
		SendMessage(TreeView.hWnd, TVM_SETBKCOLOR, 0,  xcolor)
		thisform.refresh
		thisform.ybuild()
	ENDPROC

	PROCEDURE command3.Click
		do case
		case this.caption="transparency"
		this.caption="opaque"
		thisform.ytranspa(thisform.spinner1.value)

		case this.caption="opaque"
		this.caption="transparency"
		thisform.yopaque()
		endcase
	ENDPROC

	PROCEDURE spinner1.InteractiveChange
		if thisform.command3.caption="opaque" and this.value>=140  &&transparency low level=140 here
		thisform.ytranspa(this.value)
		endi
	ENDPROC
	
    PROCEDURE DESTROY
    CLEA EVENTS
    ENDPROC
    
ENDDEFINE






Regards
Yousfi Benameur

ENTIRE THREAD

can we change background of TreeCtr12 Posted by prasanna kunder @ 6/28/2011 12:55:27 PM
RE: can we change background of TreeCtr12 Posted by Borislav Borissov @ 6/28/2011 1:41:41 PM
RE: can we change background of TreeCtr12 Posted by prasanna kunder @ 6/28/2011 2:10:29 PM
RE: can we change background of TreeCtr12 Posted by Borislav Borissov @ 6/28/2011 3:16:07 PM
RE: can we change background of TreeCtr12 Posted by Yousfi Benameur @ 6/28/2011 3:19:44 PM
RE: can we change background of TreeCtr12 Posted by prasanna kunder @ 6/28/2011 5:45:40 PM
RE: can we change background of TreeCtr12 Posted by Yousfi Benameur @ 6/28/2011 7:44:37 PM