Win32 API samples

This collection of code snippets used to be hosted on www.global-shared.com.
It is an old collection: it all began in 1996 or 1997, when Progress 8 was new and many of us were still using Windows 3.1 !!
Unlike wine or paintings, program code doesn't get better when it ages. You can find fragments that can be improved because Microsoft continuously expands their API, or are outdated because Progress has added features to the ABL so we don't need to use the WIN32 API anymore.


Asterisks in password

The Progress fill-in widget has a :blank attribute that you can use when creating a password field. But most Windows applications use asterisks instead of blanks.
It's fairly simple to have asterisks (or any other password-character) in Progress too:

  {windows.i}
  DEFINE VARIABLE ReturnValue AS INTEGER NO-UNDO.
  RUN SendMessage{&A} IN hpApi (fill-in_password:HWND, 
                                {&EM_SETPASSWORDCHAR}, 
                                ASC("*"),
                                0,
                                OUTPUT ReturnValue).

Explanation


Login

.


Popup windows from HTML Help

The previous topic calling HTML Help described how to call HtmlHelp to show a normal HTML topic. Here is how to use HtmlHelp to show a popup or contexthelp-window.

The declaration for the HtmlHelp function is now slightly different: pszFile is now declared as a LONG parameter because we will have to pass it the NULL value. This is the new declaration:

&GLOBAL-DEFINE HH_DISPLAY_TEXT_POPUP 14
 
PROCEDURE HtmlHelpA EXTERNAL "hhctrl.ocx" PERSISTENT :
   DEFINE INPUT PARAMETER  hwndCaller AS LONG.
   DEFINE INPUT PARAMETER  pszFile    AS LONG.
   DEFINE INPUT PARAMETER  uCommand   AS LONG.

Calling HTML-Help

WinHelp is history... HTML Help is the future. The API for HTML Help is implemented in hhctrl.ocx (don't let the filename fool you; the ocx contains both an ActiveX control and API functions). First let's take a look at the definition:

&GLOBAL-DEFINE HH_DISPLAY_TOPIC 0
&GLOBAL-DEFINE HH_KEYWORD_LOOKUP 13
&GLOBAL-DEFINE HH_DISPLAY_TEXT_POPUP 14
 
PROCEDURE HtmlHelpA EXTERNAL "hhctrl.ocx" PERSISTENT :
   DEFINE INPUT PARAMETER  hwndCaller AS LONG.
   DEFINE INPUT PARAMETER  pszFile    AS CHARACTER.
   DEFINE INPUT PARAMETER  uCommand   AS LONG.
   DEFINE INPUT PARAMETER  dwData     AS LONG.
   DEFINE RETURN PARAMETER hwndHelp   AS LONG.
END PROCEDURE.

Notice the **PERSISTENT** keyword: it is required for this function!
hwndCaller is the HWND of the calling window. The help-window stays on top of this calling window. You can specify hwndCaller=0 if you don't like that stay-on-top behaviour.
pszFile is (depending on uCommand) the name of the helpfile, combined with the name of the topic file, combined with the name of the window class in which you want to show the topic. For example "apisite.chm::/playsounda.html>mainwin".
pszFile can also be used to specify the text to show in a popup-window (if uCommand is HH_DISPLAY_TEXT_POPUP) as demonstrated on the next page, Popup windows from HTML Help


Using the contexthelp-button from the title-bar


This topic is 32-bit only and was made in cooperation with Paul Koufalis.

This example uses the source in procedure winstyle.p, available on page WinStyle.p.
It also uses the MsgBlaster control, free available for download.

It seems common practice in Windows 95 to create a Contexthelp button in the titlebar of a dialog, rather than a 'normal' helpbutton. When the user chooses the Contexthelp button it will stay down and the mouse pointer changes into an arrow with question mark. When the user now chooses a control, Windows will send a WM_HELP message to the top-level window, releases the Contexthelp button and reloads the usual mouse-pointer.


Using context help from any button

Topic using the contexthelp-button from the title-bar explained how to create the standard windows contexthelp-button on the title bar, and how to respond to its events. This standard button is commonly used with dialog boxes but is not really suitable for (top-level) windows, especially because the contexthelp-button can only be realised when the Minimize/Maximize buttons aren't visible.
On a (top-level) window, it's probably more appropriate to create a toolbar where one of the right-most buttons invokes context-help. To implement this in Progress you can simply create a button-widget and add the following ON CHOOSE-handler to it:


Helpfiles

.


WinStyle.p

You can find procedure winstyle.p in everything.zip, available on page windows.i and hpApi


windows.i and hpApi

Introduction

Throughout the site you will see references to windows.i and the handle hpApi.
hpApi is defined in windows.i and is a procedure-handle to windows.p.
windows.p contains a bunch of API procedures.

You can get a copy of windows.i and windows.p: they are in "everything.zip" which also contains some more API-related sources .

Attachments

everything.zip : contains windows.i and windows.p, and more :-)


Winconst tool (search Windows Constants)

The Win32 API contains many constants.
winconst.zip contains a list of more than 14000 P4GL preprocessor definitions and a utility that helps to find dependencies.
For example, the constant WVR_REDRAW is defined as (WVR_HREDRAW | WVR_VREDRAW).

When you search for WVR_REDRAW in winconst.exe it will return

&GLOBAL-DEFINE WVR_VREDRAW 512
&GLOBAL-DEFINE WVR_HREDRAW 256
&GLOBAL-DEFINE WVR_REDRAW  ({&WVR_HREDRAW} + {&WVR_VREDRAW})

winconst.zip is freeware. So feel free to download it :-)


ProExtra.dll

ProExtra.dll is a small Delphi utility I wrote to call some low-level stuff that would otherwise be hard to do from within 4GL.

proextra.dll and its Delphi source are included in "everything.zip" which is available for download on page windows.i and hpApi.


MsgBlaster

The MsgBlaster or MessageBlaster is a freeware ActiveX control that helps you catch every Windows message. This control is used in several examples in this Win32 zone, see topic context-help for a practical example.

You can download the MsgBlaster from: http:extra.newsguy.com/~bridge/mbocx32b.zip


Downloads

.


Local name to UNC name

by Michael Rüsweg-Gilbert

Procedure WNetGetConnection retrieves the name of the network resource associated with a local device. In other words, it can be used to get the UNC name for a mapped network drive or printer. If K: is the drive letter of a mapped network drive, the following example finds the UNC name for this network drive.

DEFINE VARIABLE Drive_Name AS CHARACTER NO-UNDO INIT "K:".
DEFINE VARIABLE UNC_Name AS CHARACTER NO-UNDO.
 
DEFINE VARIABLE namelen AS INTEGER NO-UNDO INITIAL 100.
DEFINE VARIABLE retBool AS INTEGER NO-UNDO.
 
UNC_Name = FILL("x",namelen).

Mailslot example

Source code by Todd. G. Nist, Protech Systems Inc.

Source is attached for download.

This procedure can run either as a mailslot server or as a mailslot client. If it runs as a server, it will be able to read messages (it uses a PSTimer.ocx to scan for new messages each 500 msec). If it runs as a client it is able to send messages if there is also a server active.
I (Jurjen) had only one PC to play with, so I launched two instances of Progress on that PC, each running a copy of w-mailslot.w as shown on the pic.


#
Syndicate content