$Include "Rapidq.inc"

'''Api decl
Const DT_TOP = &H0
Const DT_LEFT = &H0
Const DT_CENTER = &H1
Const DT_RIGHT = &H2
Const DT_VCENTER = &H4
Const DT_BOTTOM = &H8
Const DT_WORDBREAK = &H10
Const DT_SINGLELINE = &H20
Const DT_EXPANDTABS = &H40
Const DT_TABSTOP = &H80
Const DT_NOCLIP = &H100
Const DT_EXTERNALLEADING = &H200
Const DT_CALCRECT = &H400
Const DT_NOPREFIX = &H800
Const DT_INTERNAL = &H1000

Const EM_GETFIRSTVISIBLELINE = &HCE
Const EM_GETLINECOUNT = &HBA
Const EM_GETRECT = &HB2
Const EM_SETRECT = &HB3

Const WM_PAINT = &HF
Const GWL_WNDPROC = (-4)

Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_RBUTTONDOWN = &H204
Const WM_LBUTTONDBLCLK = &H203

Const DST_BITMAP = &H4
Const DSS_NORMAL = &H0

Const OPAQUE = 2
Const TRANSPARENT = 1

Const RDW_ERASE = &H4
Const RDW_INVALIDATE = &H1

Const PATCOPY = &HF00021
Const IMAGE_BITMAP = 0

Const LR_LOADFROMFILE = &H10
Const LR_LOADMAP3DCOLORS = &H1000
Const LR_LOADTRANSPARENT = &H20

Const PS_SOLID = 0

Type Size
        cx As Long
        cy As Long
End Type

Type POINTAPI
        x As Long
        y As Long
End Type

Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Function LoWord(Value As Long) As Integer
   If (Value And &H8000) = 0 Then
      Result = Value And &HFFFF
   Else
      Result = Value Or &HFFFF0000
   End If
End Function

Function HiWord(Value As Long) As Integer
   Result = (Value And &HFFFF0000) \ &H10000
End Function

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function SendMessageA Lib "user32" Alias "SendMessageA" (hwnd As Long, wMsg As Long, wParam As Long, lParam As Long) As Long
Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long) As Long
Declare Function SetBkColor Lib "gdi32" Alias "SetBkColor" (ByVal hdc As Long, ByVal crColor As Long) As Long
Declare Function SetBkMode Lib "gdi32" Alias "SetBkMode" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Declare Function SetTextColor Lib "gdi32" Alias "SetTextColor" (ByVal hdc As Long, ByVal crColor As Long) As Long
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE) As Long
Declare Function CreatePen Lib "gdi32" Alias "CreatePen" (ByVal nPenStyle As Long, ByVal nWidth As Long,ByVal crColor As Long) As Long
Declare Function CreateSolidBrush Lib "gdi32" Alias "CreateSolidBrush" (ByVal crColor As Long) As Long
Declare Function FillRect Lib "user32" Alias "FillRect" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Declare Function LineTo Lib "gdi32" Alias "LineTo" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Declare Function GetSysColor Lib "user32" Alias "GetSysColor" (ByVal nIndex As Long) As Long
Declare Function DrawState Lib "user32" Alias "DrawStateA" (ByVal hDC As Long, ByVal hBrush As Long, ByVal lpDrawStateProc As Long, ByVal lParam As Long, ByVal wParam As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal un As Long) As Long
Declare Function RedrawWindow Lib "user32" Alias "RedrawWindow" (ByVal hwnd As Long, lprcUpdate As RECT,ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hdc As Long) As Long
Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Declare Function StretchBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nWidthSrc As Long, ByVal nHeightSrc As Long,ByVal dwRop As Long) As Long
Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Long) As Long
Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String,ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Declare Function UpdateWindow Lib "user32" Alias "UpdateWindow" (ByVal hwnd As Long) As Long
Declare Function InvalidateRect Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long

'''Main
Deflng OldProc

Declare Function ButtonProc(hWnd As Long,Msg As Long,wParam As Long,lParam As Long,Sender As QButton) As Long
Declare Sub MainFormShow(Sender as QForm)
Create MainForm as QForm
      Caption = "MainForm"
      Top     = 131
      Left    = 217
      Width   = 232
      Height  = 121
      OnShow = MainFormShow
End Create
Create Button as QButton
      Parent  = MainForm
      Top     = 24
      Left    = 64
      Width   = 75
      Height  = 25
      Caption = ""
      Font.Name = "MS Sans Serif"
      Font.Color = 0
      Font.Size = 8
      Font.AddStyles  fsBold
      Tag = &H00FF00
End Create
'$Include "Minimize.inc"


'SetMinimize(MainForm)
MainForm.ShowModal


Function ButtonProc(hWnd As Long,Msg As Long,wParam As Long,lParam As Long,Sender As QButton) As Long
   Defint X,Y
   Dim rc As RECT
   Dim PT As POINTAPI
   Deflng hDC, OldObject, Brush
   Defstr Buffer
   Dim Siz As Size
   
   If Msg = WM_PAINT then
      CallWindowProc(OldProc, hWnd, Msg, wParam, lParam)
      hDC = GetDC(Sender.Handle)
      Brush = CreateSolidBrush(Sender.Tag)
      GetClientRect(Sender.Handle, rc)
      Rc.Top = Rc.Top + 2
      Rc.Bottom = Rc.Bottom -3
      Rc.Left = Rc.Left + 2
      Rc.Right = Rc.Right -2
      FillRect(hDC, rc, Brush)
      ReleaseDC(Sender.Handle, hDC)
      DeleteObject(Brush)
      Result = 0
   End If
   
   If Msg = WM_LBUTTONDOWN OR Msg = WM_LBUTTONUP OR Msg = WM_LBUTTONDBLCLK then InvalidateRect(Button.Handle,0,1)
   
   Result = CallWindowProc(OldProc,hWnd,Msg,wParam,lParam)
End Sub
 
Sub MainFormShow(Sender as QForm)
    OldProc = SetWindowLong(Button.Handle,GWL_WNDPROC,CodePTR(ButtonProc))
End Sub

