You will get plenty of useless warnings - you can ignore them (more). The example builds and runs fine with Gas & Gcc in 32- or 64-bit mode.
Code: Select all
#if 0 ' *** simple example how to subclass an edit control ***
This example creates a Windows application with a static and an edit control
The edit control is subclassed and does not accept any char above Ascii 57, i.e. the number 9
The source consists of three major parts:
- Function SubEdit is a callback procedure (added with SetWindowLongPtr) where we decide which keypresses to accept
- Function WndProc is the main window's callback procedure; here, we can handle various events
- Function WinMain does the setup of the main window, and creates the message loop
#endif
#include "windows.bi"
Dim Shared as Handle hEdit, hStatic
Dim Shared as any ptr PreviousWinProc
Function SubEdit(hWnd As HWND, uMsg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
' we ignore all messages and pass them on to Windows via CallWindowProc, with one exception:
' if Windows tells us that it wants to pass a CHAR that we don't like, WE BLOCK IT:
if uMsg=WM_CHAR then ' we are only interested in the WM_CHAR message:
if wParam>57 then
SendMessageW(hStatic, WM_SETTEXT, 0, StrPtr("chars above '9' are not allowed"))
return 0 ' bingo: we do NOT process this message
else
SendMessageW(hStatic, WM_SETTEXT, 0, StrPtr("ok"))
endif
endif
return CallWindowProc(PreviousWinProc, hWnd, uMsg, wParam, lParam) ' perform default processing
End Function
Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
Select Case msg
Case WM_CREATE ' we create two child controls here
hStatic=CreateWindowEx(0, "static", "start typing now...",_
WS_CHILD Or WS_VISIBLE, 0, 0, 1, 1, hWnd, 100, 0, 0)
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE, "edit", 0,_
WS_CHILD Or WS_VISIBLE or ES_MULTILINE, 0, 0, 1, 1, hWnd, 101, 0, 0)
PreviousWinProc=SetWindowLongPtr(hEdit, GWLP_WNDPROC, @SubEdit)
SetFocus(hEdit) ' start typing immediately
Case WM_SIZE ' we adjust the child controls to the main window
Dim As RECT rc
GetClientRect(hWnd, @rc)
MoveWindow(hStatic, 3, 3, rc.right-6, 20, 0)
MoveWindow(hEdit, 3, 23, rc.right-6, rc.bottom-26, 0)
Case WM_DESTROY
PostQuitMessage(0) ' close the main window
End Select
return DefWindowProc(hwnd, msg, wParam, lParam)
End Function
Function WinMain(hInstance As HINSTANCE, hPrevInstance As HINSTANCE, lpCmdLine As LPSTR, nShowCmd As Integer) As Integer
Dim As WNDCLASSEX wc
Dim As MSG msg
Dim As string classname="FbGui"
wc.cbSize = sizeof(WNDCLASSEX)
wc.hbrBackground = COLOR_BTNFACE+1
wc.hCursor = LoadCursor(0, IDC_ARROW)
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION)
wc.hIconSm = wc.hIcon
wc.hInstance = hInstance
wc.lpfnWndProc = @WndProc
wc.lpszClassName = StrPtr(classname)
wc.style = CS_HREDRAW Or CS_VREDRAW
RegisterClassEx(@wc)
if CreateWindowEx(0, wc.lpszClassName, "Simple subclassing example",_
WS_OVERLAPPEDWINDOW Or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) / 2) - 150,_
(GetSystemMetrics(SM_CYSCREEN) / 2) - 100, 300, 200, 0, 0, hInstance, 0)=0 then
MessageBox(0, "Creating hMain failed miserably", 0, MB_OK)
return 0
End If
While GetMessage(@msg, 0, 0, 0)
TranslateMessage(@msg)
DispatchMessage(@msg)
Wend
return msg.wParam
End Function
' ----------- end of functions, the main program starts here: -----------
WinMain(GetModuleHandle(NULL), NULL, COMMAND(), SW_NORMAL)