Highlighted
Absent Member.
Absent Member.
1993 views

[archive] API SetWindowPos

[Migrated content. Thread originally posted on 15 November 2005]

Have anyone experience with SetWindowPos?

we need to set a window On Top until it's closed. I figured out that this could be handled with SetWindowPos from user32.dll.

But i have no experience with Api-Calls.

I found in MSDN this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowpos.asp


BOOL SetWindowPos(          HWND hWnd,
    HWND hWndInsertAfter,
    int X,
    int Y,
    int cx,
    int cy,
    UINT uFlags
);


hWnd - [in] Handle to the window.
is this the window handle which i will set to top? can i put there for example the handle from cobol for the window?

I mean for example:

       77  main-window                           handle of window.

           call "SetWindowPos" using
                by value main-window
                by value ...
                by value ...
                by value ...
                by value ...
                by value ...
                by value ...
           end-call.


hWndInsertAfter
[in] Handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values.


where can i get the value for hWndInsertAfter?
or is it something like
1 for HWND_BOTTOM
2 for HWND_NOTOPMOST
3 for HWND_TOP
4 for HWND_TOPMOST
this?

have anyone a tip for me how i can figure out the values for it?

Thanks,
David
0 Likes
6 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] API SetWindowPos

Originally posted by Frosti
Have anyone experience with SetWindowPos?

we need to set a window On Top until it's closed. I figured out that this could be handled with SetWindowPos from user32.dll.



SetWindowPos is for specifying where on the desktop you want to put your window, not necessarily bringing it to front. For that purpose you would use SetForegroundWindow, if using API at all.

May I ask why you do not use:

SET INPUT WINDOW TO windowhandle.

This should bring your cobol window up. If you have multiple windows in your cobol app, you should use the MODAL style to keep it on top.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] API SetWindowPos

in this special situation we have 2 several programs running and some persons are not able to recognize that one of this programms is minimized or behind the other program-window.

I added a code that it is not possible to start any of these program 2 times. And when both programs are running and one program is behing the other program we get several call each day from this persons that they become a msg "that the program is already running". We explained 1000 times how to bring the window in front, but.... we still get calls.

The Window of each programm is not so big that they haven't enough place that they can be placed next to each other on the desktop. So we hope that this could be the solutions to stop the problem.


Another Solution i could integrate is a fix position for each program which can't be changed. But this is atm my second choice.

David


PS:
i found several c++ and dephi programms - where SetWindowPos is used to set it on top.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] API SetWindowPos

> i found several c++ and dephi programms -
> where SetWindowPos is used to set it on top.

Odd. But how come you do not use COBOL:
SET INPUT WINDOW winhandle.

Have you tried this?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] API SetWindowPos

in the documentation from AcuCobol it is describted that it must be a valid floating window and i have a standard window.

Still tested to change it to a floating window - but the window still can put to background. So i have to write a thread which only do every x seconds "set input window to winhandle". But i think this can't be the solution.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] API SetWindowPos

Here is how to with SetWindowPos.

First of all, get the Microsoft window handle of the cobol window handle, from now on referred to as respectively hWnd and cWnd:

       77 hWnd PIC X(4) COMP-N.
       77 hWndInsertAfter PIC X(4) COMP-N.
       77 X PIC X(4) COMP-N.
       77 Y PIC X(4) COMP-N.
       77 CX PIC X(4) COMP-N.
       77 CY PIC X(4) COMP-N.
       77 uFlags PIC X(4) COMP-N.
       78 HWND-TOP        VALUE 0
       78 HWND-BOTTOM     VALUE 1
       78 HWND-TOPMOST    VALUE -1
       78 HWND-NOTOPMOST  VALUE -2

...

INQUIRE cWnd SYSTEM HANDLE IN hWnd.
MOVE 1 TO X Y. | new start coordinates, pick your choice
MOVE 0 TO CX CY. | Whatever, the next will ignore this anyway.
MOVE 1 TO uFlags. | 1 is SWP_NOSIZE, don\t change size.
MOVE HWND-TOPMOST TO hWndInsertAfter. | I am not sure of this though...
CALL "USER32.DLL".
CALL "SetWindowPos@WINAPI" USING | @WINAPI requires v. 7...
       BY VALUE hWnd
       BY VALUE hWndInsertAfter
       BY VALUE X
       BY VALUE Y
       BY VALUE CX
       BY VALUE CY
       BY VALUE uFlags
CANCEL "USER32.DLL"


No warrants this will work. But the princip is there.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] API SetWindowPos

thx for the code 🙂

i will test it as soon as possible.
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.