Getting a pixel's coordinates

Is there any way to get the coordinates of a pixel using the standard console? I know this is possible using the rather complicated Windows API by creating a Windows class, winproc handler etc.
The standard console seems to support setPixel but not getPixel. https://docs.microsoft.com/en-us/windows/console/console-functions

Thanks for your help.
GetPixel seems to work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int main()
{
  HWND hConsole = ::GetConsoleWindow();
  HDC hDC = ::GetDC(hConsole);
  COLORREF crRed = RGB(255, 0, 0);

  for (int i = 10; i < 200; ++i)
    for (int j = 10; j < 200; ++j)
      ::SetPixel(hDC, i, j, crRed);

  COLORREF crColor = ::GetPixel(hDC, 20, 20);
  printf("Color at 20 20 = %d %d %d", GetRValue(crColor), GetBValue(crColor), GetGValue(crColor));

  ::Sleep(5000); /* wait 5 sec */
  ::ReleaseDC(hConsole, hDC);

  return 0;
}
Sorry, my question wasn't clear enough. I want the pixel coordinates of a mouse click, GetPixel gives the colour at the specified coordinates.
This might be helpful, however it doesn't look easy.
https://docs.microsoft.com/en-us/windows/console/reading-input-buffer-events
Yes, this is what I have already implemented to get the mouse event, that's not the problem, what I can't get are the pixel coordinates.
The MOUSE_EVENT_RECORD gives you the mouse position in character-cell coordinates.
Maybe get the width of the console window in pixels and divide by number of characters.

Consider to create a normal Windows app for this.
The console is not meant for this and everything is far more complicated.
Indeed that's what I ended up doing. It does seem strange that the API supports writing at pixel resolution but not reading. Oh well.
closed account (E0p9LyTq)
The Windows API does support reading mouse click location, just use the HIWORD and LOWORD of the lparam parameter supplied to the window's WndProc() when you handle a mouse message.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms645607(v=vs.85).aspx
Topic archived. No new replies allowed.