Windows API から監視データを取得しようとしています。このGetSystemMetrics()
コマンドは、間違った幅をピクセル単位で返します。MicrosoftのWebサイトによると、これは私がする必要があるためですSetProcessDPIAware()
つまり、理解できないアプリケーション マニフェストを作成できることが望ましいということです。
同様に低レベルの代替手段を探していたところ、複数のディスプレイ モニターの関数と構造体が見つかりました。HMONITOR
必要な rect 構造にアクセスするにはパスする必要がありHMONITOR
ますが、問題が発生しているのは取得です。
MonitorFromWindow(hwnd,MONITOR_DEFAULTTOPRIMARY)
GetMonitorInfo()
このコマンドは範囲外です - [私が必要HMONITOR
としている] は何の問題も引き起こさない
ので奇妙です。私はすでに持っていてwindows.h
含まwindowsx.h
れています。ライブラリがありませんか、それとも何が問題なのですか?
余談ですが、そちらを見てみると、使用するモニターをユーザーが調整できるようにするのもいいかもしれないということがわかりました。 カウントを返す必要がありますが、これらの数値をモニター固有の情報を取得するために必要なデータにSM_CMONITORS
変換する方法を知りたいです。HMONITOR
::編集::
「コメント」機能では、要求されたコード クリップを配置するのに十分なスペースが提供されないため、ここに編集を入れています。
また、MinGWでGNU GCCを使用しています
#include <iostream>//using these libraries
#include <Windowsx.h>
#include <windows.h>
using namespace std;
int main()
{
//should print screen width in pixels
LPMONITORINFO target;
//create a monitor info struct to store the data to
HMONITOR Hmon = MonitorFromWindow(hwnd,MONITOR_DEFAULTTOPRIMARY);
//create a handle to the main monitor
//(should start at top left of screen with (0,0) as apposed to other monitors i believe)
//if i could gather aditional info on what monitors are available that might be useful
GetMonitorInfo(Hmon, target);
//Get the necessary data and store it to target
cout << "bottom of selected monitor in pixels: " << target->rcMonitor.bottom
<< "Top of the selected monitor" << target->rcMonitor.top
<< "right extreme of selected monitor" << target->rcMonitor.right
<< "left extreme of selected monitor" << target->rcMonitor.left;
return 0;
}