手工麻烦!我开始着手写个软件自动找链接地址,有兴趣的朋友给些意见,以下是小样的代码:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
SendMessage(this->ListBox1->Handle,LB_SETHORIZONTALEXTENT,500,0);
LPDEVMODE lpmode;
WinX=GetSystemMetrics(SM_CXSCREEN);
WinY=GetSystemMetrics(SM_CYSCREEN);//获得显示模式1024 OR 800
Form1->Left=WinX-Form1->Width;
Form1->Top=WinY-30-Form1->Height;
long lRt=GetWindowLong(Handle,GWL_EXSTYLE);
lRt=lRt|WS_EX_LAYERED;
SetWindowLong(Handle,GWL_EXSTYLE,lRt);
SetLayeredWindowAttributes(Handle,clBlue,200,LWA_ALPHA);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(TMessage& Message)
{
switch(Message.Msg)
{
/*在窗口移动之前,判断窗口新位置的Top值是否在磁性范围内,如果在,让它归0,
表示不产生窗体移动,避免在磁性范围内移动窗口的时候窗口过于闪烁*/
case WM_WINDOWPOSCHANGING:
if ((LPWINDOWPOS(Message.LParam))->y<50)
(LPWINDOWPOS(Message.LParam))->y=0;
if ((LPWINDOWPOS(Message.LParam))->x>(WinX-56-Form1->Width))
(LPWINDOWPOS(Message.LParam))->x=WinX-Form1->Width;
break;
default:
break;
}
TForm::WndProc(Message);
}
//==============
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
POINT* pMyPoint=new POINT;
GetCursorPos(pMyPoint);
if(
(pMyPoint->x>Form1->Left)&&(pMyPoint->x<(Form1->Left+Form1->Width))&&
(pMyPoint->y>Form1->Top)&&(pMyPoint->y<(Form1->Top+Form1->Height))
)
{
Form1->Show();
}
else
{
if(Form1->Left>(WinX-10)-Form1->Width||Form1->Top<10)
{Form1->Hide();}
}
delete pMyPoint;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::suiButton1Click(TObject *Sender)
{
Label2->Caption="正在获取,获取速度视网速快慢!请等待!";
suiButton1->Enabled=false;
Label2->Caption=URL();
if(MusicURL()=="浏览器没有运行!"){return;}
else if(MusicURL()!=""){this->ListBox1->Items->Insert(0,MusicURL());}
else{suiEdit1->Text="";}
suiEdit1->Text=MusicURL();
suiButton1->Enabled=true;
}
//---------------------------------------------------------------------------
AnsiString TForm1::URL()
{
AnsiString URL1,URL2,URL3="浏览器没有运行!";
if(DdeClientConv1->SetLink("IExplore","WWW_GetWindowInfo"))
{
DdeClientConv1->OpenLink();
URL1=DdeClientConv1->RequestData("-1");
URL2=URL1.SubString(2,URL1.Pos(",")-3);
DdeClientConv1->CloseLink();
return URL2;
}
else
{
return URL3;
}
}
//=====================================
AnsiString TForm1::MusicURL()
{ //查找音乐源
try{
AnsiString str,str1;
AnsiString URLstr=this->IdHTTP1->Get(Label2->Caption);
if(URLstr.Pos(".mp3")>10)
{
str1=URLstr.SubString(URLstr.Pos(".mp3")-100,104);
str=str1.SubString(str1.Pos("http://"),str1.Pos(".mp3")-str1.Pos("http://")+4);
}
else if(URLstr.Pos(".wma")>10)
{
str1=URLstr.SubString(URLstr.Pos(".wma")-100,104);
str=str1.SubString(str1.Pos("http://"),str1.Pos(".wma")-str1.Pos("http://")+4);
}
return str;
}
catch(...){Label2->Caption="未能连接!";return 0;}
}
//=====================================
void __fastcall TForm1::N1Click(TObject *Sender)
{
// 读数据
// if (Clipboard()->HasFormat(CF_TEXT))
// AnsiString Text=Clipboard()->AsText;
// 写数据
char *Text=ListBox1->Items->Strings[ListBox1->ItemIndex].c_str();
Clipboard()->SetTextBuf(Text);
delete Text;
}
//---------------------------------------------------------------------------