typedef BOOL ( __stdcall * pEnumDiaplayDevices )( LPCTSTR lpDevice, // device name
DWORD iDevNum, // display device
PDISPLAY_DEVICE lpDisplayDevice, // device information
DWORD dwFlags // reserved
);
int GetScreenRect( int ScreenNo, RECT *rect )
{
pEnumDiaplayDevices xenum;
BOOL flag;
DISPLAY_DEVICE dd;
ZeroMemory( &dd, sizeof( dd ) );
dd.cb = sizeof( dd );
HMODULE hhh = LoadLibrary( _T( "user32.dll" ) );
if( hhh )
{
xenum = ( pEnumDiaplayDevices )GetProcAddress( hhh, "EnumDisplayDevicesW" );
}
if( !xenum )
{
FreeLibrary( hhh );
return 1;
}
//flag = EnumDisplayDevices( NULL, ScreenNo, &dd, 0 );
flag = xenum( NULL, ScreenNo, &dd, 0 );
if( !flag )
{
FreeLibrary( hhh );
return 1;
}
DEVMODE dm;
ZeroMemory( &dm, sizeof( dm ) );
dm.dmSize = sizeof( dm );
flag = EnumDisplaySettings( dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm );
rect->left = dm.dmPosition.x;
rect->top = dm.dmPosition.y;
rect->right = dm.dmPelsWidth;
rect->bottom = dm.dmPelsHeight;
FreeLibrary( hhh );
return 0;
}
void Ctmfc1Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
//ClipOrCenterWindowToMonitor( m_hWnd, MONITOR_CENTER );
RECT rec;
int result = GetScreenRect( 1, &rec );
// if( rec.left == rec.right )
{
// 没找到第二显示器,随便判断一下,不严格
MoveWindow( &rec );
CenterWindow();
ModifyStyle(WS_CAPTION,0,0);
MoveWindow(rec.left, 0, rec.right, rec.bottom );
}
}