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); //这一句需要么,应该不需要?应该不可能关得掉的
char title[MAX_PATH]={0};
GetWindowText(Focus, title, sizeof(title));
if (strcmp(title,"")==0) //与if(strlen(title)==0)相比哪一句的效率高些?好像是strcmp
{
printf("空");
}
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
{
printf kong
}
用 title[0]=0;更高效。
然后就是如jennyvenus在二楼的代码或者:
if(!title[0])呵呵
HWND Focus=GetForegroundWindow();
char title[MAX_PATH];
*title=0;if( !GetWindowText(Focus, title, sizeof(title)) )
{
printf("空");
}