Here is RASHAD's first program with comments added.
I hope some might find it useful in understanding Windows programming.
Code: Select all
#TVM_SETITEMHEIGHT = $111B
#TVM_GETITEMHEIGHT = $111C
#TVM_SETBKCOLOR = $111D
Global hBrush,hBrush2,TVH
; The CreateSolidBrush function creates a logical brush
; that has the specified solid color.
; When you no longer need the HBRUSH object, call the
; DeleteObject function To delete it.
hBrush = CreateSolidBrush_($D7FEFE)
; GetSysColor
; Retrieves the current color of the specified display element.
; Display elements are the parts of a window And the display
; that appear on the system display screen.
; COLOR_HIGHLIGHT - Item(s) selected in a control.
hBrush2 = CreateSolidBrush_(GetSysColor_(#COLOR_HIGHLIGHT))
Procedure WCallback(hWnd,uMsg,wParam,lParam)
result=#PB_ProcessPureBasicEvents
Select uMsg
Case #WM_NOTIFY
; Structure NMTVCUSTOMDRAW -Contains information specific to an
; NM_CUSTOMDRAW (tree view) notification code
; sent by a tree-view control.
; nmcd.NMCUSTOMDRAW - Structure that contains general custom draw
; information
; | Structure NMCUSTOMDRAW
; | hdr.NMHDR - Contains information about
; | a notification message.
; | | Structure NMHDR
; | | hwndFrom.i - A window handle to
; | | the control sending
; | | the message.
; | | idFrom.i - An identifier of the
; | | control sending the message.
; | | code.l - A notification code.
; | | EndStructure
; | dwDrawStage.l - The current drawing stage.
; | hdc.i - A handle to the control's device context.
; | Use this HDC (Handle to Device Context)
; | to perform any GDI functions.
; | rc.RECT - The RECT structure that describes the bounding
; | rectangle of the area being drawn.
; | Structure RECT
; | | left.l
; | | top.l
; | | right.l
; | | bottom.l
; | EndStructur
; | dwItemSpec.i - The item number.
; | uItemState.l - The current item state.
; | lItemlParam.i - Application-defined item data.
; | EndStructure
; clrText.l - COLORREF value representing the color that will
; be used to display text foreground in the
; tree-view control.
; clrTextBk.l - COLORREF value representing the color that will
; be used To display text background in the
; tree-view control.
; iLevel.l - (int) Zero-based level of the item being drawn.
; The root item is at level zero, a child of the
; root item is at level one, And so on.
; EndStructure
*tvCD.NMTVCUSTOMDRAW=lParam
; #NM_CUSTOMDRAW - Notifies a control's parent window about custom drawing operations.
; This notification code is sent in the form of a WM_NOTIFY message.
If *tvCD\nmcd\hdr\hwndFrom=GadgetID(0) And *tvCD\nmcd\hdr\code = #NM_CUSTOMDRAW
Select *tvCD\nmcd\dwDrawStage
; #CDDS_PREPAINT - Before the paint cycle begins.
; #CDRF_NOTIFYITEMDRAW - The control will notify the parent of any item-related drawing operations.
; It will send NM_CUSTOMDRAW notification codes before And after drawing items.
Case #CDDS_PREPAINT:ProcedureReturn #CDRF_NOTIFYITEMDRAW
; #CDDS_ITEMPREPAINT - Before an item is drawn.
; #CDRF_NOTIFYPOSTPAINT - The control will notify the parent after painting an item.
Case #CDDS_ITEMPREPAINT: ProcedureReturn #CDRF_NOTIFYPOSTPAINT
; #CDDS_ITEMPOSTPAINT - After an item has been drawn.
Case #CDDS_ITEMPOSTPAINT
; The dwItemSpec member of the nmcd structure contains the handle of the item being drawn.
Item=*tvCD\nmcd\dwItemSpec
tvr.RECT\left=Item
; TVM_GETITEMRECT message - Retrieves the bounding rectangle for a tree-view
; item and indicates whether the item is visible.
; Parameters: wParam - Value specifying the portion of the item
; for which to retrieve the bounding rectangle.
; If this parameter is TRUE, the bounding rectangle
; includes only the text of the item. Otherwise,
; it includes the entire line that the item occupies
; in the tree-view control.
; lParam - Pointer to a RECT Structure that, when sending the
; message, contains the handle of the item to retrieve
; the rectangle for. After returning from the message,
; this parameter contains the bounding rectangle.
; The coordinates are relative To the upper-left corner
; of the tree-view control.
SendMessage_(GadgetID(0),#TVM_GETITEMRECT,#True,@tvr)
tvi.TV_ITEM ; Specifies or receives attributes of a tree-view item.
; Structure TV_ITEM
; | mask.l - Array of flags that indicate which of the other structure
; | members contain valid Data.
; | hItem.i - Handle to the item.
; | state.l - Set of bit flags and image list indexes that indicate the
; | item's state.
; | stateMask.l - Bits of the state member that are valid.
; | *pszText - Pointer to a null-terminated string that contains the
; | item text If the Structure specifies item attributes.
; | cchTextMax.l - Size of the buffer pointed to by the pszText member,
; | in characters.
; | iImage.l - Index in the tree-view control's image list of the icon
; | image To use when the item is in the nonselected state.
; | iSelectedImage.l - Index in the tree-view control's image list of
; | the icon image To use when the item is in the
; | selected state
; | cChildren.l - lag that indicates whether the item has associated
; | child items.
; | lParam.i - A value to associate with the item.
; EndStructure
tvi$ = Space(#MAX_PATH) ; #MAX_PATH = 260
; TVIF_HANDLE - The hItem member is valid.
; TVIF_PARAM - The lParam member is valid.
; TVIF_TEXT - The pszText And cchTextMax members are valid.
tvi\mask = #TVIF_HANDLE | #TVIF_PARAM | #TVIF_TEXT
tvi\pszText = @tvi$
tvi\cchTextMax = #MAX_PATH
tvi\hItem=Item
; TVM_GETITEM message - Retrieves some or all of a tree-view item's attributes.
SendMessage_(GadgetID(0),#TVM_GETITEM,0,tvi)
; SetBkMode - Sets the background mix mode of the specified device context.
; #TRANSPARENT - Background remains untouched.
SetBkMode_(*tvCD\nmcd\hdc,#TRANSPARENT)
; #CDIS_FOCUS - The item is in focus.
; #CDIS_SELECTED - The item is selected.
If *tvCD\nmcd\uItemState = #CDIS_FOCUS | #CDIS_SELECTED
; FillRect - Fills a rectangle by using the specified brush.
; This function includes the left And top borders, but excludes
; the right And bottom borders of the rectangle.
FillRect_(*tvCD\nmcd\hdc, tvr, hBrush2)
; SetTextColor - Sets the text color for the specified device context
; to the specified color.
SetTextColor_(*tvCD\nmcd\hdc,$FFFFFF)
Else
FillRect_(*tvCD\nmcd\hdc, tvr, hBrush)
SetTextColor_(*tvCD\nmcd\hdc,0)
EndIf
If FindString(tvi$,#CRLF$) > 0
tvr\left + 2
; DrawText - Draws formatted text in the specified rectangle.
; #DT_WORDBREAK - Breaks words. Lines are automatically broken between
; words If a word would extend past the edge of the rectangle
; specified by the lpRect parameter. A carriage Return-line
; feed sequence also breaks the line.
; If this is not specified, output is on one line.
DrawText_(*tvCD\nmcd\hdc,tvi$,Len(tvi$),tvr,#DT_WORDBREAK )
Else
; TextOut - Writes a character string at the specified location,
; using the currently selected font, background color, And text color.
TextOut_(*tvCD\nmcd\hdc,tvr\left+2,tvr\top+14,tvi$,Len(tvi$))
EndIf
; #CDRF_NEWFONT - The application specified a new font for the item
ProcedureReturn #CDRF_NEWFONT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
LoadFont(0,"Tahoma",14)
If OpenWindow(0,0,0,600,400,"TreeGadget",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
TreeGadget(0, 10,10,580,380)
; TVM_SETBKCOLOR message - Sets the background color of the control.
SendMessage_(GadgetID(0), #TVM_SETBKCOLOR, 0, $D7FEFE)
SetGadgetFont( 0,FontID(0))
; TVM_GETITEMHEIGHT message - Retrieves the current height of the each tree-view item.
TVH = SendMessage_(GadgetID(0),#TVM_GETITEMHEIGHT,0,0)
; TVM_SETITEMHEIGHT message - Sets the height of the tree-view items.
SendMessage_(GadgetID(0),#TVM_SETITEMHEIGHT,TVH*2,0)
AddGadgetItem (0,-1,"First Main Node"+#CRLF$+"Happ New Year",0,0)
AddGadgetItem (0,-1,"Sub Item!"+#CRLF$+"RASHAD",0,1)
AddGadgetItem (0,-1,"Second Main Level Node"+#CRLF$+"Happy New Year",0,0)
AddGadgetItem(0,-1,"Sub text",0,1)
AddGadgetItem(0,-1,"Third Node")
SetWindowCallback(@WCallback())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
DeleteObject_(hBrush)
DeleteObject_(hBrush2)
EndIf