Feedback Search Top Backward Forward
EDM/2

Questions and Answers

Written by Larry Salomon

  Welcome to this month's "Questions and Answers"! Each month, I collect various questions sent to me via email and try to answer each directly; the ones that I feel contribute the most to developers, whether in terms of information or as a nifty trick to tuck into your cap, get published in this column.

This month's deluge of questions covered the following topics:

  • Using Presentation Parameters
  • Context-specific Dialogs
  • Adjusting the Priority of a Non-related Process
  • Hooking the Kernel APIs
  • Using MMPM/2 to Record and Playback Audio Samples

Using Presentation Parameters

Les Chan ( chan@holo.ps.iit.nrc.ca) writes:

How do I create buttons (and other standard classes) with custom fonts? I think the way to do this is with the last parameter in WinCreateWindow, which is PVOID pPresParams. But I can't figure out how to use it.

Also, once the window is created, one should be able to change the font with WinSetPresParams. And I can't get this to work consistently (the window is created with pPresParams=NULL).

So, what is the correct way to create and manipulate presentation parameters?

To answer your second question first, the most common problem with using WinSetPresParam is not passing the correct values for the parameters; this often manifests itself when attempting to change the font of a control. What most developers do not know, when using a string for the value of the presentation parameter, is that you must add one to the length for the `\0' byte at the end.


WinSetPresParam(hwndButton,
                PP_FONTNAMESIZE,
                strlen("12.Helv"),
                "12.Helv");

WinSetPresParam(hwndButton,
                PP_FONTNAMESIZE,
                strlen("12.Helv")+1,
                "12.Helv");

Thus, the first example is incorrect and will yield indeterminable results, while the second will work as expected. Using WinSetPresParam will work regardless of the value of pPresParam on the WinCreateWindow call.

Your first question is a bit more complex, due to the fact that the online and hardcopy documentation for 1.x and 2.0 are incorrect. Piecing together the information from all sources reaps the solution, however. In the WinCreateWindow call, the last parameter is defined to be of type PVOID when in reality it is of type PPRESPARAMS. This type is a variable length structure which contains one or more presentation parameters to be passed to the window (I won't review the structure definition, since you can do that on your own). By initializing this structure properly, you can set the appropriate characteristics on the call to WinCreateWindow as in the example below:


ULONG ulSzFont;
BYTE abBuf[sizeof(PRESPARAMS)+256];
PPRESPARAMS pppParm;

ulSzFont=strlen("18.Helv")+1;

pppParm=(PPRESPARAMS)abBuf;
pppParm->cb=sizeof(PARAM)+ulSzFont-1;
pppParm->aparam[0].id=PP_FONTNAMESIZE;
pppParm->aparam[0].cb=ulSzFont;
strcpy(pppParm->aparam[0].ab,"18.Helv");

if (WinCreateWindow(hwndWnd,
                    WC_BUTTON,
                    "Test",
                    WS_VISIBLE|BS_PUSHBUTTON,
                    100,
                    100,
                    200,
                    100,
                    hwndWnd,
                    HWND_TOP,
                    1,
                    NULL,
                    pppParm)==NULLHANDLE) {
   WinAlarm(HWND_DESKTOP,WA_ERROR);
   return MRFROMSHORT(FALSE);
} /* endif */

An interesting note here is that, when testing this, this code did not result in an error, yet no button was displayed when I placed this in the WM_CREATE processing.

Context-specific Dialogs

A user who wishes to remain anonymous writes:

I'm writing a program that is essentially a dialog. I know how to do that. But I want to have a portion be dependant on another part, but don't know how to make that happen. For example, when you click on an radio button in the top half, the bottom half changes so you can change settings for it.

If you have any experience using the notebook, you can design your main dialog in a related fashion. For each radio button in the top half, call WinLoadDlg to load an auxilliary dialog specific to the item that radio button represents. Then, when you receive the WM_CONTROL/ BN_CLICKED notification message, call WinShowWindow both to hide the currently displayed dialog and to display the dialog corresponding to the button selected.

As a caveat, define the auxilliary dialogs as having no border and not having any frame controls (FCF_ flags). You will also need to call WinSetWindowPos after loading them to set their position to be the lower half of the main dialog.

Adjusting the Priority of a Non-related Process

Roman Stangl ( 86505339awiwuw11.wu-wien.ac.at) writes:

How can the priority of any running process be adjusted, without these processes being child processes of the program that wants to adjust the priority.

The answer is that you can't, at least as far as I am aware. If you have the source to the child processes, you can modify them to accept a command line parameter specifying the desired priority class and value and then have them call DosSetPriority.

Hooking the Kernel APIs

Roman Stangl ( 86505339awiwuw11.wu-wien.ac.at) again writes:

How can the OS/2 API DosOpen() be hooked to trace write accesses to files, similar to a DOS TSR that hooks into INT21?

The only way I know of to accomplish what your second question is asking is by writing your own IFS (installable file system). You might be able to also do this using device monitors, but I cannot be sure. My apologies for the lack of a concrete answer to this.

Using MMPM/2 to Record and Playback Audio Samples

Marc Van-Woerkom ( Marc_Van-Woerkom@ac3.maus.de) writes:

I own a Soundblaster card and want to use it under OS/2!

It's FM synthesizers generate some nice sounds but I think the best effects are produced by it's digital channel. For this I need a driver/routines that allow me to record and play a sample.

A solution already exists (sbos2 package) but that's only an intermediate solution -- with OS/2 2.1 MMPM/2 will become the standard to deal with.

So is there a MMPM/2 API which allows me to record/play samples?

In the Summer 1992 issue of the OS/2 Developer magazine, there is an article entitled "Listen to the Sounds: The MMPM/2 Audio Subsystem" starting on page 98. In this article, the author discusses how both audio samples and MIDI sequences are used in the MMPM/2 system. Since I personally have no experience using MMPM/2, I will not try to explain the article in order to avoid confusing anyone, but will consider the reference as an affirmative answer to your question.

Now that the magazine is published by Miller Freeman, I am unsure if back issues can be ordered. If so, the IBM Mechanicsburg number is G362-0001; if not, you can try contacting the magazine via the Internet at the address os2mag@vnet.ibm.com for the possibility of article reprints.