Just put this together in an hour or so but it at least flushes out for me some of the issues concerning this idea I have had for some time, and that is wrapping some Sdk style control creation/interface elements in OOP machinery. I had intended trying it in C++ but now with this really awesome PowerBASIC compiler I tried it first with it. It seems to work as far as that goes. The idea is as follows. With Visual Basic it was really easy to interface with controls on a Form/Dialog. Everything was wrapped in OOP syntax. Also, controls were an application global resource. If you had a textbox on a Form named txtTextBox, it could be addressed from anywhere in the project. If you wanted to put text in it all you had to do was this...
txtTextBox.Text = "Some Text In A Textbox"
Certainly easier than...
Local szBuffer As Asciiz*128
szBuffer="Some Text In A Text Box"
Call SetWindowText(hTextBox,szBuffer)
Well, here is a very rough sketch of what it would look like in PowerBASIC OOP.
I hate the global though. However, that is the only way to so easily do it as in VB. I'll not have globals in my programs so I have to give that some thought. Properties or cbWndExtra bytes in one way or another should work.
txtTextBox.Text = "Some Text In A Textbox"
Certainly easier than...
Local szBuffer As Asciiz*128
szBuffer="Some Text In A Text Box"
Call SetWindowText(hTextBox,szBuffer)
Well, here is a very rough sketch of what it would look like in PowerBASIC OOP.
Code:
'For PowerBASIC Windows 9.0 #Compile Exe #Include "Win32api.inc" %IDC_TEXT1 =1200 Class CEdit Instance dwExStyle As Dword Instance dwStyle As Dword Instance x As Long Instance y As Long Instance dwWidth As Dword Instance dwHeight As Dword Instance hEdit As Dword Instance hParent As Dword Instance hInstance As Dword Instance dwPtr As Dword Ptr Instance Equate As Long Interface IEdit : Inherit IUnknown Property Set Text(Byval strText As String) Local szBuffer As Asciiz*128 szBuffer=strText Call SetWindowText(hEdit,szBuffer) End Property Method CreateWindow(hMain As Dword, iEquate As Dword, hIns As Dword) As Dword dwExStyle=0 dwStyle=%WS_CHILD Or %WS_VISIBLE Or %WS_BORDER x=55 : y=40 dwWidth=210 : dwHeight=25 hParent=hMain : Equate=iEquate hInstance=hIns : dwPtr=0 hEdit=CreateWindowEx(dwExStyle,"edit","",dwStyle,x,y,dwWidth,dwHeight,hMain,iEquate,hInstance,Byval dwPtr) Method=hEdit End Method Method GetWindowHandle(hParent As Dword, iEquate As Dword) As Dword Method=GetDlgItem(hParent,iEquate) End Method End Interface End Class Type WndEventArgs wParam As Long lParam As Long hWnd As Dword hInst As Dword End Type Declare Function FnPtr(wea As WndEventArgs) As Long Type MessageHandler wMessage As Long dwFnPtr As Dword End Type Global MsgHdlr() As MessageHandler Global txtTextBox As IEdit Function fnWndProc_OnCreate(wea As WndEventArgs) As Long Local pCreateStruct As CREATESTRUCT Ptr Local hEdit As Dword pCreateStruct=wea.lParam [email protected] txtTextBox=Class "CEdit" hEdit=txtTextBox.CreateWindow(wea.hWnd,%IDC_TEXT1,wea.hInst) txtTextBox.Text="Compile Without Compromise!" fnWndProc_OnCreate=0 End Function Function fnWndProc_OnNotify(wea As WndEventArgs) As Long fnWndProc_OnNotify=0 End Function Function fnWndProc_OnClose(wea As WndEventArgs) As Long Call PostQuitMessage(0) fnWndProc_OnClose=0 End Function Function fnWndProc(ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As Long) As Long Static wea As WndEventArgs Register iReturn As Long Register i As Long For i=0 To 2 If wMsg=MsgHdlr(i).wMessage Then wea.hWnd=hWnd: wea.wParam=wParam: wea.lParam=lParam Call Dword MsgHdlr(i).dwFnPtr Using FnPtr(wea) To iReturn fnWndProc=iReturn Exit Function End If Next i fnWndProc=DefWindowProc(hWnd,wMsg,wParam,lParam) End Function Sub AttachMessageHandlers() ReDim MsgHdlr(2) As MessageHandler 'Associate Windows Message With Message Handlers MsgHdlr(0).wMessage=%WM_CREATE : MsgHdlr(0).dwFnPtr=CodePtr(fnWndProc_OnCreate) MsgHdlr(1).wMessage=%WM_NOTIFY : MsgHdlr(1).dwFnPtr=CodePtr(fnWndProc_OnNotify) MsgHdlr(2).wMessage=%WM_CLOSE : MsgHdlr(2).dwFnPtr=CodePtr(fnWndProc_OnClose) End Sub Function WinMain(ByVal hIns As Long,ByVal hPrev As Long,ByVal lpCL As Asciiz Ptr,ByVal iShow As Long) As Long Local hWnd As Dword Local winclass As WndClassEx Local szAppName As Asciiz * 16 Local Msg As tagMsg szAppName="Api Classes" Call AttachMessageHandlers() winclass.cbSize=SizeOf(winclass) winclass.style=%CS_HREDRAW Or %CS_VREDRAW winclass.lpfnWndProc=CodePtr(fnWndProc) winclass.cbClsExtra=0 winclass.cbWndExtra=0 winclass.hInstance=hIns winclass.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION) winclass.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW) winclass.hbrBackground=%COLOR_BTNFACE+1 winclass.lpszMenuName=%NULL winclass.lpszClassName=VarPtr(szAppName) RegisterClassEx winclass hWnd=CreateWindow(szAppName,"Edit Class",%WS_OVERLAPPEDWINDOW,200,100,325,200,0,0,hIns,ByVal 0) Call ShowWindow(hWnd,iShow) While GetMessage(Msg,%NULL,0,0) TranslateMessage Msg DispatchMessage Msg Wend Function=msg.wParam End Function
Comment