Author Topic: Windows API Headers v.2.03  (Read 8188 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Windows API Headers v.2.03
« on: July 12, 2011, 12:10:11 AM »
 
This project is an effort to translate the C headers of the Microsoft Platform SDK for Windows to PowerBASIC™. This version has been updated using the SDK for Windows 7.1.

These headers are freeware, not public domain. This means that you can use them for your own purposes, even in commercial applications, without paying a fee, but not to make derivative works from, sell or redistribute without permission. Also you must assume the entire risk of using them. Downloading the software indicates that you accept these terms.

Because of the use of new data types only available in PNWIN 10.0+ and PBCC 6.0+ and other features, they can only be used with the new compilers.

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.

The wrapper functions for the Common Controls have been removed from CommCtrl.inc and placed in the following individual files. Therefore, the use of constants such %NOTOOLBAR, %NOUPDOWN, etc., is no longer needed. Just #INCLUDE the wanted files in your application.

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)

There are 1,180 files using 76,189,551 bytes.
« Last Edit: August 06, 2011, 01:50:30 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Windows API Headers v.2.03 Help File
« Reply #1 on: July 12, 2011, 12:12:45 AM »
 
Help file for the main classes and wrapper functions available in the version 2.03 of the Windows API Headers for PBWin 10.02 and PBCC 6.02.
« Last Edit: August 06, 2011, 01:58:14 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Windows API Headers v.2.03 FAQ
« Reply #2 on: July 12, 2011, 12:14:07 AM »
 
Existing code that uses my headers for PB9 will work without changes with PB10 and the new headers with the exception of these that use calls to unicode functions or COM interfaces. These will continue to work with PB10 without changes using the old headers, but will need changes to work with PB10 and the new headers.

The reason is that because there was not native unicode support in PB9 we had to use the workaround of declaring the parameter as BYVAL DWORD, use a dynamic string and UCODE$ and pass a pointer to the string content using STRPTR. With PB10 and the new headers, these parameters are now declared as WSTRING or WSTRINGZ, as appropriate, and you no longer have to use UCODE$/ACODE$.

Regarding the API functions, these are the ones that will need a change: PtInRect, MenuItemFromPoint, WindowFromPoint, ChildWindowFromPointEx, WindowFromPoint, MonitorFromPoint, RealChildWindowFromPoint, LBItemFromPt, DragDetect.

All of these have a parameter that is a POINT structure passed by value. As very old versions of the compiler could not pass structures by value, they used two long parameters, x and y. I also used two long parameters in my headers to avoid conflicts with the PB headers, but this is not longer the case with the new PB headers. To make the change as painless as possible, I'm providing alternate XY functions, so you only have to change slightly the name of the function if you prefer to continue passing longs.

Code: [Select]
DECLARE FUNCTION PtInRect IMPORT "USER32.DLL" ALIAS "PtInRect" ( _
   BYREF lprc AS RECT _                                 ' __in CONST RECT *lprc
 , BYVAL pt AS POINT _                                  ' __in POINT pt
 ) AS LONG                                              ' BOOL

' Same as above, but using x, y coordinates
DECLARE FUNCTION PtInRectXY IMPORT "USER32.DLL" ALIAS "PtInRect" ( _
   BYREF lprc AS RECT _                                 ' __in CONST RECT *lprc
 , BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 ) AS LONG                                              ' BOOL

Code: [Select]
DECLARE FUNCTION MenuItemFromPoint IMPORT "USER32.DLL" ALIAS "MenuItemFromPoint" ( _
   BYVAL hWnd AS DWORD _                                ' __in_opt HWND hWnd
 , BYVAL hMenu AS DWORD _                               ' __in HMENU hMenu
 , BYVAL pt AS POINT _                                  ' __in pt POINT
 ) AS LONG                                              ' int

' // Same as above, but using x, y coordinates
DECLARE FUNCTION MenuItemFromXY IMPORT "USER32.DLL" ALIAS "MenuItemFromPoint" ( _
   BYVAL hWnd AS DWORD _                                ' __in_opt HWND hWnd
 , BYVAL hMenu AS DWORD _                               ' __in HMENU hMenu
 , BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 ) AS LONG                                              ' int

Code: [Select]
DECLARE FUNCTION WindowFromPoint IMPORT "USER32.DLL" ALIAS "WindowFromPoint" ( _
   BYVAL Point AS POINT _                               ' __in POINT Point
 ) AS DWORD                                             ' HWND

' // Same as above, but using x, y coordinates
DECLARE FUNCTION WindowFromXY IMPORT "USER32.DLL" ALIAS "WindowFromPoint" ( _
   BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 ) AS DWORD                                             ' HWND

Code: [Select]
DECLARE FUNCTION ChildWindowFromPointEx IMPORT "USER32.DLL" ALIAS "ChildWindowFromPointEx" ( _
   BYVAL hWnd AS DWORD _                                ' __in HWND hWnd
 , BYVAL pt AS POINT _                                  ' __in POINT pt
 , BYVAL Flags AS DWORD _                               ' __in UINT Flags
 ) AS DWORD                                             ' HWND

' Same as above, but using x, y coordinates
DECLARE FUNCTION ChildWindowFromXYEx IMPORT "USER32.DLL" ALIAS "ChildWindowFromPointEx" ( _
   BYVAL hWnd AS DWORD _                                ' __in HWND hWnd
 , BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 , BYVAL Flags AS DWORD _                               ' __in UINT Flags
 ) AS DWORD                                             ' HWND

Code: [Select]
DECLARE FUNCTION MonitorFromPoint IMPORT "USER32.DLL" ALIAS "MonitorFromPoint" ( _
   BYVAL pt AS POINT _                                  ' __in POINT pt
 , BYVAL dwFlags AS DWORD _                             ' __in DWORD dwFlags
 ) AS DWORD                                             ' HMONITOR

' // Same as above, but using x, y coordinates
DECLARE FUNCTION MonitorFromXY IMPORT "USER32.DLL" ALIAS "MonitorFromPoint" ( _
   BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 , BYVAL dwFlags AS DWORD _                             ' __in DWORD dwFlags
 ) AS DWORD                                             ' HMONITOR

Code: [Select]
DECLARE FUNCTION RealChildWindowFromPoint IMPORT "USER32.DLL" ALIAS "RealChildWindowFromPoint" ( _
   BYVAL hwndParent AS DWORD _                          ' __in HWND hwndParent
 , BYVAL ptParentClientCoords AS POINT _                ' __in POINT ptParentClientCoords
 ) AS DWORD                                             ' HWND

' // Same as above, but using x, y coordinates
DECLARE FUNCTION RealChildWindowFromXY IMPORT "USER32.DLL" ALIAS "RealChildWindowFromPoint" ( _
   BYVAL hwndParent AS DWORD _                          ' __in HWND hwndParent
 , BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 ) AS DWORD                                             ' HWND

Code: [Select]
DECLARE FUNCTION LBItemFromPt IMPORT "COMCTL32.DLL" ALIAS "LBItemFromPt" ( _
   BYVAL hLB AS DWORD _                                 ' __in HWND hLB
 , BYVAL pt AS POINT _                                  ' __in pt POINT
 , BYVAL bAutoScroll AS LONG _                          ' __in BOOL bAutoScroll
 ) AS LONG                                              ' int

' // Same as above but using x, y coordinates
DECLARE FUNCTION LBItemFromXY IMPORT "COMCTL32.DLL" ALIAS "LBItemFromPt" ( _
   BYVAL hLB AS DWORD _                                 ' __in HWND hLB
 , BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 , BYVAL bAutoScroll AS LONG _                          ' __in BOOL bAutoScroll
 ) AS LONG                                              ' int

Code: [Select]
DECLARE FUNCTION DragDetect IMPORT "USER32.DLL" ALIAS "DragDetect" ( _
   BYVAL hwnd AS DWORD _                                ' __in HWND hwnd
 , BYVAL pt AS POINT _                                  ' __in pt POINT
 ) AS LONG                                              ' BOOL

' // Same as above, but using x, y coordinates
DECLARE FUNCTION DragDetectXY IMPORT "USER32.DLL" ALIAS "DragDetect" ( _
   BYVAL hwnd AS DWORD _                                ' __in HWND hwnd
 , BYVAL x AS LONG _                                    ' __in x
 , BYVAL y AS LONG _                                    ' __in y
 ) AS LONG                                              ' BOOL

There are other changes that don't affect existing code, such the RECT structure, that now is an union to allow the use of rc.nLeft, rc.Left, rc.x, etc.

Code: [Select]
' // Size = 16 bytes
TYPE OLD_RECT_STRUCT DWORD   ' Old PB definition
   nLeft   AS LONG   ' LONG left
   nTop    AS LONG   ' LONG top
   nRight  AS LONG   ' LONG right
   nBottom AS LONG   ' LONG bottom
END TYPE

' // Size = 16 bytes
TYPE tagRECT DWORD
   left   AS LONG   ' LONG left
   top    AS LONG   ' LONG top
   right  AS LONG   ' LONG right
   bottom AS LONG   ' LONG bottom
END TYPE

' // GDI+ uses x, y, Width and Height as members instead of Left, Right, Top and Bottom
TYPE GDIP_RECT_STRUCT DWORD
   x      AS LONG   ' LONG x
   y      AS LONG   ' LONG y
   Width  AS LONG   ' LONG Width
   Height AS LONG   ' LONG Height
END TYPE

' // To allow the use of both nLeft, etc, and Left, etc.
' // Size = 16 bytes
UNION RECT
   OLD_RECT_STRUCT
   tagRECT
   GDIP_RECT_STRUCT
END UNION

The new headers allow to work with unicode transparently just by defining %UNICODE = 1 before #INCLUDEing the headers. For example, if you call RegisterWindowMessage, RegisterWindowMessageA will be called if %UNICODE is not defined (not defined does not mean equal to 0; if you use %UNICODE = 0, then %UNICODE is defined with a value of 0), and RegisterWindowMessageW will be called if %UNICODE is defined (any value, although the usual is to set it to 1).

Code: [Select]
DECLARE FUNCTION RegisterWindowMessageA IMPORT "USER32.DLL" ALIAS "RegisterWindowMessageA" ( _
   BYREF lpString AS ASCIIZ _                           ' __in LPCSTR lpString
 ) AS DWORD                                             ' UINT

DECLARE FUNCTION RegisterWindowMessageW IMPORT "USER32.DLL" ALIAS "RegisterWindowMessageW" ( _
   BYREF lpString AS WSTRINGZ _                         ' __in LPCWSTR lpString
 ) AS DWORD                                             ' UINT

#IF %DEF(%UNICODE)
   MACRO RegisterWindowMessage = RegisterWindowMessageW
#ELSE
   MACRO RegisterWindowMessage = RegisterWindowMessageA
#ENDIF

You can also call RegisterWindowMessageA or RegisterWindowMessageW individually.

This SDK skeleton will work either as ansi or unicode just commenting or uncommenting the %UNICODE constant:

Code: [Select]
#COMPILE EXE
#DIM ALL
'%UNICODE = 1

' // Include files for external files
#INCLUDE ONCE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   LOCAL hwndMain AS DWORD
   LOCAL hFont 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

   ' // Default font
   hFont = GetStockObject(%DEFAULT_GUI_FONT)

   ' // Register the window class
   szClassName        = "MyClassName"
   wcex.cbSize        = SIZEOF(wcex)
   wcex.style         = %CS_DBLCLKS OR %CS_HREDRAW OR %CS_VREDRAW
   wcex.lpfnWndProc   = CODEPTR(WindowProc)
   wcex.cbClsExtra    = 0
   wcex.cbWndExtra    = 0
   wcex.hInstance     = hInstance
   wcex.hCursor       = LoadCursor (%NULL, BYVAL %IDC_ARROW)
   wcex.hbrBackground = %COLOR_3DFACE + 1
   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 = "Generic SDK Program"

   ' 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
                             %CW_USEDEFAULT, _                 ' initial x position
                             %CW_USEDEFAULT, _                 ' initial y position
                             %CW_USEDEFAULT, _                 ' initial x nSize
                             %CW_USEDEFAULT, _                 ' initial y nSize
                             %NULL, _                          ' parent window handle
                             0, _                              ' window menu handle
                             hInstance, _                      ' program instance handle
                             BYVAL %NULL)                      ' creation parameters

   

   ' // 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

   FUNCTION = uMsg.wParam

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

   ' // Process window mesages
   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
                  EXIT FUNCTION
               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
' ========================================================================================

As you can see, the only visible difference is:

Code: [Select]
#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

but if %UNICODE is defined, it will call RegisterClassExW, CreateWindowExW, DefWindowProcW, SendMessageW, else it will call RegisterClassExA, CreateWindowExA, DefWindowProcA, SendMessageA.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Windows API Headers v.2.03: ODBC Reference Guide
« Reply #3 on: July 12, 2011, 01:13:30 AM »
 
Help file for the ODBC flat API and the CODBC class.
« Last Edit: August 06, 2011, 01:59:38 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Windows API Headers v.2.03: GDI+ Reference Guide
« Reply #4 on: July 12, 2011, 01:15:32 AM »
 
Help file for the GDI+ Flat API and the GDI+ classes.
« Last Edit: August 06, 2011, 02:00:28 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Windows API Headers v.2.03: Windows GDI Reference Guide
« Reply #5 on: July 12, 2011, 11:39:03 AM »
 
Help file for the Windows GDI API.
« Last Edit: August 06, 2011, 02:01:53 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: Windows API Headers v.2.03
« Reply #6 on: July 12, 2011, 12:23:46 PM »
 
Help file for the Structured Storage interfaces.
« Last Edit: August 06, 2011, 02:02:29 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: Windows API Headers v.2.03
« Reply #7 on: July 12, 2011, 07:14:13 PM »
 
Help file for ADO/ADOX 2.8.
« Last Edit: August 06, 2011, 02:03:14 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: Windows API Headers v.2.03
« Reply #8 on: July 12, 2011, 07:15:16 PM »
 
Help file for WinHTTP.
« Last Edit: August 06, 2011, 02:03:52 PM by José Roca »