Below is the complete source for a superclassed control. It modifies the
default behaviour of a standard system button in 3 ways. It sends two
different messages to the parent with mouse UP and mouse DOWN and it will
drag and drop with the right mouse button. This version is implemented
in a DLL but it need not be, the code can be put directly into an EXE
file.
This could not be classed as complex code yet it allows the PowerBASIC
programmer to do something that is different and original. There is no
need to buy or wait for other peoples custom controls when you can "Roll
your own". For vendors who write aftermarket add-ons, this technology is
the basis of producing your own custom control library for your product
range so that it has different and original features.
The Declaration of the DLL function in the calling application.
The message processing code in the calling application to use it.
The complete DLL code for the superclassed control. Make sure you build it
with the name "cbutton.bas" so it matches the declaration.
Regards,
[email protected]
default behaviour of a standard system button in 3 ways. It sends two
different messages to the parent with mouse UP and mouse DOWN and it will
drag and drop with the right mouse button. This version is implemented
in a DLL but it need not be, the code can be put directly into an EXE
file.
This could not be classed as complex code yet it allows the PowerBASIC
programmer to do something that is different and original. There is no
need to buy or wait for other peoples custom controls when you can "Roll
your own". For vendors who write aftermarket add-ons, this technology is
the basis of producing your own custom control library for your product
range so that it has different and original features.
The Declaration of the DLL function in the calling application.
Code:
DECLARE FUNCTION cButton lib "Cbutton.dll" ALIAS "cButton" _ (hParent as LONG, txt$, _ tx as LONG,ty as LONG, _ wd as LONG,ht as LONG, _ align as LONG,ID as LONG) as LONG
Code:
Case %WM_COMMAND Select Case wParam Case 500 Select Case lParam Case 0 SetWindowText hWin,ByCopy "Button Down" Case 1 SetWindowText hWin,ByCopy "Button Up" End Select End Select Case %WM_CREATE hButn1& = cButton(hWin,"Test Button",10,10,100,25,2,500)
with the name "cbutton.bas" so it matches the declaration.
Code:
' ########################################################################### #COMPILE DLL GLOBAL DLLinstance as LONG ' the DLLs instance handle GLOBAL lpButnProc& ' subclass address GLOBAL hButn& ' global handle GLOBAL mFlag as LONG ' button down flag GLOBAL xDn as LONG ' x co-ordinate for WM_MOUSEDOWN GLOBAL yDn as LONG ' y co-ordinate for WM_MOUSEDOWN ' ----------------------------------- ' set correct paths for include files ' ----------------------------------- #INCLUDE "d:\pb6\winapi\win32api.inc" ' ########################################################################### FUNCTION LibMain(BYVAL hInst AS LONG, _ BYVAL Reason AS LONG, _ BYVAL Reserved AS LONG) EXPORT AS LONG LOCAL RetVal as LONG Select Case Reason Case %DLL_PROCESS_ATTACH DLLinstance = hInst ' set global instance global RetVal = 1 ' needed so DLL will start ' ------------------- ' uncomment if needed ' ------------------- ' Case %DLL_PROCESS_DETACH ' Case %DLL_THREAD_ATTACH ' Case %DLL_THREAD_DETACH End Select FUNCTION = RetVal END FUNCTION ' ########################################################################### FUNCTION cButton ALIAS "cButton"(hParent as LONG, txt$, _ tx as LONG,ty as LONG, _ wd as LONG,ht as LONG, _ align as LONG,ID as LONG) EXPORT as LONG ' ----------------------------------------------------- ' hButn1& = cButton(hWin,"Button 1",10,10,100,25,2,500) ' ----------------------------------------------------- Select Case align Case 1 align = %BS_LEFT Case 2 align = %BS_CENTER Case 3 align = %BS_RIGHT End Select hButn& = CreateWindowEx(%WS_EX_LEFT, _ "BUTTON",ByCopy txt$, _ %WS_VISIBLE or %WS_CHILD or align, _ tx,ty,wd,ht, _ hParent,ID,DLLinstance,ByVal %NULL) lpButnProc& =SetWindowLong(hButn&,%GWL_WNDPROC,_ ByVal CodePtr(ButnProc)) FUNCTION = hButn& END FUNCTION ' ########################################################################### FUNCTION ButnProc(BYVAL hCtl as LONG, _ BYVAL Msg as LONG, _ BYVAL wParam as LONG, _ BYVAL lParam as LONG) EXPORT AS LONG LOCAL CtlID as LONG LOCAL hParent as LONG LOCAL xPos as LONG LOCAL yPos as LONG LOCAL hDC as LONG LOCAL bWd as LONG LOCAL bHt as LONG LOCAL Pt as POINTL LOCAL Rct as RECT Select Case Msg Case %WM_LBUTTONDOWN CtlID = GetDlgCtrlID(hCtl) hParent = GetParent(hCtl) Sendmessage hParent,%WM_COMMAND,CtlID,0 Case %WM_LBUTTONUP CtlID = GetDlgCtrlID(hCtl) hParent = GetParent(hCtl) Sendmessage hParent,%WM_COMMAND,CtlID,1 Case %WM_MOUSEMOVE If mFlag = 1 Then ! mov edx, lParam ' put lParam in edx ! mov ax, dx ' put loword of edx in ax ! cwde ' convert it to DWORD ! mov xPos, eax ' copy it to variable ! rol edx, 16 ' rotate edx by 16 bits ! mov ax, dx ' put loword of edx in ax ! cwde ' convert it to DWORD ! mov yPos, eax ' copy it to variable Pt.x = xPos Pt.y = yPos ClientToScreen hCtl, Pt hParent = getParent(hCtl) ScreenToClient hParent, Pt '<< move the window >>-------------------- GetWindowRect hCtl, Rct bWd = Rct.nRight - Rct.nLeft bHt = Rct.nBottom - Rct.nTop MoveWindow hCtl,Pt.x - xDn,Pt.y - yDn,bWd,bHt,%TRUE hDC = GetDC(hCtl) SendMessage hCtl,%WM_PAINT,hDC,0 ReleaseDC hCtl,hDC End If Case %WM_RBUTTONDOWN SetCapture hCtl mFlag = 1 ! mov edx, lParam ' put lParam in edx ! mov ax, dx ' put loword of edx in ax ! cwde ' convert it to DWORD ! mov xDn, eax ' copy it to variable ! rol edx, 16 ' rotate edx by 16 bits ! mov ax, dx ' put loword of edx in ax ! cwde ' convert it to DWORD ! mov yDn, eax ' copy it to variable Case %WM_RBUTTONUP ReleaseCapture mFlag = 0 End Select FUNCTION=CallWindowProc(ByVal lpButnProc&,hCtl,Msg,wParam,lParam) END FUNCTION ' ##########################################################################
[email protected]
Comment