最近一網友要戒QQ,要我寫個程序幫他把QQ戒了,昨天一天搞定了,裡面有點有用的東西拿出來 如果覺得我很菜不要罵我 :E
主要思路:
FindWindow -> "發送消息" "查看消息"
修改QQ的Button,Static,Edit控件
修改注冊表,讓其自動運行
具體代碼如下:char buttoncaption[4][20]={
"聊天記錄(&H)",
"對話模式(&T)",
"取消發送(&C)",
"送訊息(&S)"
};
HWND WndHandle;
HWND WndEdit;
HWND static_c[11];//static 的hwnd,因為很多不確定設了11個
HWND button_c[6];//Button的Hwnd 查看消息4個發送消息6個 所以取6個
WndHandle = ::FindWindow(NULL, "查看消息");
::SetWindowText( WndHandle, "聊天真的很痛苦的呀");
if( WndHandle != NULL){
/////////開始搞定Edit////////////////////
WndEdit = ::FindWindowEx( WndHandle,NULL,"Edit","");
類名 Caption
::EnableWindow( WndEdit, false );
/////////Edit被搞定/////////////////////
//////////開始搞定Button//////////
for( int i = 0; i < 4; i++ ){
button_c[i] = FindWindowEx(WndHandle,NULL,"Button",buttoncaption[i]);
}
for( i = 0; i < 4; i++ ){
::EnableWindow( button_c[i],false);
}
//////////Button±被搞定///////////
/////////開始搞定Static/////////////
static_c[0] = NULL;
int n=0;
for( i = 1; i < 11; i++ ){
static_c[i] = FindWindowEx( WndHandle,static_c[i-1],"Static",NULL);
//發現第二個參數為NULL時,FindWindowEx會返回一樣的值,所以以上次取的Hwnd為參數
//可以獲得所有Static的HWND
}
for( i = 1; i < 11; i++ ){
char caption[100];
::GetWindowText( static_c[i],caption,100);
if( strcmp(caption,"QQ#:") != 0 &&
strcmp(caption,"昵稱:") != 0 &&
strcmp(caption,"Email:") != 0 &&
strcmp(caption,"按ctrl + 回車鍵發送消息") != 0 ){
static_index[n++] = i;
}
//把不要修改的剔除掉
}
for( i = 1; i <= 4; i++ ){
int index = static_index[i-1];
if( index < 0 || index > 10)
continue;
int dlgindex = ::GetDlgCtrlID( static_c[index] );
::SetDlgItemText( WndHandle,dlgindex,s[i-1]);
}
::InvalidateRect( WndHandle,NULL,false);
for( i = 1; i <= 4; i++ ){
::UpdateWindow( static_c[static_index[i-1]] );
}
//////////Static±?被搞定///////////////////
}
修改注冊表如下:
char path[50]; ::GetCurrentDirectory(50,path); strcat(path,"\\戒掉qq聊天的壞習慣.exe"); LPBYTE path_set = pchar_To_LPBYTE( path ); DWORD type = REG_SZ; DWORD cbdata = strlen(path)+1; HKEY hkey; LPCTSTR data_set = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\"; long ret_0 = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, data_set, 0, KEY_ALL_ACCESS, &hkey); long ret_1 = ::RegSetValueEx( hkey, "BadQQ", 0, type, path_set, cbdata ); ::RegCloseKey( hkey ); LPBYTE CShitDlg::pchar_To_LPBYTE( char* str) { LPBYTE lpb=new BYTE[strlen(str)+1]; for(int i=0; i < strlen(str);i++) lpb[i]=str[i]; lpb[strlen(str)]=0; return lpb; }
(全文完)
本文配套源碼