• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

demo LionBasic Warp

Started by Frank Brübach, October 17, 2009, 12:48:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

#15
good morning,

here first of all the "decimal Calculator" from petzold's "hexCalculator" I have changed correctly :)

I will check other possibilities to make an own sdk window for InputBoxes and Calculations. not doing this one with ddt, so it's boring enough. I was very tired last night. Better to sleep if you are tired to prevent mistakes. I must grinning.

' ========================================================================================
' HEXCALC.BAS
' This program is a translation of HEXCALC.C -- Hexadecimal Calculator
' © Charles Petzold, 1998, described and analysed in Chapter 11 of the book Programming
' Windows, 5th Edition.
' Perhaps the epitome of lazy programming is the HEXCALC program. This program doesn't
' call CreateWindow at all, never processes WM_PAINT messages, never obtains a device
' context, and never processes mouse messages. Yet it manages to incorporate a 10-function
' hexadecimal calculator with a full keyboard and mouse interface in fewer than 150 lines
' of source code.
' ========================================================================================

#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"
#RESOURCE "hexcalc.pbr"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, _
                 BYVAL pszCmdLine AS ASCIIZ PTR, BYVAL iCmdShow AS LONG) AS LONG

  LOCAL szAppName AS ASCIIZ * 256
  LOCAL msg       AS tagMsg
  LOCAL hWnd      AS DWORD
  LOCAL wc        AS WNDCLASS

  szAppName        = "HexCalc"
  wc.style         = %CS_HREDRAW OR %CS_VREDRAW
  wc.lpfnWndProc   = CODEPTR(WndProc)
  wc.cbClsExtra    = 0
  wc.cbWndExtra    = %DLGWINDOWEXTRA    ' // Note!
  wc.hInstance     = hInstance
  wc.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION) '%NULL
  wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
  wc.hbrBackground = %COLOR_BTNFACE + 1
  wc.lpszMenuName  = %NULL
  wc.lpszClassName = VARPTR(szAppName)

  IF ISFALSE RegisterClass(wc) THEN EXIT FUNCTION

  hWnd = CreateDialog (hInstance, szAppName, 0, %NULL)

  ShowWindow hWnd, iCmdShow

  WHILE GetMessage(msg, %NULL, 0, 0)
     TranslateMessage msg
     DispatchMessage msg
  WEND

  FUNCTION = Msg.wParam

END FUNCTION
' ========================================================================================

' ========================================================================================
SUB ShowNumber (BYVAL hWnd AS DWORD, BYVAL iNumber AS DWORD)
  LOCAL szBuffer AS ASCIIZ * 20
  wsprintf szBuffer, "%X", BYVAL iNumber
  SetDlgItemText hWnd, %VK_ESCAPE, szBuffer
  SetDlgItemText hWnd, %VK_ESCAPE, FORMAT$(iNumber) '- HEX$(iNumber)
END SUB
' ========================================================================================

' ========================================================================================
FUNCTION CalcIt (BYVAL iFirstNum AS DWORD, BYVAL iOperation AS LONG, BYVAL iNum AS DWORD) AS DWORD

  SELECT CASE CHR$(iOperation)
    CASE "=": FUNCTION = iNum
    CASE "+": FUNCTION = iFirstNum +  iNum
    CASE "-": FUNCTION = iFirstNum -  iNum
    CASE "*": FUNCTION = iFirstNum *  iNum
    CASE "&": FUNCTION = iFirstNum AND  iNum
    CASE "|": FUNCTION = iFirstNum OR  iNum
    CASE "^": FUNCTION = iFirstNum ^  iNum
    CASE "<": SHIFT LEFT iFirstNum, iNum : FUNCTION = iFirstNum
    CASE ">": SHIFT RIGHT iFirstNum, iNum : FUNCTION = iFirstNum
    CASE "/": FUNCTION = IIF&(iNum = 0, %MAXDWORD, iFirstNum \ iNum)
    CASE "%": FUNCTION = IIF&(iNum = 0, %MAXDWORD, iFirstNum MOD iNum)
    CASE ELSE : FUNCTION = 0
  END SELECT

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main dialog callback.
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL message AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  STATIC bNewNumber AS LONG
  STATIC iOperation AS LONG
  STATIC iNumber    AS DWORD
  STATIC iFirstNum  AS DWORD
  LOCAL  hButton    AS DWORD
  LOCAL  dwTemp     AS DWORD

  SELECT CASE message

     CASE %WM_CREATE
        bNewNumber = %TRUE
        iOperation = ASC("=")
        FUNCTION = 0
        EXIT FUNCTION

     CASE %WM_KEYDOWN                ' left arrow --> backspace
        IF wParam <> %VK_LEFT THEN EXIT FUNCTION
        SendMessage hWnd, %WM_CHAR, %VK_BACK, 0

     CASE %WM_CHAR
        wParam = ASC(UCASE$(CHR$(wParam)))
        IF wParam = %VK_RETURN THEN wParam = ASC("=")
        hButton = GetDlgItem(hWnd, wParam)
        IF hButton THEN
           SendMessage hButton, %BM_SETSTATE, 1, 0
           ApiSleep 100
           SendMessage hButton, %BM_SETSTATE, 0, 0
        ELSE
           MessageBeep 0
        END IF
        SendMessage hWnd, %WM_COMMAND, wParam, 0

     CASE %WM_COMMAND
        SetFocus hWnd
        IF LOWRD(wParam) = %VK_BACK THEN          ' backspace
           iNumber = iNumber \ 16
           ShowNumber hWnd, iNumber
        ELSEIF LOWRD(wParam) = %VK_ESCAPE THEN    ' escape
           iNumber = 0
           ShowNumber hWnd, iNumber
        ELSEIF isxdigit(LOWRD(wParam)) THEN       ' hex digit
           IF bNewNumber THEN
              iFirstNum = iNumber
              iNumber = 0
           END IF
           bNewNumber = %FALSE
           dwTemp = %MAXDWORD
           SHIFT RIGHT dwTemp, 4
           IF iNumber <= dwTemp THEN
              iNumber = 16 * iNumber + wParam - IIF&(isdigit(wParam), ASC("0"), ASC("A") - 10)
              ShowNumber hWnd, iNumber
           ELSE
              MessageBeep 0
           END IF
        ELSE                                      ' operation
           IF ISFALSE bNewNumber THEN
              iNumber = CalcIt (iFirstNum, iOperation, iNumber)
              ShowNumber hWnd, iNumber
           END IF
           bNewNumber = %TRUE
           iOperation = LOWRD(wParam)
        END IF

     CASE %WM_DESTROY
        PostQuitMessage 0
        FUNCTION = 0
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hWnd, message, wParam, lParam)

END FUNCTION
'



zip file and picture below. more to come. I will show new way to include calculations with inputmask for lionBasic Warp next time. I try to open by sdk_window (second picture) a new calculator with inputs and feedback results. - by the way: the big "ddt calculator" is on the road again to work fine as soon as possible. thanks.


frank

Frank Brübach

#16
more than one question ;)

I am trying to make an "cWindow" sdk with popup menu. I have managed this part. but with a normal sdk feature, because I don't know how to use "cWindow" features for popup menus or handling for new properties and buttons or changing values in combo boxes and much more. does anybody has an existing cWindow example they are using this features ?

my "cWindow-popup" example:

' ########################################################################################
' SDK window with gradient.
' ########################################################################################

#DIM ALL
#COMPILE EXE

%USEMACROS = 1                  ' // Use macros
%USERICHEDIT = 1              ' // Use RichEdit
#INCLUDE ONCE "CWindow.inc"     ' // CWindow class
#INCLUDE ONCE "CommCtrl.inc"     ' // CWindow class
#INCLUDE ONCE "winctrl.inc"   ' // Window wrapper functions
#INCLUDE ONCE "richedit.inc"
%IDMonster = 2
%IDCombo = 3
%IDText = 4
%IDScroll = 5
%IDTool = 6
%IDRich = 7
%IDCombobox = 8
'%IDTEXT = 9

' ########################################################################################
' Main
' ########################################################################################
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

  ' // Create an instance of the class
  LOCAL pWindow AS IWindow
  pWindow = CLASS "CWindow"
  IF ISNOTHING(pWindow) THEN EXIT FUNCTION

  ' // Create the main window
  LOCAL hwnd AS DWORD
  hwnd = pWindow.CreateWindow(%NULL, "SDK Window with gradient Effect", %CW_USEDEFAULT, %CW_USEDEFAULT, _
         %CW_USEDEFAULT, %CW_USEDEFAULT, -1, -1, CODEPTR(WindowProc))

  ' // Change the style of the main window class
  SetClassLong hwnd, %GCL_STYLE, %CS_DBLCLKS OR %CS_HREDRAW OR %CS_VREDRAW

  ' // Add two buttons without position or size (they will be resized
  ' // in the WM_SIZE message).
  pWindow.AddButton(hwnd, %IDOK,     "&Ok_Open",   0, 0, 0, 0, -1, -1)
  pWindow.AddButton(hwnd, %IDCANCEL, "&Quit", 0, 0, 0, 0, -1, -1)
  pWindow.AddButton(hwnd, %IDMONSTER, "&Monster", 10, 36, 50, 50, -1, -1)
  pWindow.AddCombobox(hwnd, %IDCombo, "&Combo", 10, 100, 60, 60, -1, -1)
  pWindow.AddToolbar(hwnd, %IDTool, "&Combo", 10, 100, 60, 60, -1, -1)
  pWindow.AddRichEdit(hwnd,%IDRich, "&Write something! RichEdit, pherhaps here could read some day the whole story of the 'Lords of the Rings' adventures!", 340,410,120,80,-1,-1)
  pWindow.AddTextbox(hwnd, %IDText, "&Info:Text", 10, 140, 40, 40, -1, -1)
  pWindow.AddVScrollBar(hwnd, %IDScroll, "&ToolBar", 20, 400, 40, 120, -1, -1)
  pWindow.AddVScrollBar(hwnd, %IDScroll, "&ToolBar", 70, 400, 40, 120, -1, -1)

  ' // Force the resizing of the buttons by sending a WM_SIZE message
  SendMessage hwnd, %WM_SIZE, 0, 0

  ' // Default message pump (you can replace it with your own)
  pWindow.DoEvents

END FUNCTION
' ########################################################################################

' ========================================================================================
' Gradient fill procedure
' ========================================================================================
SUB DrawGradient (BYVAL hDC AS DWORD)

  LOCAL rectFill   AS RECT
  LOCAL rectClient AS RECT
  LOCAL fStep      AS SINGLE
  LOCAL hBrush     AS DWORD
  LOCAL lOnBand    AS LONG

  GetClientRect WindowFromDC(hDC), rectClient
  fStep = rectClient.nbottom / 200

  FOR lOnBand = 0 TO 199
     SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
     hBrush = CreateSolidBrush(RGB(100, 0, (255 - lOnBand)))
     FillRect hDC, rectFill, hBrush
     DeleteObject hBrush
  NEXT

END SUB
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  LOCAL hDC AS DWORD
  LOCAL pPaint AS PAINTSTRUCT
  LOCAL rc AS RECT

  SELECT CASE uMsg

     CASE %WM_COMMAND
        SELECT CASE LO(WORD, wParam)
           CASE %IDCANCEL
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 SendMessage hwnd, %WM_CLOSE, 0, 0
                 EXIT FUNCTION
              END IF

        CASE %IDOK
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 ShowPopupDialog hwnd
              END IF

        END SELECT



     CASE %WM_PAINT
        hDC = BeginPaint(hwnd, pPaint)
        GetClientRect hwnd, rc
        SetBkMode hDC, %TRANSPARENT
        SetTextColor hDC, %WHITE
        DrawText hDC, "Hello, my funny and exciting cWindows!", -1, rc, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
        EndPaint hwnd, pPaint
        FUNCTION = %TRUE
        EXIT FUNCTION

     CASE %IDMonster
         MSGBOX "more to come as soon as possible", %MB_ICONINFORMATION, "Info: Cwindow says Yep!"

     CASE %WM_ERASEBKGND
        hDC = wParam
        DrawGradient hDC
        FUNCTION = %TRUE
        EXIT FUNCTION

     CASE %WM_SIZE
        IF wParam <> %SIZE_MINIMIZED THEN
           GetClientRect hwnd, rc
           MoveWindow GetDlgItem(hwnd, %IDMonster), (rc.nRight - rc.nLeft) - 425, (rc.nBottom - rc.nTop) - 55, 55, 55, %TRUE '35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDOK), (rc.nRight - rc.nLeft) - 185, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDCANCEL), (rc.nRight - rc.nLeft) - 95, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE

        END IF

     CASE %WM_DESTROY
        PostQuitMessage 0
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Popup dialog procedure
' ========================================================================================
FUNCTION PopupDlgProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  SELECT CASE wMsg
     CASE %WM_CREATE
        EnableWindow GetWindow(hWnd, %GW_OWNER), %FALSE   ' To make the popup dialog modal

     CASE %WM_COMMAND
        SELECT CASE LO(WORD, wParam)
           CASE %IDCANCEL
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 SendMessage hWnd, %WM_CLOSE, 0, 0
                 EXIT FUNCTION
              END IF
        END SELECT

     CASE %WM_CLOSE
        EnableWindow GetWindow(hWnd, %GW_OWNER), %TRUE  ' Maintains parent's zorder

     CASE %WM_DESTROY
        PostQuitMessage 0                ' This function closes the main window
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Popup dialog - Calling example: ShowPopupDialog hWnd
' ========================================================================================
FUNCTION ShowPopupDialog (BYVAL hParent AS LONG) AS LONG

  LOCAL hWndPopup   AS LONG
  LOCAL hCtl        AS LONG
  LOCAL hFont       AS LONG
  LOCAL rc          AS RECT
  LOCAL wcex        AS WNDCLASSEX
  LOCAL szClassName AS ASCIIZ * 80
  LOCAL szCaption   AS ASCIIZ * 255
  LOCAL hInstance   AS DWORD

  hFont = GetStockObject(%ANSI_VAR_FONT)

  szClassName        = "MyPopupClassName"
  wcex.cbSize        = SIZEOF(wcex)
  wcex.style         = %CS_HREDRAW OR %CS_VREDRAW
  wcex.lpfnWndProc   = CODEPTR(PopupDlgProc)
  wcex.cbClsExtra    = 0
  wcex.cbWndExtra    = 0
  wcex.hInstance     = GetModuleHandle("")
  wcex.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
  wcex.hbrBackground = %COLOR_3DFACE + 1
  wcex.lpszMenuName  = %NULL
  wcex.lpszClassName = VARPTR(szClassName)
  wcex.hIcon         = 0
  wcex.hIconSm       = 0
  RegisterClassEx wcex

  GetWindowRect hParent, rc          ' For centering child in parent
  rc.nRight = rc.nRight - rc.nLeft   ' Parent's width
  rc.nBottom = rc.nBottom - rc.nTop  ' Parent's height

  szCaption = "Popup dialog with SDK"
  hWndPopup = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT, _
              szClassName, szCaption, %WS_CAPTION OR %WS_POPUPWINDOW OR %WS_VISIBLE OR %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN, _
              rc.nLeft + (rc.nRight - 290) / 2, _
              rc.nTop + (rc.nBottom - 180) / 2, _
              340, 180, hParent, 0, GetModuleHandle(""), BYVAL %NULL)

  hCtl = CreateWindowEx(0, "BUTTON", "&Close", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
              200, 118, 75, 23, hWndPopup, %IDCANCEL, hInstance, BYVAL %NULL)
  hCtl = CreateWindowEx(0, "BUTTON", "&Monster", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
              60, 118, 75, 23, hWndPopup, %IDOK, hInstance, BYVAL %NULL)
  hCtl = CreateWindowEx(0, "Combobox", "&TEXT", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
              80, 80, 125, 25, hWndPopup, %IDCombobox, hInstance, BYVAL %NULL)
  hCtl = CreateWindowEx(0, "Combobox", "&type in", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
              80, 40, 100, 25, hWndPopup, %IDTEXT, hInstance, BYVAL %NULL)

  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  ShowWindow hWndPopup, %SW_SHOW
  UpdateWindow hWndPopup
  ' Message handler loop
  LOCAL uMsg AS tagMsg
  WHILE GetMessage(uMsg, %NULL, 0, 0)
     IF ISFALSE IsDialogMessage(hWndPopup, uMsg) THEN
        TranslateMessage uMsg
        DispatchMessage uMsg
     END IF
  WEND

  FUNCTION = uMsg.wParam

END FUNCTION
' =================================


my idea was to make some new feature for LionBasic Warp (via Menus) to open new sdk windows or cWindows with more functions and possibilities for sdk handling. the popup window in this example should be help to make some day "user inputs" for values and calculate something. !? ;)

nice day, frank

José Roca

 
Do not use low numbers for the identifiers, such %IDMonster = 2, %IDCombo = 3 because these numbers are used by Windows for its own identifiers, and if you click the monster button having assigned to it a value of 2 you will receive an %IDCANCEL message.

Do not use the same identifier for different controls or you will be unable to ascertain which one has been clicked.

Do not try to process control messages putting the CASE xxx anywhere. Control and menu items must be processed under the %WM_COMMAND message. CASE %IDMonster is misplaced.

Adding scrollbars isn't going to make your dialog scrollable. Size the dialog according your needs.

The CWindow class has been designed to just make easier to create dialogs and add controls with less verbosity, i.e. without having to create a class first, and with a simplified syntax. But it has not properties for each control ala Visual Basic because this will require a very big amount of code and will bloat the size of the program.

My headers contain wrapper functions to handle all the messages of all the common controls.

AnimateCtrl.inc (Animation control)
ButtonCtrl.inc (Button control)
ComboBoxCtrl.inc (ComboBox control)
ComboBoxExCtrl.inc (ComboBoxEx control)
DateTimeCtrl.inc (Date Time control)
EditCtrl.inc (Edit control)
HeaderCtrl.inc (Header control)
HotKeyCtrl.inc (Hot Key control)
IPAddressCtrl.inc (IP Address control)
ListBoxCtrl.inc (ListBox control)
ListViewCtrl.inc (ListView control)
MonthCalCtrl.inc (Month Calendar control)
PagerCtrl.inc (Pager control)
ProgressBarCtrl.inc (Progress Bar control)
RebarCtrl.inc (Rebar control)
RichEditCtrl.inc (Rich Edit control)
ScrollBarCtrl.inc (Scroll Bar control)
StaticCtrl.inc (Static control)
StatusbarCtrl.inc (Status Bar control)
SysLinkCtrl.inc (SysLink control)
TabCtrl.inc (Tab control)
TaskDialogCtrl.inc (Task Dialog control)
ToolbarCtrl.inc (Toolbar control)
TrackbarCtrl.inc (Track Bar control)
TreeViewCtrl.inc (TreeView control)
UpDownCtrl.inc (UpDown control)

They are documented in my reference guides for them:

http://www.jose.it-berater.org/comctrl/iframe/index1.htm
http://www.jose.it-berater.org/comctrl/iframe/index2.htm

Finally, there is a modified version of your test program:


' ########################################################################################
' SDK window with gradient.
' ########################################################################################

#DIM ALL
#COMPILE EXE

%USEMACROS = 1                  ' // Use macros
%USERICHEDIT = 1              ' // Use RichEdit
#INCLUDE ONCE "CWindow.inc"     ' // CWindow class
#INCLUDE ONCE "CommCtrl.inc"     ' // Common controls
#INCLUDE ONCE "winctrl.inc"   ' // Window wrapper functions
#INCLUDE ONCE "richedit.inc"
%IDMonster = 1001
%IDCombo = 1002
%IDText = 1003
%IDScroll = 1004
%IDTool = 1005
%IDRich = 1006
%IDCombobox = 1007
'%IDTEXT = 1008

' ########################################################################################
' Main
' ########################################################################################
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

  ' // Create an instance of the class
  LOCAL pWindow AS IWindow
  pWindow = CLASS "CWindow"
  IF ISNOTHING(pWindow) THEN EXIT FUNCTION

  ' // Create the main window
  LOCAL hwnd AS DWORD
  hwnd = pWindow.CreateWindow(%NULL, "SDK Window with gradient Effect", 0, 0, _
         500, 400, -1, -1, CODEPTR(WindowProc))

  ' // Change the style of the main window class
  SetClassLong hwnd, %GCL_STYLE, %CS_DBLCLKS OR %CS_HREDRAW OR %CS_VREDRAW

  ' // Add two buttons without position or size (they will be resized
  ' // in the WM_SIZE message).
  pWindow.AddButton(hwnd, %IDOK,     "&Ok_Open",   0, 0, 0, 0, -1, -1)
  pWindow.AddButton(hwnd, %IDCANCEL, "&Quit", 0, 0, 0, 0, -1, -1)
  pWindow.AddButton(hwnd, %IDMONSTER, "&Monster", 10, 36, 50, 50, -1, -1)
  pWindow.AddCombobox(hwnd, %IDCombo, "&Combo", 10, 100, 60, 60, -1, -1)
  pWindow.AddToolbar(hwnd, %IDTool, "", 10, 100, 60, 60, -1, -1)
  pWindow.AddRichEdit(hwnd,%IDRich, "Write something! RichEdit, pherhaps here could read some day the whole story of the 'Lords of the Rings' adventures!", 10,250,120,80,-1,-1)
  pWindow.AddTextbox(hwnd, %IDText, "", 10, 140, 40, 40, -1, -1)

  ' // Force the resizing of the buttons by sending a WM_SIZE message
  SendMessage hwnd, %WM_SIZE, 0, 0

  ' // Default message pump (you can replace it with your own)
  pWindow.DoEvents

END FUNCTION
' ########################################################################################

' ========================================================================================
' Gradient fill procedure
' ========================================================================================
SUB DrawGradient (BYVAL hDC AS DWORD)

  LOCAL rectFill   AS RECT
  LOCAL rectClient AS RECT
  LOCAL fStep      AS SINGLE
  LOCAL hBrush     AS DWORD
  LOCAL lOnBand    AS LONG

  GetClientRect WindowFromDC(hDC), rectClient
  fStep = rectClient.nbottom / 200

  FOR lOnBand = 0 TO 199
     SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
     hBrush = CreateSolidBrush(RGB(100, 0, (255 - lOnBand)))
     FillRect hDC, rectFill, hBrush
     DeleteObject hBrush
  NEXT

END SUB
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  LOCAL hDC AS DWORD
  LOCAL pPaint AS PAINTSTRUCT
  LOCAL rc AS RECT

  SELECT CASE uMsg

     CASE %WM_COMMAND
        SELECT CASE LO(WORD, wParam)
           CASE %IDCANCEL
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 SendMessage hwnd, %WM_CLOSE, 0, 0
                 EXIT FUNCTION
              END IF

           CASE %IDOK
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 ShowPopupDialog hwnd
              END IF

           CASE %IDMonster
              MSGBOX "more to come as soon as possible", %MB_ICONINFORMATION, "Info: Cwindow says Yep!"

        END SELECT

     CASE %WM_PAINT
        hDC = BeginPaint(hwnd, pPaint)
        GetClientRect hwnd, rc
        SetBkMode hDC, %TRANSPARENT
        SetTextColor hDC, %WHITE
        DrawText hDC, "Hello, my funny and exciting cWindows!", -1, rc, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
        EndPaint hwnd, pPaint
        FUNCTION = %TRUE
        EXIT FUNCTION

     CASE %WM_ERASEBKGND
        hDC = wParam
        DrawGradient hDC
        FUNCTION = %TRUE
        EXIT FUNCTION

     CASE %WM_SIZE

        ' Resize the toolbar
        SendMessage GetDlgItem(hwnd, %IDTool), uMsg, wParam, lParam

        IF wParam <> %SIZE_MINIMIZED THEN
           GetClientRect hwnd, rc
           MoveWindow GetDlgItem(hwnd, %IDMonster), 10, 40, 55, 55, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDOK), (rc.nRight - rc.nLeft) - 185, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDCANCEL), (rc.nRight - rc.nLeft) - 95, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
        END IF

     CASE %WM_DESTROY
        PostQuitMessage 0
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Popup dialog procedure
' ========================================================================================
FUNCTION PopupDlgProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  SELECT CASE wMsg
     CASE %WM_CREATE
        EnableWindow GetWindow(hWnd, %GW_OWNER), %FALSE   ' To make the popup dialog modal

     CASE %WM_COMMAND
        SELECT CASE LO(WORD, wParam)
           CASE %IDCANCEL
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 SendMessage hWnd, %WM_CLOSE, 0, 0
                 EXIT FUNCTION
              END IF
        END SELECT

     CASE %WM_CLOSE
        EnableWindow GetWindow(hWnd, %GW_OWNER), %TRUE  ' Maintains parent's zorder

     CASE %WM_DESTROY
        PostQuitMessage 0                ' This function closes the main window
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Popup dialog - Calling example: ShowPopupDialog hWnd
' ========================================================================================
SUB ShowPopupDialog (BYVAL hParent AS LONG)

  ' // Create an instance of the class
  LOCAL pPopup AS IWindow
  pPopup = CLASS "CWindow"
  IF ISNOTHING(pPopup) THEN EXIT SUB

  ' // Create the main window
  LOCAL hwnd AS DWORD
  hwnd = pPopup.CreateWindow(hParent, "Popup dialog with CWindow", 0, 0, 320, 200, -1, -1, CODEPTR(PopupDlgProc))


  ' // Add a close button
  pPopup.AddButton(hwnd, %IDCANCEL, "&Close", 200, 118, 75, 23, -1, -1)
  pPopup.AddButton(hwnd, %IDOK, "&Monster", 60, 118, 75, 23, -1, -1)
  pPopup.AddCombobox(hwnd, %IDCombobox, "", 80, 80, 125, 25, -1, -1)
  pPopup.AddCombobox(hwnd, %IDTEXT, "", 80, 40, 100, 25, -1, -1)

  ' // Default message pump (you can replace it with your own)
  pPopup.DoEvents

  ' // Enable the parent window
  EnableWindow hParent, %TRUE

END SUB
' ========================================================================================