双屏条件下使用窗口全屏,窗口被夹在双屏中间怎么办?

sss10040 2016-07-13 10:50:48

声明太多就不都贴了,这些都是网上找的代码
代码如下
public enum appStyle {
FullScreen = 0,
WindowedFullScreen = 1,
Windowed = 2,
WindowedWithoutBorder = 3,
}
public appStyle AppWindowStyle = appStyle.WindowedFullScreen;

public enum zDepth {
Normal = 0,
Top = 1,
TopMost = 2,
}
public zDepth ScreenDepth = zDepth.Normal;


public int windowLeft = 10;
public int windowTop = 10;

public int windowWidth = 800;
public int windowHeight = 600;

const uint SWP_NOMOVE = 0x0002;
const uint SWP_FRAMECHANGED = 0x0020;
const uint SWP_SHOWWINDOW = 0x0040;

const int GWL_STYLE = -16;
const int WS_BORDER = 1;
private Rect screenPosition;
private const int GWL_EXSTYLE = (-20);
private const int WS_CAPTION = 0xC00000;
private const int WS_POPUP = 0x800000;
IntPtr HWND_TOP = new IntPtr(0);
IntPtr HWND_TOPMOST = new IntPtr(-1);
IntPtr HWND_NORMAL = new IntPtr(-2);

private const int SM_CXSCREEN = 0x00000000;
private const int SM_CYSCREEN = 0x00000001;

int Xscreen;
int Yscreen;

void Start ()
{

Xscreen = (int)GetSystemMetrics(SM_CXSCREEN);
Yscreen = (int)GetSystemMetrics(SM_CYSCREEN);

//这种情况
if((int)AppWindowStyle == 1)
{
Screen.SetResolution(Xscreen-1,Yscreen-60,false);
screenPosition = new Rect(0,0,Xscreen-1,Yscreen-1);
}

}


int i = 0;
void Update () {

//然后我不明白为什么要在Update设置,直接在Start设置不好吗?
//我调了很多参数发现都改不了窗口的位置,而且我的目的是在单屏情况和双屏情况都窗口全屏显示在第一个屏幕上
if (i < 5)
{
if ((int)AppWindowStyle == 1)
{
if ((int)ScreenDepth == 2)
SetWindowPos(GetForegroundWindow(), HWND_TOPMOST, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
ShowWindow(GetForegroundWindow(), 3);
}
}
i++;

}
...全文
1596 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yellowlongriver 2016-10-26
  • 打赏
  • 举报
回复
没遇到过,请检查你的窗口是否最大化了,还是指定了大小。另外再注意一个Form的属性:Position,当值是poDesktopCenter,而且窗口不是最大化就会出现你这种情况。 poScreenCenter:在某个显示器中央 poDesktopCenter:在多个显示器组成的大桌面的中央
xxfly 2016-07-13
  • 打赏
  • 举报
回复
一直用双屏,还没有遇到过这种情况,你新建个工程,不写一行代码试试。 实在不行判断全屏时,设置self.Left=0

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧