****************************************************************************** * Program : TViewDmo.PRG * Launch TViewDmo.EXE * ..........: Just a little contrib sample to test the TTView class * Make : MKTView * Date : 03/28/06 * Author(s) : Jn DECHEREUX & MARKUS II * Copyright : (c) 2006 - Jn DECHEREUX & Markus II - NTK Team. All Rights Reserved. ******************************************************************************** // -- Manifest Windows XP //#define ISOLATION_AWARE_ENABLED 1 // remove remarks if you want fancy XP Theme buttons. #include "windows.ch" #include "ntkcctrl.ch" #include "ntkgdi.ch" #include "ntkmsg.ch" #include "ntkacc.ch" #include "ntkcmd.ch" #include "wNtk.ch" #include "wNtkKeys.ch" #include "ntkbtn.ch" #include "ntkimg.ch" #define CR CHR(13) #define ID_BTN0 8000 #define ID_BTN1 8001 #define ID_BTN2 8002 #define ID_BTN3 8003 #define ID_BTN4 8004 #define ID_BTN5 8005 #define ID_BTN6 8006 #define ID_BTN7 8007 #define ID_TV00 9000 FUNCTION MAIN() LOCAL hWndDemo LOCAL cWinTitle := "TView+ImageList+Bitmap+Icon Demo..." LOCAL hIcon := NTK_LoadIcon( NTK_GetInstance() , "rICO01" ) LOCAL oMyTView, nPerCent := 5 LOCAL XMarge := 0 LOCAL hIconLst PRIVATE XWin := 550 PRIVATE YWin := 350 PRIVATE aBtnList := {} // Do not forget it! PRIVATE hEgg := NTK_LoadIcon( NTK_GetInstance(), "EGG" ) **PRIVATE hEgg2 := NTK_CopyImage( hEgg, IMAGE_ICON, 64, 64, NULL ) PRIVATE hMyBmp := NTK_LoadBitmap( NTK_GetInstance(), "PHONE" ) **PRIVATE hImgLst := NTK_ImageList_Create(16, 16, ILC_COLOR24+ILC_MASK, 6 ,10 ) **PRIVATE hBmpLst := NTK_LoadBitmap( NTK_GetInstance(), "IDB_TREE" ) **PRIVATE hMaskLst := NTK_LoadBitmap( NTK_GetInstance(), "IDB_TREE_MASK" ) **NTK_ImageList_Add( hImgLst, hBmpLst, hMaskLst ) **PRIVATE hLoupe1 := NTK_ImageList_GetIcon( hImgLst, 3, ILD_TRANSPARENT ) PRIVATE hImgLst := NTK_ImageList_Create(40, 40, ILC_COLOR24+ILC_MASK, 10,10 ) PRIVATE hBmpLst := NTK_ReadPictureToBmp( "Images\Image.bmp" ) NTK_ImageList_AddMasked(hImgLst, hBmpLst,NTK_RGB( 255,000,255)) NTK_ImageList_Add( hImgLst, hBmpLst, NULL ) NTK_DeleteObject( hBmpLst ) PRIVATE hBkClrBrush **CREATE SOLID BRUSH NTK_RGB( 50,100,255) TO hBkClrBrush CREATE BITMAP BRUSH FROM "Images/Fond.bmp" TO hBkClrBrush CREATE WINDOW hWndDemo ; TITLE cWinTitle ; // Minimum declaration ICON hIcon ; BRUSH hBkClrBrush ; AT 0,0 SIZE Xwin,Ywin ; STYLE WS_SYSMENU+WS_SIZEBOX+WS_MAXIMIZEBOX+WS_MINIMIZEBOX ; // We just want the close et Size Btn ON PAINT DoRePaint() ; ON MSG DoMsgHandler() ; ON EXIT DoExit() // ----- Ensure that the common control dynamic-link library (DLL) is loaded. // ----- Don't forget to use this command if U plan to use controls such as DatePicker, tooltips... NTK_InitCommonControlsEx( ICC_DATE_CLASSES + ICC_BAR_CLASSES + ICC_STANDARD_CLASSES + ICC_WIN95_CLASSES + ICC_TREEVIEW_CLASSES ) XMarge := round( ( ( Xwin - (3*130) )/2 ),0) @ YWin-140,XMarge BUTTON "Add &Parent F3" SIZE 40,120 ; ID ID_BTN1 ; SUPER ACCEL KEY K_F3 ; ACTION EventAddFolder(oMyTView, 1, "Parent Folder") ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "Click here or press Up arrow key create a new PARENT Folder from actual position..." ; OF hWndDemo @ YWin-140,XMarge+130 BUTTON "Add &Child F4" SIZE 40,120 ; ID ID_BTN2 ; SUPER ACCEL KEY K_F4 ; ACTION EventAddFolder(oMyTView, 2, "Child Folder") ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "Click here or press Up arrow key create a new CHILD Folder from actual position..." ; OF hWndDemo @ YWin-140,XMarge+260 BUTTON "&Del Member(s) F5" SIZE 40,120 ; ID ID_BTN3 ; SUPER ACCEL KEY K_F5 ; ACTION EventAddMember(oMyTView, "Member of", 3) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "Click here to delete a member or a group members to the current parent" ; OF hWndDemo @ YWin-90,XMarge BUTTON "Add &Girl Member F6" SIZE 40,120 ; ID ID_BTN4 ; SUPER ACCEL KEY K_F6 ; ACTION EventAddMember(oMyTView, "Girl Member of", 2) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "Click here to add a girl member to the current parent" ; OF hWndDemo @ YWin-90,XMarge+130 BUTTON "Add &Boy Member F7" SIZE 40,120 ; ID ID_BTN5 ; SUPER ACCEL KEY K_F7 ; ACTION EventAddMember(oMyTView, "Boy Member of", 3) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "Click here to add a boy member to the current parent" ; OF hWndDemo @ YWin-90,XMarge+260 BUTTON "&See Infos F12" SIZE 40,120 ; ID ID_BTN6 ; SUPER ACCEL KEY K_F12 ; ACTION EventSeeInfos(oMyTView) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "Click here to see infos about about current treer" ; OF hWndDemo *@ YWin-90,XMarge+260 BUTTON "&See Infos F12" SIZE 40,120 ; * ID ID_BTN6 ; * TYPE NTK_BT_OWNERDRAWN ; * SUPER ACCEL KEY K_F12 ; * ACTION EventSeeInfos(oMyTView) ; * STATE NTK_BT_ENABLE ; * FONT NTK_GetStockObject(SYSTEM_FONT) ; * STYLE BS_TOP+BS_RIGHT ; * TEXTCOLOR NTK_RGB(255,000,000) ; * BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch * BITMAP UP "hEgg" ; * BITMAP DN "hEgg" ; * BITMAP SHIFT TO 5,5 ; // , * MESSAGE "This is an owner drawn button, whole painted with NTK_BT_* styles. See NTKBTN.CH ..."+CR+" No need of Manifest! " ; * OF hWndDemo * CONTROL "Tree1",IDC_TREE1,"SysTreeView32",TVS_HASBUTTONS | * TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS | * TVS_TRACKSELECT | TVS_SINGLEEXPAND | TVS_INFOTIP | * TVS_FULLROWSELECT | WS_BORDER | WS_TABSTOP,2,8,134,110, * WS_EX_ACCEPTFILES // Create a empty TView Control. // Usage: TTView():New( hWndP, nTVID, y0,x0, y1,x1, cRootLabel, nStyle) oMyTView := TTView():New( hWndDemo, ID_TV00, 20,20,YWin-150,XWin-60, "MyRootTV" , WS_CHILD + WS_VISIBLE + WS_VSCROLL + WS_HSCROLL ) oMyTView:DrawLine := .T. // Draws lines that link child items to their parent item. oMyTView:LineAtRoot := .F. // Draws Link items at the root of the hierarchy. oMyTView:ItemHasButton := .T. // Adds a [+] button to the left side of each parent item. oMyTView:ItemHasChkBox := .F. // Creates checkboxes next to each item. oMyTView:EditLabels := .F. // Makes it possible for the user to edit the labels of tree-view items. oMyTView:ShowSelAlways := .T. // Causes a selected item to remain selected when the tree-view control loses focus. oMyTView:FgColor := NTK_RGB(200,255,255) // Item Text default Color oMyTView:BgColor := NTK_RGB(040,060,130) // TV background default color oMyTView:LineColor := NTK_RGB(000,255,255) // Line default Color oMyTView:Configure() // Configure the previously created TV with our new basic settings. // -- When you need to change colors on fly, you can use one of the following available methods... *oMyTView:SetfgColor( NTK_RGB(0,0,255) ) // Now, imagine you want blue text item... *oMyTView:SetBkgColor( NTK_RGB(255,255,128) ) // Now, imagine you want a yellow background... *oMyTView:SetLineColor( NTK_RGB(255,0,0) ) // Now, imagine you want red lines... // Now, imagine the name of the game... ;-) // Display window NTK_CenterWindow(hWndDemo) ACTIVATE WINDOW hWndDemo NORMAL // Start background processing AUTO HANDLE EVENTS OF WINDOW hWndDemo USING ; BUTTON LIST aBtnList CLOSE WINDOW hWndDemo RETURN ****** ****** ****** FUNCTION DoExit(hWnd, message, nwParam, nlParam) IF NTK_MsgBox( hWnd,; "Do you really want to quit ?",; "Tree View demo",; MB_OKCANCEL+MB_ICONQUESTION ) == IDOK //NTK_PostQuitMessage(0) // tell OS to terminate the application. Do not forget! //RETURN(.T.) // Quit RETURN( NTK_SendQuitEvent() ) // Same as both previous lines : Terminate current app. ENDIF RETURN(.F.) // Do not quit, keep on current task ****** ****** ****** FUNCTION DoMsgHandler( hWnd, message, nwParam, nlParam ) LOCAL aWndSize, nSizeX, nSizeY // 1 - Here you can handle Msg according to Window's traditionnal manner. // 2 - You're are not expected to handle WM_CREATE, WM_PAINT nor WM_DESTROY. // 3 - Be carreful to the return value... Read Win32 SDK or Petzold's book !! Do Case Case message == WM_SYSCOMMAND IF nwParam == SC_MAXIMIZE NTK_MsgBox( hWnd,; "Sound like you're not allowed to maximize this window...",; "Hello, my little boy !", MB_OK+MB_ICONASTERISK ) RETURN(0) // Returning other value than DefWinProc means we don't want to iconize the window... ENDIF Case message == WM_SIZE **nSizeX := NTK_LoWord(nlParam) **nSizeY := NTK_HiWord(nlParam) aWndSize := NTK_GetWindowRect( hWnd ) nSizeX := aWndSize[RECT_Right] - aWndSize[RECT_Left] nSizeY := aWndSize[RECT_Bottom] - aWndSize[RECT_Top] IF nSizeX < 540 NTK_SetWindowPos(hWnd,Nil,0,0,550,nSizeY,SWP_NOMOVE+SWP_NOZORDER) **NTK_MoveWindow(hWnd,aWndSize[RECT_Left],aWndSize[RECT_Top],550,nSizeY, .T.) ENDIF IF nSizeY < 340 NTK_SetWindowPos(hWnd,Nil,0,0,nSizeX,350,SWP_NOMOVE+SWP_NOZORDER) **NTK_MoveWindow(hWnd,aWndSize[RECT_Left],aWndSize[RECT_Top],nSizeX,350, .T.) ENDIF RETURN(0) Case message == WM_EXITSIZEMOVE // Using this, No need to implement a NTK_SetTimerEx() NTK_InvalidateRect(hWnd) **NTK_RedrawWindow( hWnd, nil, nil, RDW_INVALIDATE ) // Less flicking tone(5000,1) RETURN(0) Case message == WM_SIZING // The WM_SIZING message is sent to a window that the user is resizing. // By processing this message, an application can monitor the size and // position of the drag rectangle and, if needed, change its size or position. * aWndSize := NTK_Rect2A( nlParam ) * nSizeX := aWndSize[RECT_Right] - aWndSize[RECT_Left] * nSizeY := aWndSize[RECT_Bottom] - aWndSize[RECT_Top] * * * IF nSizeX < 540 * NTK_MoveWindow(hWnd,aWndSize[RECT_Left],aWndSize[RECT_Top],nSizeX,350, .T.) * RETURN .T. // According to M$ Docs: An application should return TRUE if it processes this message. * ENDIF * * IF nSizeY < 340 * NTK_MoveWindow(hWnd,aWndSize[RECT_Left],aWndSize[RECT_Top],550,nSizeY, .T.) * RETURN .T. // According to M$ Docs: An application should return TRUE if it processes this message. * ENDIF Case message == WM_GETMINMAXINFO * //How do I stop the user resizing my window? * //Handle WM_GETMINMAXINFO and adjust the ptMinTrackSize and ptMaxTrackSize values of the MINMAXINFO * //structure to be the same as the windows current size. You can use the same trick to allow resizing * //but enforce a minimum resize value. * * aWndSize := NTK_GetWindowRect( hWnd ) * nSizeX := aWndSize[RECT_Right] - aWndSize[RECT_Left] * nSizeY := aWndSize[RECT_Bottom] - aWndSize[RECT_Top] * * * aMinMaxInfo := NTK_MinMaxInfo2A( nlParam ) * aMinMaxInfo[ MINMAXINFO_ptMinTrackSizeX ] := nSizeX * aMinMaxInfo[ MINMAXINFO_ptMinTrackSizeY ] := nSizeY * aMinMaxInfo[ MINMAXINFO_ptMaxTrackSizeX ] := nSizeX * aMinMaxInfo[ MINMAXINFO_ptMaxTrackSizeY ] := nSizeY * * * NTK_MsgBox( hWnd,; * * STR(aMinMaxInfo[ MINMAXINFO_ptMaxTrackSizeX ]) + " / " + STR(aMinMaxInfo[ MINMAXINFO_ptMaxTrackSizeY ]) ,; * * "mmi_ptMaxTrackSizeY / mmi_ptMaxTrackSizeY" ) * * * NTK_MsgBox( hWnd,; * * STR(aMinMaxInfo[ MINMAXINFO_ptMaxSizeX ]) + " / " + STR(aMinMaxInfo[ MINMAXINFO_ptMaxSizeY ]) ,; * * "mmi_ptMaxSizeY / mmi_ptMaxSizeY" ) * *Case message == WM_KEYDOWN *Case message == WM_COMMAND EndCase RETURN( NTK_DEFWNDPROC(hWnd, message, nwParam, nlParam) ) ****** ****** ****** ****** ****** ****** FUNCTION DOREPAINT(hWnd, message, nwParam, nlParam, hDC) LOCAL aRect, Xoffset LOCAL aWndSize, Position, SizeX, SizeY aWndSize := aWndSize := NTK_GetWindowRect(hWnd) SizeX := aWndSize[RECT_Right] - aWndSize[RECT_Left] SizeY := aWndSize[RECT_Bottom] - aWndSize[RECT_Top] aRect := NTK_GetClientRect(hWnd) Xoffset := round( ( ( aRect[3] - (3*130) )/2 ),0) NTK_DrawIcon( hDC, 5, 260, hEgg ) NTK_DrawBmpTransparent( hDC, hMyBmp, 460, 240, NTK_RGB(255,0,255) ) Position := "X1,Y1 : "+LTRIM(STR(aWndSize[RECT_Left]))+","+LTRIM(STR(aWndSize[RECT_Top]))+" à " Position := Position+"X2,Y2 : "+LTRIM(STR(aWndSize[RECT_Right]))+","+LTRIM(STR(aWndSize[RECT_Bottom]))+" et " Position := Position+"Largeur,Hauteur : "+LTRIM(STR(SizeX))+","+LTRIM(STR(SizeY)) @ 2,2 SAY Position ; INTO CONTEXT hDC ; FONT NTK_GetStockObject(SYSTEM_FONT) ; TEXTCOLOR NTK_RGB(255,255,0) ; BACKCOLOR TRANSPARENT FOR i=0 TO 5 NTK_ImageList_Drawex( hImgLst, i, hDC, 500, (38*i), 0, 0, CLR_NONE, CLR_NONE, ILD_TRANSPARENT ) NEXT RETURN 0 ****** ****** ****** FUNCTION EventAddFolder( oTV, nLevel, cFolderLabel) IF nLevel==1 // Parent oTV:AddParentFolder(cFolderLabel) ELSE oTV:AddChildFolder(cFolderLabel) ENDIF NTK_SetFocus(oTV:hWnd) RETURN(Nil) ****** ****** ****** FUNCTION EventAddMember( oTV, cFolderLabel) LOCAL hParentItem := oTV:GetSelected() LOCAL cParentLabel := oTV:GetItemLabel( hParentItem ) oTV:AddChildMember(cFolderLabel+" "+cParentLabel) NTK_SetFocus(oTV:hWnd) RETURN(Nil) ****** ****** ****** FUNCTION EventSeeInfos( oTV ) LOCAL hItem := oTV:GetSelected() LOCAL nItemID := oTV:GetItemID() LOCAL cItemLabel := oTV:GetItemLabel( hItem ) LOCAL nItemLevel := oTV:GetItemLevel( hItem ) NTK_MsgBox( oTV:hWnd , "Current Item handle : "+STR(hItem) +CHR(13)+; "Current Item ID : "+STR(nItemID)+CHR(13)+; "Current Item Label : "+cItemLabel +CHR(13)+; "Current Item Level : "+STR(nItemLevel),; "Infos about TView handle # "+STR(oTV:hWnd) ) NTK_SelectWindow(oTV:hWndP) NTK_SetFocus(oTV:hWnd) RETURN(Nil) ********** ********** **********