You may call the Windows API directly from PowerCOBOL (as well as directly from NetCOBOL). You will need to link into your PowerCOBOL application the appropriate library. NetCOBOL ships with the main Windows API library (USER32.LIB).
In order to add this into your project for linkage purposes, you right click on the module name in the Project Manager and select the Insert File option from the context menu that appears. Then navigate to the location of the USER32.LIB file, which by default is installed in the C:\Program Files\Fujitsu NetCOBOL for Windows\COBOL subdirectory, and select it.
The following example will change your desktop's wallpaper setting (your desktop's background) to a new .bmp file that you specify.
And you need to specify the "ALPHAL(WORD)" compile option in the Script's properties dialog box.
The following code placed in an event procedure will bring up the Windows get filename dialog box and allow you to select a .bmp file. It will then call the Windows API to set the desktop wallpaper to the BMP file you specify:
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ReturnValue Pic S9(9) Comp-5 Value 0.
01 FileMask Pic X(32)
Value "Bitmap Files|*.bmp|All Files|*.*".
01 DeskFile.
03 FileName Pic X(255) Value Spaces.
03 Filler Pic X Value X"00".
01 Sub1 Pic 9(4) Comp-5 Value 0.
01 uiAction Pic S9(9) Comp-5 Value 0.
01 uiParam Pic S9(9) Comp-5 Value 0.
01 pvParam Pic X(255) Value Spaces.
01 fWinIni Pic S9(9) Comp-5 Value 0.
01 SPIF_UPDATEINIFILE Pic S9(9) Value 1.
01 SPIF_SENDWININICHANGE Pic S9(9) Value 2.
PROCEDURE DIVISION.
* Note that a special compiler directive is being used. Right click
* on (Script)[COBOL Script] in the project manager.
* Select "Properties" from the context menu and check
* the ALPHAL(WORD) compiler directive.
* Get the name of the bitmap file to set desktop background to
Move Spaces to FileName.
INVOKE POW-SELF "GetFileName" USING FileName
"Select Bitmap File"
FileMask
POW-CDOPEN
RETURNING ReturnValue.
* If ReturnValue is true, user did select a .bmp file to apply
If ReturnValue = POW-TRUE
* String parameters being passed to "C" functions must be null
* terminated. Check the filename and insert a null at the end of
* the filename
Compute Sub1 = Function Length(FileName)
Perform With Test Before Until (FileName(Sub1:1)
Not = Space)
Subtract 1 From Sub1
End-Perform
If Sub1 < 255
Add 1 To Sub1
Move X"00" To FileName(Sub1:1)
End-If
* Set up parameters to call the "C" Function
Move DeskFile To pvParam
Move 20 To uiAction
Move 0 To uiParam
Move 0 To fWinIni
* Set the SPIF_UPDATEINIFILE Flag
Add SPIF_UPDATEINIFILE To fWinIni
* Set the SPIF_SENDWININICHANGE Flag
Add SPIF_SENDWININICHANGE To fWinIni
* Call the User32.dll SystemParametersInfoA function
Call "SystemParametersInfoA" With STDCALL Linkage
Using By Value uiAction,
By Value uiParam,
By Reference pvParam,
By Value fWinIni
Returning ReturnValue
If ReturnValue = 1
Invoke POW-SELF "DisplayMessage"
Using "Desktop Background Changed!"
Else
Invoke POW-SELF "DisplayMessage"
Using "Error - Desktop Background Not Changed!"
End-If.