为什么程序有时候没有反应?
写了个多显示器应用程序,窗口的配置信息写在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;
}