Determining Console Window's Position

Anything and everything about programming graphics with Ultibo
pjde
Posts: 383
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Determining Console Window's Position

Postby pjde » Wed May 23, 2018 4:45 am

Hi Garry

If I create a Graphics Console window positioned at CONSOLE_POSITION_BOTTOMRIGHT, how can I get its co-ordinates relative to the frame buffer (namely its origin).

The GraphicsWindowGetViewport function (and others) always return 0,0 as the origin.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 1980
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Determining Console Window's Position

Postby Ultibo » Wed May 23, 2018 11:05 am

pjde wrote:If I create a Graphics Console window positioned at CONSOLE_POSITION_BOTTOMRIGHT, how can I get its co-ordinates relative to the frame buffer (namely its origin).

There are two ways to do it simply, one will always work and the other might disappear in future.

The first (and recommended) way is to use GraphicsWindowGetProperties() to retrieve a TWindowProperties structure which tells you everything you need to know about the window position relative to the screen as well as things like the border width, offsets, font, state and so on.

This would look like this, the window coordinates relative to the console will be in the X1, X2, Y1 and Y2 fields:

Code: Select all

var
 Properties:TWindowProperties;
begin

  if GraphicsWindowGetProperties(Handle,@Properties) = ERROR_SUCCESS then
  begin
    ...


The second option is to call ConsoleDeviceGetPosition() which will return just the X1, X2, Y1 and Y2 values. I say this might go away in future because it is possible that at some stage we might remove the fixed window positions and allow console windows to appear anywhere on screen. Not like a full blown window manager but just for some extra flexibility.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 383
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: Determining Console Window's Position

Postby pjde » Wed May 23, 2018 9:12 pm

Thanks Garry

I will try this out.

Reagrds

Paul
Gavinmc42
Posts: 1387
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Determining Console Window's Position

Postby Gavinmc42 » Thu May 24, 2018 1:04 am

I have been using code like this for grabbing screenshots, the mulitpliers depend on which position the console is in, top left, bottom right etc.

Code: Select all

  Gwidth:=GraphicsWindowGetMaxX(GHandle);
  GHeight:=GraphicsWindowGetMaxY(GHandle);

  Gwidthoffset:=Gwidth + FRAMEBUFFER_CONSOLE_DEFAULT_DESKTOPOFFSET + 3 * CONSOLE_DEFAULT_BORDERWIDTH +  2 * WINDOW_DEFAULT_BORDERWIDTH;
  Gheightoffset:=FRAMEBUFFER_CONSOLE_DEFAULT_DESKTOPOFFSET + CONSOLE_DEFAULT_BORDERWIDTH +  WINDOW_DEFAULT_BORDERWIDTH;


I really need to find a better way but this has been working for a year so no hurry ;)
The system must know, because I don't need to do this when doing plotting in a graphics console, it knows the 0,0 point has x, y offset in the console window.
User avatar
Ultibo
Site Admin
Posts: 1980
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Determining Console Window's Position

Postby Ultibo » Thu May 24, 2018 10:53 am

Gavinmc42 wrote:I really need to find a better way but this has been working for a year so no hurry ;)
The system must know, because I don't need to do this when doing plotting in a graphics console, it knows the 0,0 point has x, y offset in the console window.

Try this, it should save an image of any window (text or graphics) to disk using the coordinates from the window properties.

Code: Select all


uses
  ...
  Console,
  GraphicsConsole,
  uScreenshot;

var
 X,Y:LongWord;
 Width,Height:LongWord;
 Properties:TWindowProperties;
begin

  if GraphicsWindowGetProperties(Handle,@Properties) = ERROR_SUCCESS then
  begin
    X:=Properties.X1 + Properties.Borderwidth;
    Y:=Properties.Y1 + Properties.Borderwidth;
    Width:=(Properties.X2 - Properties.X1 + 1) - (Properties.Borderwidth * 2);
    Height:=(Properties.Y2 - Properties.Y1 + 1) - (Properties.Borderwidth * 2);

    SaveScreen('C:\Mybitmap.bmp',X,Y,Width,Height,24);
Ultibo.org | Make something amazing
https://ultibo.org
Gavinmc42
Posts: 1387
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Determining Console Window's Position

Postby Gavinmc42 » Fri May 25, 2018 12:26 am

Thanks Garry, I will try it if I can get my hands on that gadget again.
Currently it is working better than a $80,000 piece of equipment, so end user might be reluctant to let me touch it anymore :lol:

Return to “Graphics”

Who is online

Users browsing this forum: No registered users and 0 guests