5

I'm trying to get the border thickness of a console app.

So far, I've got the value from the GetSystemMetrics of the user32 dll with the SM_CXSIZEFRAME/SM_CYSIZEFRAME value.

In a winform application, it return the right value (9), however, in a console app, it return 4.

I can's see how a system metric change between those 2 calls.

Is there something specific to do in a console app ?

Remy Grandin
  • 1,638
  • 1
  • 14
  • 34
  • Checked [this](https://social.msdn.microsoft.com/Forums/en-US/53d5433f-1384-4b73-97d8-580a861c1caa/why-getsystemmetricssmcxsizeframe-returns-4-in-my-windows-7) yet, or [this](https://social.msdn.microsoft.com/Forums/vstudio/en-US/a910e656-5829-4e5e-8adb-54cfac088a9f/problem-with-system-metrics-smcxsizeframe-smcxpaddedborder-in-windows-10-preview-build-10041)? Console windows use a different style, and the "system" in the name notwithstanding, it's far from the first time Windows selectively changes its answers based on the application it's talking to (for compat and other reasons). – Jeroen Mostert Dec 06 '18 at 14:16
  • 2
    The million dollar question would probably be why you've got a call like this in a console app. Console applications aren't supposed to know or do anything about the window hosting them (which is in any case living in `conhost.exe`, separate from you), and asking questions about windows in an application that's not supposed to use any is suspect, to say the least. One possible workaround, depending on what it is you're doing, is to use an actual GUI application that uses `AllocConsole()` if it does need a console for some reason. – Jeroen Mostert Dec 06 '18 at 14:20
  • 1
    You get small lies, big lies or damn lies about border size, the fat borders that were introduced at Vista and Aero are a big honking appcompat problem. A value of 4 is expected in any scenario where it tries to emulate the way a window looked in the olden days. 9 is too wonky, 8 is normal. Bigger issues at Win10 where a window has just a single pixel border and the drag area is transparent. I don't think you can stop GetSystemMetrics() from lying in a console app, but you can make GetWindowRect() vs GetClientRect() behave. Ensure the app is dpiAware and targets at least 4.5 – Hans Passant Dec 06 '18 at 17:18
  • @JeroenMostert : To add some context, I'm developping a console GUI framework (https://github.com/remygrandin/CLIForms) and I wanted to try to add mouse support, just because It would be cool feature to have for those who don't want to navigate via keyboard only. Currently, I have figurred out how to get my mouse coordinate relative to the top left origin of the window, I just need to add the border to get the real 0,0 of the console area. – Remy Grandin Dec 07 '18 at 06:59
  • 1
    @RemyGrandin If you want the mouse position and row/column is precise enough, this post might be what you are looking for: [link](https://stackoverflow.com/a/29971246/6764710) – Yosh Dec 12 '18 at 14:12
  • @yosh : that totally what i'm looking for, thank you so much ! – Remy Grandin Dec 20 '18 at 09:44

0 Answers0