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.htmhttp://www.jose.it-berater.org/comctrl/iframe/index2.htmFinally, 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
' ========================================================================================