Win32API の MonitorFromPoint と GetMonitorInfo を使用すると実現できるようです
スペースキーを押すとウインドウがモニターの左上端に移動するというサンプルを
作成してみましたので、よろしければご覧ください m(_ _)m
#include "DxLib.h"
// 指定のデスクトップ座標のモニターの左上座標を取得する
void GetMonitorLeftTopPos( int DesktopX, int DesktopY, int *MonitorLeftX, int *MonitorTopY )
{
HMONITOR hMonitor ;
MONITORINFOEX MonitorInfoEx ;
POINT point ;
// DesktopX, DesktopY の座標のモニターのハンドルを取得する
point.x = DesktopX ;
point.y = DesktopY ;
hMonitor = MonitorFromPoint( point, MONITOR_DEFAULTTONEAREST ) ;
// モニター情報を取得する
MonitorInfoEx.cbSize = sizeof( MonitorInfoEx ) ;
GetMonitorInfo( hMonitor, &MonitorInfoEx ) ;
// モニターのデスクトップでの左上座標を代入する
*MonitorLeftX = MonitorInfoEx.rcMonitor.left ;
*MonitorTopY = MonitorInfoEx.rcMonitor.top ;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ChangeWindowMode( TRUE ) ;
if( DxLib_Init() < 0 )
{
return -1 ;
}
SetDrawScreen( DX_SCREEN_BACK ) ;
while( ProcessMessage() == 0 )
{
ClearDrawScreen() ;
DrawString( 0, 0, "スペースキーを押すとモニターの左上座標にウインドウを移動します", GetColor( 255,255,255 ) ) ;
// スペースキーが押されたら分岐
if( GetInputChar( TRUE ) == ' ' )
{
int MonitorLeftX, MonitorTopY ;
int WinPosX, WinPosY ;
// ウインドウの座標を取得
GetWindowPosition( &WinPosX, &WinPosY ) ;
// ウインドウがあるモニターの左上座標を取得
GetMonitorLeftTopPos( WinPosX, WinPosY, &MonitorLeftX, &MonitorTopY ) ;
// ウインドウの位置をモニターの左上座標に移動
SetWindowPosition( MonitorLeftX, MonitorTopY ) ;
}
ScreenFlip() ;
}
DxLib_End();
return 0;
}