HWND Focus=GetForegroundWindow();
char title[MAX_PATH]={0};
GetWindowText(Focus, title, sizeof(title));
if (strcmp(title,"")==0)           //与if(strlen(title)==0)相比哪一句的效率高些?好像是strcmp
{
printf("空");
}
CloseHandle(Focus);                  //这一句需要么,应该不需要?应该不可能关得掉的

解决方案 »

  1.   

    不需要CloseHandle(Focus).
    看MSDN:The CloseHandle function closes handles to the following objects:Access token 
    Communications device 
    Console input 
    Console screen buffer 
    Event 
    File 
    File mapping 
    Job 
    Mailslot 
    Memory resource notification 
    Mutex 
    Named pipe 
    Pipe 
    Process 
    Semaphore 
    Socket 
    Thread 
    Waitable timer 
      

  2.   

    if( !*title )
    {
       printf  kong
    }
      

  3.   

    char title[MAX_PATH]={0};//实际上用的是memset(title, 0, max_path),
    用 title[0]=0;更高效。
    然后就是如jennyvenus在二楼的代码或者:
    if(!title[0])呵呵
      

  4.   

    strcmp比较的少.肯定高效..计算长度会会字符串整个走一下的.
      

  5.   


    HWND Focus=GetForegroundWindow();
    char title[MAX_PATH];
    *title=0;if( !GetWindowText(Focus, title, sizeof(title)) )
    {
    printf("空");
    }
      

  6.   

    strcmp效率高,当它遇到一个不匹配的支付就退出了,strlen需要把字符串走完。