Hi guys,
I post this in the hope other's can learn from it.
This is the way I understand it now.
I post this in the hope other's can learn from it.
This is the way I understand it now.
Code:
FUNCTION WinMain (BYVAL hInstance AS DWORD, _ ' recieves this apllication unique handle BYVAL hPrevInstance AS DWORD, _ ' not used in 32 bits windows always 0 BYVAL lpCmdLine AS ASCIIZ PTR, _ ' pointer to cmdline (gives only the params not path etc) BYVAL nCmdShow AS LONG) AS LONG ' calling proggie can do for example % sw_normal or %sw_minimize LOCAL szAppName AS ASCIIZ * 80 : szAppName = "HelloWin" LOCAL hWnd AS DWORD LOCAL Msg AS tagMsg ' Msg struct for message pump LOCAL wClass AS WndClassEx ' WndClassEx struct wClass.cbSize = SIZEOF(wClass) wClass.style = %CS_HREDRAW OR %CS_VREDRAW ' Redraws whole window if height/width changes or win is moved wClass.lpfnWndProc = CODEPTR(WinProc) ' set the target address for the message pump wClass.cbClsExtra = 0 wClass.cbWndExtra = 0 wClass.hInstance = hInstance wClass.hIcon = LoadIcon(%NULL, BYVAL %IDI_APPLICATION) wClass.hCursor = LoadCursor(%NULL, BYVAL %IDC_ARROW) wClass.hbrBackground = CreateHatchBrush(%HS_CROSS, &H0FFFF11&) ' use this brush for background wClass.lpszMenuName = %NULL wClass.lpszClassName = VARPTR(szAppName) wClass.hIconSm = LoadIcon(%NULL, BYVAL %IDI_APPLICATION) RegisterClassEx wClass ' register our class (wClass) for use with CreateWindowEx hWnd = CreateWindowEx( _ %WS_EX_LEFT, _ ' extended style (now default) szAppName, _ ' window class name "The Hello Program Extra", _ ' window caption %WS_OVERLAPPEDWINDOW, _ ' window style 10, _ ' left position 50, _ ' top position 640, _ ' our window width 400, _ ' our window height %NULL, _ ' parent window handle %NULL, _ ' window menu handle hInstance, _ ' program instance handle BYVAL %NULL) ' creation parameters local hBtn as long hBtn = CreateWindowEx( _ 0, _ "BUTTON", _ "Test", _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _ 100,100,80,25, _ hWnd, _ 100, _ hinstance, _ BYVAL %NULL) hBtn = CreateWindowEx( _ 0, _ "BUTTON", _ "Test2", _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _ 200,100,80,25, _ hWnd, _ 200, _ hinstance, _ BYVAL %NULL) ShowWindow hWnd, %SW_NORMAL ' Show the window with nCmdShow style(s) UpdateWindow hWnd ' Triggers a WM_PAINT DO WHILE GetMessage(Msg, %NULL, 0, 0) > 0 ' Getmessage result can be -1 TranslateMessage Msg DispatchMessage Msg LOOP FUNCTION = msg.wParam END FUNCTION FUNCTION WinProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG LOCAL hDC AS DWORD LOCAL pS AS PAINTSTRUCT LOCAL rct AS RECT SELECT CASE AS LONG wMsg ' use (force) integer testing for messages CASE %WM_CREATE CASE %WM_PAINT hDC = BeginPaint(hWnd, ps) ' set paint struct GetClientRect hWnd, rct ' recieve window left,top, right, bottom coordinates DrawText _ ' hDC, _ ' device context handle "Hello, WindBlows!"+chr$(0), _ ' null terminated string otherwise pointer to string -1, _ ' the textlenght, if -1 then must be a null terminated string rct, _ ' the rectangle to paint in %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER ' singleline centered hor. and vertical EndPaint hWnd, ps FUNCTION = 0 ' tell os that we did handle this msg EXIT FUNCTION CASE %WM_COMMAND SELECT CASE LOWRD(wParam) CASE 100 IF HIWRD(wParam) = %BN_CLICKED THEN MsgBox "Button1 Clicked",,"" FUNCTION=0 END IF CASE 200 IF hiwrd(WpARAM) = %BN_CLICKED THEN MsgBox "Button2 Clicked",,"" FUNCTION=0 END IF END SELECT CASE %WM_DESTROY ' our main window is already gone, clean up here and terminate the msg-pump PostQuitMessage 0 ' this will give our msg-pump a 0 so the while wend stops FUNCTION = 0 EXIT FUNCTION END SELECT FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam) ' not for us so give control to main msg pump END FUNCTION
Comment