Changing the metrics in console from characters to pixels - c++

I'm wondering, is there a way to click the mouse on a console window and get the x y position by pixels instead of a character like the console mode is set on?
i.e I click on the (350,250) pixel on the console but the returned position is (56,35) for example, I searched all over google but didn't find anything usefull.

This will get you a bit further along:
Call GetConsoleWindow() to the the handle to the console that is running your process.
Call GetConsoleFontSize() to get width and height of the console font in pixels.
Call GetConsoleScreenBufferInfo() to get the screen buffer size.
Call PeekConsoleInput() or ReadConsoleOutput() to read the contents of the console you should probably read up on Low-Level Console Input Functions to understand what's going on here.
This MSDN article explains how to get console click events,
Now that you know how to get the mouse click coordinates and you have access to the buffer contents of the console it's simple to calculate what character is being clicked by dividing the X & Y cooridinates with the font width and height.

Related

Force Qt-Window to specific screen

I have a Windows-system with two monitors connected to it that itself expand the Windows-desktop. Now I want to start two Qt-applications but need to force each of them to a specific monitor, means application A always has to open it's window on monitor 1, application B always has to open it's window on monitor 2 (no matter where they have been opened the last time and no matter where the mouse is located at the moment).
How can this be done automatically? Can it only be done via the screen-coordinates of the desktop? If yes: how can I force my QWidget-based window to a specific coordinate? If no: how else can this be done?
To get the number of screens at runtime you can use:
int screenCount = QApplication::desktop()->screenCount();
To get the geometry of a screen, you can use:
QRect screenRect = QApplication::desktop()->screenGeometry(1); // 0-indexed, so this would get the second screen
Moving a window to that position (or resizing it) is then trivial:
yourWindow->move(QPoint(screenRect.x(), screenRect.y()));

Direct2D WM_MOUSEMOVE message with scaled display

I am new to Direct2D programming and I have encountered an issue with the WM_MOUSEMOVE message handling.
As documented in MSDN, I should use this enum to handle the mouse move, and should use the LOWORD & HIWORD to extract the current x and y coordinates.
That works fine when I am working on a normal display, but when trying to run it on scaled displays (e.g. 125% in my case), the values of x and y aren't accurate, in other words, there is an "indentation" between the current position of the mouse and the values extracted from lparam.
I guess I should query the OS or the window to get the current scaling so I can calculate the right position, but don't know how!
any help please?
You can take control of the scaling by declaring your program as DPI aware. Then the automatic scaling will stop and you'll get the original coordinates. You'll need to scale the window yourself though.
Creating a DPI-Aware Application

mouse click to get coordinates of picture control-MFC

I created a picture control (type: frame) to display image. Now I want to use mouse to click specified coordinates of picture control to show position and R, G,B values. How could I solve this problem?
Catch the WM_LBUTTONDOWN message. Get x/y coordinates from lParam (see MSDN for details). Get bits from image using GetDIBits(). Read RGBA from bitmap buffer you got from GetDIBits(), at the location x/y you got from lParam. This assumes your picture control doesn't do scaling etc., you'd have to correct x/y for that. Alternatively, you could use the ::PrintWindow() API to get a copy of the window into a DC; you could then use GetPixel() on the DC to get a COLORREF. Come to think of it, this is probably a better solution, if you're only after one RGB value.

Cursor indicator in terminal console - out of buffer size

I'm writing a program that prints squares to the screen according to the user's entries, in windows terminal console.
When the cursor
indicator reaches the most bottom right corner of the console and prints a character, it forces a another line in the console, since it moves one place to the right but has no more space.
Any suggestions how to avoid it?

Stop app window overlapping Windows start bar

On my Win7 PC I have the start-bar running vertically, it's about 60px wide. In my win32 application, the created window always appears overlapping the start bar, which looks bad - I just use (0,0) as the top-left position for the window.
How should I be doing it to get (0,0) relative to the desktop, taking the Start Bar into account? Is there a flag, or do I manually need to look up a metric?
There are a few problems here. You don't want to use a hard-coded value like (0,0). That might not even be visible on a multi-monitor system. As you have discovered, you should try to avoid overlapping with the taskbar or other appbars. If there are multiple monitors you should try and start on the monitor where the user has most recently interacted.
There is a simple way to make much of this happen for free. Pass CW_USEDEFAULT as the x and y coordinates when you call CreateWindow. This will let the window manager do the hard work of making your window appear in a sensible location.
You can get the system to tell you the coordinates of the work area. The work area is that part of the desktop that does not contain the taskbar or other appbars. Call SystemParametersInfo passing SPI_GETWORKAREA.
Retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars. The pvParam parameter must point to a RECT structure that receives the coordinates of the work area, expressed in virtual screen coordinates.
To get the work area of a monitor other than the primary display monitor, call the GetMonitorInfo function.
Use SetWindowPlacement. The (0,0) for that function excludes the taskbar and any other appbars.