ErosOlmi
07-02-2012, 09:01
To me it looks interesting
José Roca
07-02-2012, 17:14
I have been working in version III of my headers to allow to be used more easily by DDTers.
Because there were incompatibilities with the PB includes, now if you have existing code written with them, you can compatibilize it with my headers and wrappers by adding %USEPBDECL = 1 before #INCLUDE "Win32Api.inc".
You can use "windows.inc" or "win32api.inc" as you master include file. The new "win32api.inc" just includes "windows.inc" and other additional files for those that hate to use several #INCLUDE statements.
I have began to write some examples to demonstrate how to use my wrappers, classes and controls with DDT. The following one embeds a Google Map in a DDT dialog:
#COMPILE EXE
#DIM ALL
%UNICODE = 1
' // Include files for external files
%USEWEBBROWSER = 1 ' // Use the WebBrowser control
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
' // Identifier
%IDC_WEBBROWSER = 1001
' ########################################################################################
' Main
' ########################################################################################
FUNCTION PBMAIN
' // Create the dialog
LOCAL hDlg AS DWORD
DIALOG NEW PIXELS, 0, "Google Map", , , 700, 500, %WS_OVERLAPPEDWINDOW TO hDlg
' // Create an instance of the class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Build the html script
LOCAL s AS WSTRING
LOCAL cx, cy AS DOUBLE
LOCAL zoom AS LONG
cx = 39.47#
cy = 0.28#
zoom = 7
s = "<!DOCTYPE html>"
s += "<html>"
s += "<head>"
s += "<meta name='viewport' content='initial-scale=1.0, user-scalable=no' />"
s += "<style type='text/css'>" & $CRLF
s += "html { height: 100% }" & $CRLF
s += " body { height: 100%; margin: 0px; padding: 0px }" & $CRLF
s += " #map_canvas { height: 100% }" & $CRLF
s += "</style>" & $CRLF
s += "<script type='text/javascript'" & $CRLF
s += " src='http://maps.google.com/maps/api/js?sensor=false'>" & $CRLF
s += "</script>" & $CRLF
s += "<script type='text/javascript'>" & $CRLF
s += " function initialize() {" & $CRLF
s += " var latlng = new google.maps.LatLng(" & FORMAT$(cx) & "," & FORMAT$(cy) & ");" & $CRLF
s += " var myOptions = {" & $CRLF
s += " zoom: " & FORMAT$(zoom) & "," & $CRLF
s += " center: latlng," & $CRLF
s += " mapTypeId: google.maps.MapTypeId.ROADMAP" & $CRLF
s += " };" & $CRLF
s += " var map = new google.maps.Map(document.getElementById('map_canvas')," & $CRLF
s += " myOptions);" & $CRLF
s += " }" & $CRLF
s += "</script>" & $CRLF
s += "</head>" & $CRLF
s += "<body scroll='no' onload='initialize()'>" & $CRLF
s += " <div id='map_canvas' style='width:100%; height:100%'></div>" & $CRLF
s += "</body>" & $CRLF
s += "</html>" & $CRLF
' // Save the script as a temporary file
LOCAL bstrTempFileName AS WSTRING
bstrTempFileName = AfxSaveTempFile(s, "", "TMP", "html", 1)
' // Create the WebBrowser control with the embedded map
LOCAL nWide, nHigh AS LONG
DIALOG GET CLIENT hDlg TO nWide, nHigh
pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, bstrTempFileName, NOTHING, 0, 0, nWide, nHigh)
' // Display and activate the dialog
DIALOG SHOW MODAL hDlg, CALL DlgProc
END FUNCTION
' ########################################################################################
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG
SELECT CASE CBMSG
CASE %WM_COMMAND
SELECT CASE CB.CTL
' ...
' ...
END SELECT
CASE %WM_SIZE
IF CB.WPARAM <> %SIZE_MINIMIZED THEN
' // Resize the control
LOCAL nWide, nHigh AS LONG
DIALOG GET CLIENT CB.HNDL TO nWide, nHigh
CONTROL SET SIZE CB.HNDL, %IDC_WEBBROWSER, nWide, nHigh
END IF
END SELECT
END FUNCTION
' ========================================================================================
The attached zip file contains the executable generated by the above code.
José Roca
07-02-2012, 17:28
There are many other headers, classes and wrappers that are not GUI related and, therefore, can be used both by DDTers and SDKers in the same way.
For example, I have written a class that wraps the ODBC raw api to allow to use it as easily as ADO, with exception handling and rich error information included.
' ########################################################################################
' Microsoft Windows
' File: CODBCEX_BasicSteps.bas
' Contents: CODBC class example
' Demonstrates the basic steps to use the CODBC class to connect to a database, execute a
' query and fetch the results.
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
' CSED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CODBC.INC"
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
' // Create an instance of the class
LOCAL pOdbc AS IOdbc
pOdbc = NewOdbc(%SQL_OV_ODBC3_80)
IF ISNOTHING(pOdbc) THEN EXIT FUNCTION
TRY
' // Create a connection object
LOCAL pCon AS IOdbcConnection
pCon = pOdbc.Connection("Connection1")
' // Open the database
pCon.OpenDatabase("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=biblio.mdb;UID=;PWD=;")
' // Allocate an statement object
LOCAL pStmt AS IOdbcStatement
pStmt = pCon.Statement("Statement1")
' // Cursor type
pStmt.SetMultiuserKeysetCursor
' // Generate a result set
pStmt.ExecDirect ("SELECT TOP 20 * FROM Authors ORDER BY Author")
' // Parse the result set
LOCAL strOutput AS STRING
DO
' // Fetch the record
IF ISFALSE pStmt.Fetch THEN EXIT DO
' // Get the values of the columns and display them
strOutput = ""
strOutput += pStmt.GetDataString(1) & " "
strOutput += pStmt.GetDataString(2) & " "
strOutput += pStmt.GetDataString(3)
STDOUT strOutput
' // Note: Instead of retrieving the data by ordinal,
' // you can also do it by column name.
' strOutput = ""
' strOutput += pStmt.GetDataString("Au_ID") & " "
' strOutput += pStmt.GetDataString("Author") & " "
' strOutput += pStmt.GetDataString("Year Born")
' STDOUT strOutput
LOOP
CATCH
' // Display error information
STDOUT OdbcOleErrorInfo(OBJRESULT)
WAITKEY$
END TRY
' // Destroy the class
pOdbc = NOTHING
WAITKEY$
END FUNCTION
' ========================================================================================
José Roca
07-02-2012, 18:25
Thanks to the dead code removal feature of the latest compilers, I can extend the language with wrappers and classes as much as I wish without bloating the executable. Also, as I don't have the constraint that everything must work with all versions of Windows, I don't have to wait a decade to use the new technologies. I have code that requires at least XP SP2 or even Windows 7. If you want compatibility with older OSEs, just don't use it.
For example, I have written a class with some 180 methods to work with variants in almost all possible ways, and another to deal with PROPVARIANTs. They require XP SP2 or superior, but can make your life much sweeter if you don't need to support lower versions.
I'm also providing support for recent technologies that require at least Vista/Windows 7, such Direct2D and DirectWrite, and much more.