S
swangbit
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个应用程序,使用BCB控制子窗体实现双屏显示。我按照论坛的提示,做了一个例子,但只能使主窗体和子窗体都显示在同一个显示器上,代码如下,请高人帮我指点指点:
//---------------------------------------------------------------------------
/*使用该方法可以是两个form都显示在副显示器上,如果去除蓝色部分,则两个窗体都显示在主显示器上,但我想实现的是form1显示在主显示器上,form2显示在副显示器上*/
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
USEFORM("Unit2.cpp", Form2);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TForm2), &Form2);
[blue]int mleft,mtop;
if(Form2->GetWorkArea(&mleft,&mtop))
{
Form2->Left=mleft;
Form2->Top=mtop;
Form2->Show();
Sleep(3000);
}[/blue]
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception(""
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//获取第二显示器的工作区域
bool TForm1::GetWorkArea(int *mleft,int *mtop)
{
TRect R;
for (int i=0;i<Screen->MonitorCount;i++)
{
if (!Screen->Monitors->Primary)
{
R= Screen->Monitors->WorkareaRect;
*mleft=R.Left;
*mtop=R.Top;
return true;
}
}
return false;
}
//-----------------------------------------------------------------
//显示form2,form2是一个简单窗体
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int mleft,mtop;
if(GetWorkArea(&mleft,&mtop))
{
Form2->Left=mleft;
//---------------------------------------------------------------------------
/*使用该方法可以是两个form都显示在副显示器上,如果去除蓝色部分,则两个窗体都显示在主显示器上,但我想实现的是form1显示在主显示器上,form2显示在副显示器上*/
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
USEFORM("Unit2.cpp", Form2);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TForm2), &Form2);
[blue]int mleft,mtop;
if(Form2->GetWorkArea(&mleft,&mtop))
{
Form2->Left=mleft;
Form2->Top=mtop;
Form2->Show();
Sleep(3000);
}[/blue]
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception(""
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//获取第二显示器的工作区域
bool TForm1::GetWorkArea(int *mleft,int *mtop)
{
TRect R;
for (int i=0;i<Screen->MonitorCount;i++)
{
if (!Screen->Monitors->Primary)
{
R= Screen->Monitors->WorkareaRect;
*mleft=R.Left;
*mtop=R.Top;
return true;
}
}
return false;
}
//-----------------------------------------------------------------
//显示form2,form2是一个简单窗体
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int mleft,mtop;
if(GetWorkArea(&mleft,&mtop))
{
Form2->Left=mleft;