91vpn 控制模块

来源:互联网 发布:sql根据条件删除数据 编辑:程序博客网 时间:2024/04/27 14:39

91vpn程序不能被控制,只能手动,所以增加了一些控制代码

实现了断开,连接,自动切换见代码

BOOL __stdcall Enum91VpnWindowsProc(HWND hWnd, LPARAM lParam)
{


TCHAR m_strTitle[MAX_PATH];
TCHAR m_strClass[MAX_PATH];
TCHAR m_strDisplay[MAX_PATH*2+10]; 
int controlCode=(int)lParam;
if(::GetWindowLong(hWnd,GWL_STYLE))//& WS_VISIBLE)
{
::GetWindowText(hWnd,m_strTitle,MAX_PATH-1);
::GetClassName(hWnd,m_strClass,MAX_PATH-1);


strcpy(m_strDisplay,m_strTitle);
strcat(m_strDisplay,":[");
strcat(m_strDisplay,m_strClass);
strcat(m_strDisplay,"]");


CString strClass,strTitle;


strClass.Format("%s",m_strClass);
strTitle.Format("%s",m_strTitle);






if(controlCode==0)
{
if(strTitle=="连接" )
{  
if(strClass=="Button")
{
int ID=GetDlgCtrlID(hWnd); 
::PostMessage(hWnd,WM_COMMAND, MAKEWPARAM(ID, BN_CLICKED), NULL);
::PostMessage(hWnd,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );     
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));        
::PostMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0)); 
return TRUE;

}


}
if(controlCode==5)
{
if(strTitle=="测试" )
{  
if(strClass=="Button"&&pDlg->bClickButton==false)
{
pDlg->bClickButton=true;
int ID=GetDlgCtrlID(hWnd); 
::PostMessage(hWnd,WM_COMMAND, MAKEWPARAM(ID, BN_CLICKED), NULL);
::PostMessage(hWnd,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );     
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));        
::PostMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0)); 
return TRUE;

}


}
if(controlCode==6)
{
if(strTitle=="关闭" )
{  
if(strClass=="Button")
{
int ID=GetDlgCtrlID(hWnd); 
::PostMessage(hWnd,WM_COMMAND, MAKEWPARAM(ID, BN_CLICKED), NULL);
Sleep(200);
::PostMessage(hWnd,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );     
Sleep(200);
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));   
Sleep(200);
::PostMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0));  


 


 
return TRUE;

}


}if(controlCode==1)
{
if(strTitle=="断开" )
{  
if(strClass=="Button")
{
int ID=GetDlgCtrlID(hWnd); 
::PostMessage(hWnd,WM_COMMAND, MAKEWPARAM(ID, BN_CLICKED), NULL);
::PostMessage(hWnd,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );     
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));        
::PostMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0)); 
return TRUE;

}


}
if(controlCode==2)
{
if(strClass=="ComboBox")
{
HWND hParent=::GetParent(hWnd);
CString strParent;
int titleLength=strTitle.GetLength();
::GetWindowText(hParent,strParent.GetBufferSetLength(MAX_PATH-1),MAX_PATH-1);


if(strParent=="连接"&&pDlg->b91VpnChangeISDone==false) 
{
RECT rect; 


::GetWindowRect(hWnd,&rect);
CRect cRect(&rect);
int cWidth=cRect.Width();
int cHeight=cRect.Height();
if(cWidth>=160)
{


pDlg->b91VpnChangeISDone=true;
int ID=GetDlgCtrlID(hWnd); 
 

int cbIndex = SendMessage(hWnd, CB_GETCURSEL, 0, 0);  
int   count   =  SendMessage(hWnd, CB_GETCOUNT, 0,0);


CString strCBtext;
SendMessage(hWnd,CB_GETLBTEXT,(WORD)cbIndex,(LONG)strCBtext.GetBufferSetLength(255)); 



pDlg->ShowResult("切换前%s",strCBtext);


bool bFind=false;
for(int i=cbIndex+1;i<count;i++)
{


SendMessage(hWnd,CB_GETLBTEXT,(WORD)i,(LONG)strCBtext.GetBufferSetLength(255)); 
if(strCBtext.Find("联通")!=-1&&strCBtext.Find("辽宁")!=-1)
{
SendMessage(hWnd, CB_SETCURSEL, i, 0);


bFind=true;
pDlg->ShowResult("切换后%s",strCBtext);
break;
}


}
if( bFind==false)
{
for(int i=0;i<count;i++)
{




SendMessage(hWnd,CB_GETLBTEXT,(WORD)cbIndex,(LONG)strCBtext.GetBufferSetLength(255)); 
if(strCBtext.Find("联通")!=-1&&strCBtext.Find("辽宁")!=-1)
{
SendMessage(hWnd, CB_SETCURSEL, cbIndex, 0);


bFind=true;
pDlg->ShowResult("从0切换后%s",strCBtext);
break;
}


}
}

 



 
return TRUE;

}
}



}
if(controlCode==3)
{
if(strClass=="ComboBox")
{
HWND hParent=::GetParent(hWnd);
CString strParent;
int titleLength=strTitle.GetLength();
::GetWindowText(hParent,strParent.GetBufferSetLength(MAX_PATH-1),MAX_PATH-1);




if(strParent=="连接") 
{
RECT rect; 




::GetWindowRect(hWnd,&rect);
CRect cRect(&rect);
int cWidth=cRect.Width();
int cHeight=cRect.Height();
if(cWidth>=160)
{


 




int cbIndex = SendMessage(hWnd, CB_GETCURSEL, 0, 0);  
int   count   =  SendMessage(hWnd, CB_GETCOUNT, 0,0);


CString strCBtext;
SendMessage(hWnd,CB_GETLBTEXT,(WORD)cbIndex,(LONG)strCBtext.GetBufferSetLength(255)); 




 
for(int i=0;i<count;i++)
{


SendMessage(hWnd,CB_GETLBTEXT,(WORD)i,(LONG)strCBtext.GetBufferSetLength(255)); 
pDlg->strArray91Ip.Add(strCBtext);


}
 
return TRUE;

}
}




}


if(controlCode==4)
{
if(strClass=="ComboBox")
{
HWND hParent=::GetParent(hWnd);
CString strParent;
int titleLength=strTitle.GetLength();
::GetWindowText(hParent,strParent.GetBufferSetLength(MAX_PATH-1),MAX_PATH-1);




if(strParent=="连接"&&pDlg->b91VpnChangeISDone==false) 
{
RECT rect; 




::GetWindowRect(hWnd,&rect);
CRect cRect(&rect);
int cWidth=cRect.Width();
int cHeight=cRect.Height();
if(cWidth>=160)
{


pDlg->b91VpnChangeISDone=true;
int ID=GetDlgCtrlID(hWnd); 




int cbIndex = SendMessage(hWnd, CB_GETCURSEL, 0, 0);  
int   count   =  SendMessage(hWnd, CB_GETCOUNT, 0,0);


CString strCBtext;
SendMessage(hWnd,CB_GETLBTEXT,(WORD)cbIndex,(LONG)strCBtext.GetBufferSetLength(255)); 




pDlg->ShowResult("切换前%s",strCBtext);


bool bFind=false;
for(int i=0;i<count;i++)
{


SendMessage(hWnd,CB_GETLBTEXT,(WORD)i,(LONG)strCBtext.GetBufferSetLength(255)); 
if(strCBtext==pDlg->m_currentVPN_Name)
{
SendMessage(hWnd, CB_SETCURSEL, i, 0);


bFind=true;
pDlg->ShowResult("切换后%s",strCBtext);
break;
}


}
 
return TRUE;

}
}




}




::EnumChildWindows(hWnd,Enum91VpnWindowsProc,controlCode);
}
return TRUE;
}

完整代码联系我99596464

原创粉丝点击