IT-Consultant: José Roca (PBWIN 10+/PBCC 6+) (Archive only) > Windows API Headers
Using API Headers
José Roca:
--- Quote ---I can see, however, why Jose has the "win32api.inc" stub file - to prevent the need to change code when using different includes. In my case, I'm happy to have that constriction in order to clarify for myself which includes I used to develop/test the code.
--- End quote ---
Yes, that is the purpose, but be aware that the PB includes also have a file called windows.inc, so there is no problem if you don't change it. However, using your own you can add additional include files of you interest. My headers have two main include files, windows.inc, that provides the main functionality for the classical windows api, and ole2.inc, that provides the main functionality to work with COM.
The wrappers for the common controls are in separated files, not in commctrl.inc, because they contain many hundreds of functions.
AnimateCtrl.inc (Animation control)
ButtonCtrl.inc (Button control)
ComboBoxCtrl.inc (ComboBox control)
ComboBoxExCtrl.inc (ComboBoxEx control)
DateTimeCtrl.inc (Date Time control)
EditCtrl.inc (Edit control)
HeaderCtrl.inc (Header control)
HotKeyCtrl.inc (Hot Key control)
IPAddressCtrl.inc (IP Address control)
ListBoxCtrl.inc (ListBox control)
ListViewCtrl.inc (ListView control)
MonthCalCtrl.inc (Month Calendar control)
PagerCtrl.inc (Pager control)
ProgressBarCtrl.inc (Progress Bar control)
RebarCtrl.inc (Rebar control)
RichEditCtrl.inc (Rich Edit control)
ScrollBarCtrl.inc (Scroll Bar control)
StaticCtrl.inc (Static control)
StatusbarCtrl.inc (Status Bar control)
SysLinkCtrl.inc (SysLink control)
TabCtrl.inc (Tab control)
TaskDialogCtrl.inc (Task Dialog control)
ToolbarCtrl.inc (Toolbar control)
TrackbarCtrl.inc (Track Bar control)
TreeViewCtrl.inc (TreeView control)
UpDownCtrl.inc (UpDown control)
So, you may need to use #INCLUDE a bit more often that with the PB includes, but in turn you get faster compile times, and the current users of my headers are always counting bytes and milliseconds.
There are other main files for different technologies, such ADO.INC, for ADO support, ODBC.INC, for ODBC support, OPENGL, for OpenGL support, WMI..inc, for WMI support, etc. There are also classes such CODBC to use ODBC as easily as ADO, with a dotted syntax and exception handling, CGDIPLUS.INC, to allow to use GDI+ with a syntax similar to the one used by C++ programmers, there are graphic and image controls, an OLE container, and much more.
--- Quote ---If so, then the correct approach seems to be to place only 1 path in the PBEdit settings, and completely replace it if I want to use the other set of includes.
Is this correct?
--- End quote ---
Yes, it is. In the introduction of the the post that has the attachment with the includes, it says:
--- Quote ---You must also be aware that these headers are not extensions to the ones provided with the compiler, but a full replacement. Therefore, you must not mix them with the PowerBASIC include files in any way, neither directly (via #INCLUDE), nor indirectly (via the include path in the IDE).
Unzip the attached file to a folder of your choice and replace the PB Include path in the PB Ide or the editor that you are using to that folder instead of C:\PBWin10\WinApi.
--- End quote ---
You can have more folders, e.g. MyIncludes, as long as they're compatible with my headers. I use one of these for my translations of the headers of third party libraries.
I have no problems changing it because in the CSED editor I added four text boxes for the include's paths, and can quickly switch between them choosing the option with the dropdow menu of one of the toolbar buttons. The editor also comes with many templates. These are compatible with the PB IDE and you only need to copy them in the bin folder of the PB editor to access them. Just don't overwrite three or four that have the same name, such Default.pbtpl.
I have already modified some 150 files to allow them to be used with existing code that uses the PB includes. It remains 50 of them and then the worst part: to test them with existing code. I will test with my hundreds of examples to check that I haven't broken anything in the process and then I will try the PB10 examples and some of the latest posts in the PB forum that use the PB 10 includes. The purpose is to allow PBer's to use my headers with his existing PB10 code without having to make changes, or at least as less as possible.
José Roca:
This example demonstrates how to use the GDI+ raw api with a DDT graphic control.
--- Code: ---' ########################################################################################
' Microsoft Windows
' File: EX_DDT_GDIP_DrawLine_02.bas
' Contents: GDI+ example
' This version uses a DDT graphic control
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers 2.0+
' Copyright (c) 2012 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.
' ########################################################################################
' SED_PBWIN
#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"
%IDC_GRAPHIC = 101
' ========================================================================================
' The following example draws a line.
' ========================================================================================
SUB GDIP_DrawLine (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
' // Create a graphics object
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a Pen
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitPixel, pPen)
' // Draw the line
GdipDrawLine pGraphics, pPen, 0, 0, 200, 100
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
LOCAL hr AS LONG
LOCAL hDlg AS DWORD
LOCAL hdc AS DWORD
' // Initialize GDI+
LOCAL GdipToken AS DWORD
GdipToken = GdiPlusInit
' // Create the dialog
DIALOG NEW PIXELS, 0, "GdipDrawLine", , , 400, 250, %WS_SYSMENU TO hDlg
' // Add a graphic control
CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC,"", 0, 0, 400, 250
' // Select the drawing target
GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
' // Set the foreground and background colors
GRAPHIC COLOR %BLACK, %WHITE
' // Clear the entire selected graphic window
GRAPHIC CLEAR
' // Retrieve the handle of the device context
GRAPHIC GET DC TO hdc
' // Draw the graphics
GDIP_DrawLine hdc
' // Display and activate the dialog
DIALOG SHOW MODAL hDlg, CALL DlgProc
' // Shutdown GDI+
GdiplusShutdown GdipToken
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG
SELECT CASE CBMSG
CASE %WM_COMMAND
SELECT CASE CB.CTL
' ...
' ...
END SELECT
END SELECT
END FUNCTION
' ========================================================================================
--- End code ---
And this one using a DDT control and the CGDIPLUS class. Look at the code in the SUB GDIP_DrawLine to see the syntax differences.
--- Code: ---' ########################################################################################
' Microsoft Windows
' File: EX_DDT_CGDIP_DrawLine.bas
' Contents: GDI+ example
' This version uses a DDT graphic control
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers 2.0+
' Copyright (c) 2012 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.
' ########################################################################################
' SED_PBWIN
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CGdiPlus.inc" ' // CGdiPlus class
%IDC_GRAPHIC = 101
' ========================================================================================
' The following example draws a line.
' ========================================================================================
SUB GDIP_DrawLine (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)
LOCAL graphics AS IGdipGraphics
graphics = pGdip.Graphics(hdc)
' // Create a Pen object
LOCAL redPen AS IGdipPen
redPen = pGdip.Pen(pGdip.Color(255, 255, 0, 0))
' // Draw the line
graphics.DrawLine(redPen, 0, 0, 200, 100)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
LOCAL hr AS LONG
LOCAL hDlg AS DWORD
LOCAL hdc AS DWORD
' // Create the dialog
DIALOG NEW PIXELS, 0, "GdipDrawLine", , , 400, 250, %WS_SYSMENU TO hDlg
' // Add a graphic control
CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC,"", 0, 0, 400, 250
' // Select the drawing target
GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
' // Set the foreground and background colors
GRAPHIC COLOR %BLACK, %WHITE
' // Clear the entire selected graphic window
GRAPHIC CLEAR
' // Retrieve the handle of the device context
GRAPHIC GET DC TO hdc
' // Create an instance of the GdiPlus class
LOCAL pGdip AS IGdiPlus
pGdip = NewGdiPlus
' // Draw the graphics
GDIP_DrawLine pGdip, hdc
' // 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
END SELECT
END FUNCTION
' ========================================================================================
--- End code ---
José Roca:
This one uses the GDI+ raw api and pure SDK code:
--- Code: ---#COMPILE EXE
#DIM ALL
%UNICODE = 1
' // Header files for imported files
#INCLUDE ONCE "GDIPLUS.INC" ' // GDI+
#INCLUDE ONCE "GraphCtx.INC" ' // Graphic control
#INCLUDE ONCE "AfxWin.inc" ' // Window wrappers
%IDC_GRCTX = 101
' ========================================================================================
' The following sample code draws a line.
' Change it with your own code.
' ========================================================================================
SUB GDIP_DrawLine (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a Pen
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitPixel, pPen)
' // Draw the line
GdipDrawLineI pGraphics, pPen, 0, 0, 200, 100
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
LOCAL hwndMain AS DWORD
LOCAL wcex AS WNDCLASSEX
#IF %DEF(%UNICODE)
LOCAL szClassName AS WSTRINGZ * 80
LOCAL szCaption AS WSTRINGZ * 255
#ELSE
LOCAL szClassName AS ASCIIZ * 80
LOCAL szCaption AS ASCIIZ * 255
#ENDIF
' // Initialize GDI+
LOCAL GdipToken AS DWORD
GdipToken = GdiPlusInit
' // Register the window class
szClassName = "MyClassName"
wcex.cbSize = SIZEOF(wcex)
wcex.style = %CS_HREDRAW OR %CS_VREDRAW
wcex.lpfnWndProc = CODEPTR(WndProc)
wcex.cbClsExtra = 0
wcex.cbWndExtra = 0
wcex.hInstance = hInstance
wcex.hCursor = LoadCursor (%NULL, BYVAL %IDC_ARROW)
wcex.hbrBackground = GetStockObject(%WHITE_BRUSH)
wcex.lpszMenuName = %NULL
wcex.lpszClassName = VARPTR(szClassName)
wcex.hIcon = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' // Sample, if resource icon: LoadIcon(hInst, "APPICON")
wcex.hIconSm = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' // Remember to set small icon too..
RegisterClassEx wcex
' // Window caption
szCaption = "GdipDrawLine"
' Create a window using the registered class
hwndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _ ' extended style
szClassName, _ ' window class name
szCaption, _ ' window caption
%WS_OVERLAPPEDWINDOW OR _
%WS_CLIPCHILDREN, _ ' window style
0, _ ' initial x position
0, _ ' initial y position
400, _ ' initial x nSize
300, _ ' initial y nSize
%NULL, _ ' parent window handle
0, _ ' window menu handle
hInstance, _ ' program instance handle
BYVAL %NULL) ' creation parameters
' // Center the window
AfxCenterWindow hwndMain
' // Initialize the graphic control
InitGraphCtx
' // Get the size of the client area
LOCAL rc AS RECT
GetClientRect(hwndMain, rc)
' // Create an instance of the graphic control
LOCAL hCtrl AS DWORD
hCtrl = CreateWindowEx(0, "GRAPHCTX", "", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
rc.Left, rc.Top, rc.Right, rc.Bottom, hwndMain, %IDC_GRCTX, hInstance, BYVAL %NULL)
' // Get the memory device context of the graphic control
LOCAL hdc AS DWORD
hdc = GraphCtx_GetDc(hCtrl)
' // Draw the graphics
GDIP_DrawLine hdc
' // Show the window
ShowWindow hwndMain, nCmdShow
UpdateWindow hwndMain
' // Message handler loop
LOCAL uMsg AS tagMsg
WHILE GetMessage(uMsg, %NULL, 0, 0)
IF IsDialogMessage(hwndMain, uMsg) = 0 THEN
TranslateMessage uMsg
DispatchMessage uMsg
END IF
WEND
' // Shutdown GDI+
GdiplusShutdown GdipToken
FUNCTION = uMsg.wParam
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL hCtrl AS DWORD
LOCAL hDC AS DWORD
SELECT CASE wMsg
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hwnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
END SELECT
CASE %WM_DESTROY
' // Close the main window
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hwnd, wMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
--- End code ---
And this one the GDI+ raw api and my CWindow class:
--- Code: ---' ########################################################################################
' Microsoft Windows
' File: CW_GraphCtrlGdipSkeleton.pbtpl
' Contents: Template - CWindow Graphic Control GDI+ Skeleton
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' 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.
' ########################################################################################
#COMPILE EXE
#DIM ALL
%UNICODE = 1
' // Header files for imported files
%USEGRAPHCTX = 1
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
%IDC_GRCTX = 1001
' ========================================================================================
' The following sample code draws a line.
' Change it with your own code.
' ========================================================================================
SUB GDIP_DrawLine (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
' // Create a graphics object
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a Pen
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitPixel, pPen)
' // Draw the line
GdipDrawLineI pGraphics, pPen, 0, 0, 200, 100
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
' SetProcessDPIAware
' // Create an instance of the CWindow class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Create the main window
pWindow.CreateWindow(%NULL, "CWindow Graphic Control GDI+ Skeleton", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
' // Set the client size
pWindow.SetClientSize 400, 250
' // Change the background color
pWindow.Brush = %COLOR_WINDOW + 1
' // Center the window
pWindow.CenterWindow
' // Add a GDI+ aware graphic control
LOCAL hCtl AS DWORD
hCtl = pWindow.AddGdipGraphCtx(pWindow.hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
' // Draw the graphics
GDIP_DrawLine(GraphCtx_GetDc(hCtl))
' // Default message pump (you can replace it with your own)
pWindow.DoEvents(nCmdShow)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
SELECT CASE uMsg
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDCANCEL
' // If the Escape key has been pressed...
IF HI(WORD, wParam) = %BN_CLICKED THEN
' // ... close the application by sending a WM_CLOSE message
SendMessage hwnd, %WM_CLOSE, 0, 0
END IF
END SELECT
CASE %WM_DESTROY
' // End the application
PostQuitMessage 0
EXIT FUNCTION
END SELECT
' // Pass unprocessed messages to Windows
FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
--- End code ---
José Roca:
Some comparisons:
SDK + my graphic control + raw api
Compile time: 0.7 seconds, at 17624400 lines/minute
15024 bytes compiled code, 4028 bytes RTLibrary,
64 bytes string literals, and 3200 bytes dgroup.
Executable stack size: 1048576 bytes.
Disk image: 24576 bytes Memory image: 7292 bytes.
CWindow+ my graphic control + raw api
Compile time: 0.7 seconds, at 18674914 lines/minute
22784 bytes compiled code, 16312 bytes RTLibrary,
172 bytes string literals, and 3540 bytes dgroup.
Executable stack size: 1048576 bytes.
Disk image: 46080 bytes Memory image: 20024 bytes.
DDT + graphic control + raw api
Compile time: 0.6 seconds, at 20045400 lines/minute
5712 bytes compiled code, 38956 bytes RTLibrary,
28 bytes string literals, and 2804 bytes dgroup.
Executable stack size: 1048576 bytes.
Disk image: 52224 bytes Memory image: 41788 bytes.
Theo Gottwald:
Jose, comparing CWindows with DDT or "Plain SDK" is unfair, because CWindows has a lot more features. It's class bvy itself.
Actually (maybe until Phoenix 3?) there is no alternative to the CWindows Class if somebody wants to make DPI-aware GUI's.
I have myself made such a "renamed" Jose_WinAPI-Version (its also somewhere here in the forum).
That can not be done manually, because all files must be renamend, and also all references in all files.
I have done it using a script file that time.
However i have dropped that approach because any update will need to have a complete new set created.
I actually make the manual switch between those two.
And for new projects of course Jose's favourable Header files are those of my choise if i use any API's.
One day I'll need to go to spain and check how many people work there really behind the synonym "Jose".
Sometimes i think it must be ten or more ... ;D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version