properwu 您好: 您可以試著把Modem狀態顯示於StatusBar Panel上,如果你要更美觀可以參考
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=34821 的方法,把Modem的狀態改用燈號顯示 試試這個方法是不是你要的結果:
Unit1.cpp
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
detect();
}
//--------------------------------------------------------------------------- void __fastcall TForm1::detect()
{
AnsiString ComPort="COM1";
bool GetModemStatus=false;
int i=1;
HANDLE hCommDev;
LPCOMMPROP lpCommProp=new COMMPROP;
do
{
hCommDev= CreateFile(ComPort.c_str(),
GENERIC_WRITE,0,NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0); if(GetCommProperties(hCommDev,lpCommProp)){
if(lpCommProp->dwProvSubType==PST_MODEM){
GetModemStatus=true;
}
}
CloseHandle(hCommDev);
i ;
} while(i<=4); if(GetModemStatus)
StatusBar1->Panels->Items[2]->Text="偵測Modem連接於 " ComPort;
else
StatusBar1->Panels->Items[2]->Text="未偵測到任何MODEM於系統上!";
}
//--------------------------------------------------------------------- Unit1.h
//--------------------------------------------------------------------------- #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TStatusBar *StatusBar1;
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall detect();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
/*開心的事情別隱藏在心裡,分享給別人知道會更快樂的*/
/*得到新知識別隱藏在心裡,分享給別人了解會更清楚的*/
發表人 - axsoft 於 2003/09/02 19:12:37