Skip to Content
Former Member
Nov 24, 2005 at 10:07 AM

Amodal dialog box: positioning in lower right corner of screen


I have what seems a quite common requirement, that is to automatically position an amodal dialog box (CL_ABAP_DIALOGBOX_CONTAINER) to the lower right corner of the screen.

The logical approach to do this would be to read the screen resolution, deduct the size of the box, and pass the result to the TOP and LEFT parameters of the constructor of the container.

Unfortunately, I haven't found any documentation of what the values for TOP and LEFT (and for WIDTH and HEIGHT, for that matter) really represent. They're not screen pixels, that's for sure.

To read the screen resolution, I execute the following code:


lo_consumer TYPE REF TO cl_gui_props_consumer,

ls_metric_factors TYPE cntl_metric_factors.

lo_consumer = cl_gui_props_consumer=>create_consumer( ).

ls_metric_factors = lo_consumer->get_metric_factors( ).

In ls_metric_factors-screen-x and ls_metric_factors-screen-y I get back the screen resolution (x = 1280 and y = 994 on a 1280 x 1024 screen, weirdly, but close enough). Got this from another SDN post, BTW - thanks.

When I manually position my dialog box to the farthest right lower corner, so that the mouse cursor can just about reach it, the GET_LEFT and GET_TOP methods for the dialog box return LEFT = 1453 and TOP = 387. So, obviously, these values have nothing to do with screen pixels.

What I did, then, was to calculate a factor between the screen pixels and the TOP and LEFT values - a factor which is different for the X and the Y dimensions. I got:

- (1453 / 1280) = 1.135 for the x dimension

- (387 / 994) = 0.389 for the y dimension.

With these factors, I calculate the initial position of the box as follows:

l_box_pos_x = ( ls_metric_factors-screen-x * lc_factor_x ) - lc_box_width.

l_box_pos_y = ( ls_metric_factors-screen-y * lc_factor_y ) - lc_box_height.

This seems to work fine, at least on my system and my front-end PC, with all supported resolutions from 800 x 600 up to 1280 x 1024.

It just leaves the question open: Does anybody know what the unit of measure for the sizing and positioning parameters of controls is? Why a box with a width and a height of 100 [whatevers] each is not square, but rectangular?

And finally: does somebody have a more intelligent way to do this?

Thanks, regards & stuff