C ++控制台应用程序总是在顶部? [英] C++ console application always on top?

查看:245
本文介绍了C ++控制台应用程序总是在顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找:




  • 使

  • 制作任何类型的GUI - 对话框等...顶部



但我正在寻找一种如何使我的简单C ++ 控制台总是在顶部,

只是为了清楚 - 我正在寻找一种方法如何做这个程序性的:)我试着努力搜索,但只找到了上述 - 我不想要的...



因此,有什么方法可以让控制台应用程序总是在 Windows 上的C ++程序中运行吗?



PS:是否存在问题与对应的标题,但该问题的OP实际上正在寻找别的东西(键盘钩子,...) - 所以答案有对我的问题。 >

解决方案:



快速回答 =>请参阅由@AlexanderVX接受的回答



示例&解释 => 我的回答


解决方案

OP文章中的链接指的是Windows。



以获取控制台窗口的句柄:
https://support.microsoft.com/kb/ 124103



或更好更现代: GetConsoleWindow 获取控制台句柄。



然后你需要做一个简单的技巧:

  :: SetWindowPos(hwndMyWnd,HWND_TOPMOST,0,0,0,0,SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 
:: ShowWindow(hwndMyWnd,SW_NORMAL);


I am NOT looking for:

  • making another window always on top
  • making any sort of GUI - dialogs etc... on top

I am however looking for a way how to make my simple C++ console application to stay always on top,
just to be clear - I am looking for a way how to do this programaticly :) I tried hard searching but only found the above - what I do not want...

So is there a way how to make your console app always on top programaticly in C++ on Windows?

PS: Yes there is an existing question with a coresponding title but the OP of that question is actually looking for something else (keyboard hooks,...) - so answers there are off-topic to my question.

Solution:

Quick answer => see accepted answer by @AlexanderVX

Example & explanation => my answer below

解决方案

The link in OP post refers to Windows.

First you need to obtain a handle for your console window: https://support.microsoft.com/kb/124103

Or even better and modern: GetConsoleWindow way to get that console handle.

Then you need to do quite a simple trick:

::SetWindowPos(hwndMyWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
::ShowWindow(hwndMyWnd, SW_NORMAL);

这篇关于C ++控制台应用程序总是在顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆