为什么程序有时候没有反应?

ravehe ravehe 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了个多显示器应用程序,窗口的配置信息写在INI文件中,程序可以进行窗口显示位置的设置,但是不知道为什么在设置的时候,程序经常没有反应,好像死掉一样。。。。。。
代码如下:







void TForm1::MultiMonitor(HWND Handle,String DClass,int Value,int Top,int Left,String opertype)
{
String Filename;
int Index,Top1,Left1,MoniCount;
int result;
Filename=ExtractFileDir(Application->ExeName)+"\\MultiMonitor.ini";
TIniFile *ini = new TIniFile(Filename);
//显示器数目
MoniCount=Screen->MonitorCount;
//保存窗口设置信息
if(opertype=="W")
{
if((Value>0)&&(Value<=MoniCount))
{
Left1 = Left - Monitor->Left;//本窗口调用此行没有问题,其他窗口调用出现地址错
Top1 = Top - Monitor->Top;//错误同上

Left1 = Left + Screen->Monitors[Value - 1]->Left;
Top1 = Top + Screen->Monitors[Value - 1]->Top;
try
{
ini->WriteString(DClass,"MonitorIndex",Value);
ini->WriteString(DClass,"Top",Top1);
ini->WriteString(DClass,"Left",Left1);
Application->MessageBoxA("ok","success" MB_OK);
SetWindowPos(Handle,HWND_TOPMOST,Top1,Left1,0,0,SWP_NOSIZE);

}
catch(...)
{
Application->MessageBoxA("error!","fail",MB_OK+16);
}
}
delete ini;
}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
ravehe
C++ Builder 13,871 成员 102,696 内容