Highlighted
Absent Member.
Absent Member.
1208 views

[archive] Trapping <Ins> key in Entry-Field

[Migrated content. Thread originally posted on 08 May 2003]

Hi there,

A program's screen section running in character based UNIX has been changed to other format so that instead

03 using INPUT-FIELD pic zzzz9.99
line 10 col 10
. . .
. . .

now is

03 INPUT-FIELD-NAME,
entry-field,
line 10 col 10,
value INPUT-FIELD
id is 10,
. . .
. . .
and in its cblconfig the key is defined as exception key:

KEYSTROKE EXCEPTION=105 KI


Problem now is that with the previous format program was capable to trap the key but not anymore in the new (entry-field) format.

As the key is not mentioned in the Manual's text
. . .
"When an entry field has the input focus, the Home and End keys position the cursor at the beginning or end of a line of text. The Page-Up and Page-Down keys can be used to scroll a multi-line entry field. Setting KEYSTROKE configuration entries does not affect these actions."

. . . so I tought that it still might be doable some how ?

Is it ? ? ?
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Trapping <Ins> key in Entry-Field

Larry,
Are you programming in Windows? If so, I would consider subclassing the AcuCorp runtime. I have successfully done this and can vouch that it works. It requires some C experience and certain other things but can get you through those tricky situations that are impossible with the runtime.

AcuCobol's (limited) documentation for subclassing suggests rebuilding the runtime but you also have the option of compiling a dll which performs the subclassing option. It takes about 2 lines of code in C plus a switch statement to do what you are trying to do.

I can post some more information here if that would be helpful to you.

Merlin
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Trapping <Ins> key in Entry-Field

Thanks Merlin,
The thing is that we have mixed types of UNIX users, i.e. some of them are connected thru terminal emulation (character mode) and some are thru either thin or fat client (graphical mode). I am trying to keep the old key fashion to which users are used to, i.e. to use key due to add new record into a file.
As I understand your suggestion applies to Windows environment but I'll need similar for UNIX's character one too.
However, I would be grateful if you post more info on this having in mind that I've no experience with subclassing runtime rebuilding nor compiling a dll.
Thanks again
😞
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Trapping <Ins> key in Entry-Field

Larry,

I did a quick check of your problem and I here is what I think you need to do. Set up your environment as such:

set environment "Keystroke" to "Terminate=9 KI".

At least on windows, the insert key now terminates your accept. You can execute code following your accept and reneter the accept if necessary. If you still require normal behavior of the insert key, use w$keybuf to post in insert keypress on the keyboard stack. This will ignore the environent mapping for the key.

As for subclassing, this is a rather complicated topic and requires some knowledge of compiling and linking C programs. Acucorp supplies documentation to subclass the runtime with microsft visual C but I have successfully subclassed the window the Borland's C++ Builder compiler! In theory, you can use just about any windows C/C++ compiler .

What does subclassing allow you to do? Well it allows you to intercept windows messages and handle them instead of/in addition to the runtime's message handler. One cool example of this is a 'sticky' topmost popup form which listens for WM_MOVE and moves along with the main application window. Another useful example of subclassing would be to monitor keypresses and set an external variable when the user presses a key, allowing custom behavior.

There are two general approaches to subclassing:
1. rebuild the runtime
2. enter the runtime process via a dll.

I found #2 to be easier than #1 because it
a. is easer to do on non microsoft compilers and
b. makes it easier to upgrade your runtime should it ever change and
c. is easier to integrate to an existing project, and
d. it is very easy to call funtions in a dll (using call syntax).

AcuCorp supplies a number of dlls in the lib folder of your installation. These dlls comprise the runtime that your cobol program interacts with. Your dll will need to staticly link with atermmgr.dll (for the application window handle) and wrun32.dll (for everything else). Once linked to those dlls, have one of your startup programs call your dll to open it and call a specific function to do your sublclass. In my dll, I had a function
static void* hAcuRuntime;

__declspec(dllexport) void _cdecl SubClass(HANDLE* hWind)
{

WNDPROC proc = &CobolMessageHandler;
hAcuRuntime = (WNDPROC) SetWindowLong(hAcuWnd, GWL_WNDPROC, (LONG) proc);
int i = GetLastError();

}

and a function

LRESULT CALLBACK CobolMessageHandler(
HWND hWnd, // handle to window
UINT Msg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
...
LRESULT lr = CallWindowProc(
(int (__stdcall*)()) hAcuRuntime, // pointer to previous procedure
hWnd, // handle to window
Msg, // message
wParam, // first message parameter
lParam); // second message parameter

...
return lr;
}

The ... spots indicate where you could put your own code to act on application window messages.

From my cobol program, I simply ran
call "CobolUtils.dll".
call "_Subclass".

note: borland compilers (not microsoft) prefix dll exports with an underscore! Also, calls to dll functions are case sensitive.

Merlin
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Trapping <Ins> key in Entry-Field

Merlin,
It worked fine on Windows.
However, I am playing now with the subclassing following your advices.
Again thanks a lot and Best Regards
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.