关闭QQ右下角弹出的广告或新闻等。
程序没有界面,后台运行。
1 #if defined(UNICODE) && !defined(_UNICODE) 2 #define _UNICODE 3 #elif defined(_UNICODE) && !defined(UNICODE) 4 #define UNICODE 5 #endif 6 7 #include <tchar.h> 8 #include <windows.h> 9 10 #include <iostream> 11 #include <stdio.h> 12 #include <windows.h> 13 #include <vector> 14 #include <time.h> 15 //#include <afxwin.h> 16 using namespace std; 17 18 19 20 /* Declare Windows procedure */ 21 LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); 22 23 /* Make the class name into a global variable */ 24 TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp"); 25 26 27 char* tmp=new char[32]; 28 LPTSTR s=new char[100]; 29 30 char* gettime(){ 31 time_t t = time(0); 32 strftime(tmp, 32, "%Y-%m-%d %H:%M:%S",localtime(&t)); 33 return tmp; 34 } 35 char* gettext(HWND hwnd){ 36 GetWindowText(hwnd,s,100); 37 return s; 38 } 39 int print_window(HWND hwnd,long w,long h,FILE* f){ 40 printf("%d (%ld,%ld) %s %s ",(int)hwnd,w,h,gettime(),gettext(hwnd)); 41 fprintf(f,"%d (%ld,%ld) %s %s ",(int)hwnd,w,h,gettime(),gettext(hwnd)); 42 fflush(f); 43 return 0; 44 } 45 int mmain(){ 46 FILE* f=fopen("main_log.txt","a"); 47 cout<<"Start Program."<<endl; 48 fprintf(f," Start Program. "); 49 fflush(f); 50 HWND qhwnd=NULL; 51 while(true){ 52 Sleep(333); 53 HWND QQhwnd = FindWindow("TXGuiFoundation", "QQ");//OrpheusBrowserHost "QQ" 54 if (QQhwnd==NULL){ 55 continue; 56 } 57 if(qhwnd!=QQhwnd){ 58 qhwnd=QQhwnd; 59 printf("%s QQ hwnd is %d ",gettime(),(int)QQhwnd); 60 fprintf(f,"%s QQ hwnd is %d ",gettime(),(int)QQhwnd); 61 fflush(f); 62 } 63 HWND hwnd = FindWindow("TXGuiFoundation", NULL);//OrpheusBrowserHost "QQ" 64 RECT rect; 65 GetWindowRect(hwnd,&rect); 66 long w=rect.right-rect.left,h=rect.bottom-rect.top; 67 //printf("%ld height:%ld ",w,h); 68 if((w==314&&h==210)||(w==314&&h==212)||(w==574&&h==414)||(w==314&&h==208)){ 69 print_window(hwnd,w,h,f); 70 SendMessage(hwnd,WM_CLOSE,0,0); 71 //DestroyWindow(hwnd); 72 } 73 } 74 delete []s; 75 delete []tmp; 76 return 0; 77 } 78 79 80 81 82 int WINAPI WinMain (HINSTANCE hThisInstance, 83 HINSTANCE hPrevInstance, 84 LPSTR lpszArgument, 85 int nCmdShow) 86 { 87 mmain(); 88 return 0; 89 } 90 91 92 /* This function is called by the Windows function DispatchMessage() */ 93 94 LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 95 { 96 switch (message) /* handle the messages */ 97 { 98 case WM_DESTROY: 99 PostQuitMessage (0); /* send a WM_QUIT to the message queue */ 100 break; 101 default: /* for messages that we don't deal with */ 102 return DefWindowProc (hwnd, message, wParam, lParam); 103 } 104 105 return 0; 106 }
2017年3月底写