Control

Control ist die BasisClasse für alle Controls und sollte nicht aufgerufen werden. Die nachfolgend aufgelisteten Eigenschaften werden an alle Controls vererbt und stehen dort zur verfühung

PropertyDatentyp(Read/Write)Hinweise
LeftInteger (R/W) Linke Position
TopInteger (R/W) Obere Position
WidthInteger (R/W) Weite
HeightInteger (R/W) Höhe
ClientHeightInteger (R) Höhe des Clientbereiches
ClientWidthInteger (R) Breite des Clientbereiches
CaptionString (R/W) Gilt für Buttons und Panel , nicht für Listbox,Combobox,Edit und Scrollbar
VisibleInteger (R/W) TRUE = sichtbar (voreingestellt) ; FALSE = nicht sichtbar
EnabledInteger (R/W) TRUE = aktiv (voreingestellt) ; FALSE = inaktiv
ColorUInteger (R/W) Hintergrundfarbe ; voreingestellt ist hellgrau
TextColorUInteger (R/W) Textfarbe ; voreingestellt ist schwarz
HandleHWND (R) Handle des Control (nur lesen !)
CtHandleHWND (R) Handle des Containers (nur lesen !)
alle Control haben ein eigenes unsichtbares Container Elternfenster
TipString (W) Der hier zugeordnete String wird als ToolTip angezeigt
SUB ArgumenteHinweis
Invalidate keine Veranlasst das senden einer WM_PAINT Botschaft
Repaint keine Wie Invalidate aber mit Nicht-Clientbereich
setFont (Face As String,
ByVal size As Integer,
ByVal bold As Integer,
ByVal italic As Integer,
ByVal underlin As Integer)
Schrift-Name
Schriftgröße
1=bold,0=normal
1=italic,0=normal
1=underlin,0=normal

 

    Beispiel:
Type FButton Extends Control
    public:
    Declare Sub Create(ByVal hParent As HWND, Capt As String,ByVal x As Integer,ByVal y As Integer,ByVal w As Integer,ByVal h As Integer )
    Declare Constructor
    Declare Destructor
    ' Events
    onClick As Sub()
     'Diese Function ist in der Control-Class mit gleichen Namen als VIRTUAL declariert
     'und wird mit diesen Namen in allen Controls als Callback Function verwendet
    Declare  Function CtrlMsgFunc(hWnd As HWND,uMsg as UINT,wParam as wParam,lParam as lParam) as LRESULT
End Type
Constructor FButton
    this.Handle  = 0
    this.ExStyle = 0
    this.Style 	 =  WS_CHILD Or WS_VISIBLE Or BS_PUSHBUTTON Or BS_OWNERDRAW Or WS_TABSTOP
End Constructor

Destructor FButton  ' OK
    this.Handle  = 0
End Destructor

Function FButton.CtrlMsgFunc(hWnd As HWND,uMsg as UINT,wParam as wParam,lParam as lParam) as LRESULT
    Function = 0   
    Select case uMsg
        Case WM_ENABLE
        this.Enabled = wParam
        Exit Function
    
    Case WM_SETFONT,WM_SETTEXT
        If this.Handle Then
        Function = SendMessage(this.Handle,uMsg,wParam,lParam)
        End If
    Exit Function
    
    Case WM_SIZE
        If this.Handle Then
        MoveWindow(this.Handle,0,0,LOWORD(lParam),HiWord(lParam),TRUE)
        End If
    Exit Function
    
    Case WM_COMMAND
        If IsChild( hWnd, Cast(HANDLE, lParam)) Then
            If this.onClick Then
              onClick()
            End If
        Function = 0
        Exit Function
        EndIf
    
    Case WM_DRAWITEM
        Dim As LPDRAWITEMSTRUCT lpdis = Cast(Any Ptr, lParam)
        Dim As HANDLE hCtrl = lpdis->hwndItem
        
        If IsChild(hWnd,hCtrl) Then
        
        Dim hBr As HBRUSH
        
        SetBkColor(lpdis->hDC,this.Color)
        hBr = CreateSolidBrush(this.Color)
        FillRect(lpdis->hDC,@lpdis->rcItem,hBr)
        DeleteObject(hBr)
        
        if lpdis->itemState and ODS_SELECTED  Then
         DrawEdge(lpdis->hDC,@lpdis->rcItem,  EDGE_SUNKEN ,BF_RECT)
        Else
         DrawEdge(lpdis->hDC,@lpdis->rcItem,  EDGE_RAISED ,  BF_RECT )
        End If
        
        SetBkMode(lpdis->hDC,TRANSPARENT)
        If this.Enabled = True Then
         SetTextColor(lpdis->hDC,this.TextColor)
        Else
         SetTextColor(lpdis->hDC,&H808080)
        End If
        DrawText( lpdis->hDC,this.Caption, -1, @lpdis->rcItem, DT_SINGLELINE or DT_CENTER or DT_VCENTER )
        '
        '------------------- Focusrect ---------
        lpdis->rcItem.Left=lpdis->rcItem.Left + 3
        lpdis->rcItem.Top = lpdis->rcItem.Top + 3
        lpdis->rcItem.Right = lpdis->rcItem.Right - 3
        lpdis->rcItem.Bottom=lpdis->rcItem.Bottom - 3
        
        If lpdis->itemState and ODS_FOCUS  Then
          DrawFocusRect(lpdis->hDC,@lpdis->rcItem)
        EndIf
        Function = TRUE
        Exit Function
        End If
    
    End Select
    
    Function = DefWindowProc(hWnd,uMsg,wParam,lParam)
end Function

Sub FButton.Create(ByVal hParent As HWND, Capt As String,ByVal x As Integer,ByVal y As Integer,ByVal w As Integer,ByVal h As Integer )

   Dim As ZString * 32 szClass
   Dim As HINSTANCE hInst

   szClass     = "FB_CONTROL"
   hInst 		= GetModuleHandle(0)
   
   ' Das Containerfenster'
   this.CtHandle = CreateWindowEx( WS_EX_CONTROLPARENT  , @szClass , "", WS_VISIBLE Or WS_CHILD  , x, y, w , h , _
                          hParent , NULL, hInst , NULL )

   SetWindowLong(this.CtHandle ,GWL_USERDATA,CInt(@This)) ' Zeiger diese Instanz

    If this.CtHandle  Then
        this.Left	 = x
        this.Top		 = y
        this.Width 	 = w
        this.Height  = h
        this.Parent  = hParent
    Else
        MessageBox(0,"Fehler - Container Button","Fehler",MB_ICONERROR)
        Exit Sub
    End If
    
   'Das Sichtbare Control'
   this.Handle = CreateWindowEx( NULL , "BUTTON" , Capt, this.Style  ,  0, 0, w, h , this.CtHandle , NULL, hInst , NULL )
   If this.Handle = 0 Then
   	MessageBox(0,"Fehler - Create Button","Fehler",MB_ICONERROR)
   EndIf
   this.Caption = Capt

End Sub