2010年8月16日 星期一

避免打開雙視窗

#include <windows.h>

#define Executable "test.exe"
char TITLE[] = "The SoftW";//full title name "The SoftWare"
int size;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, DWORD lParam)
{
//get hwnd title
char buffer[255];
SendMessage(hwnd,WM_GETTEXT,255,(long)buffer);

//check title is we want
if(strncmp(buffer,TITLE,size)==0)
{
//if window is iconic, show it as normal
if(IsIconic(hwnd))
ShowWindow(hwnd, SW_RESTORE);

//show it at top of desktop
SetForegroundWindow(hwnd);

//we got it
return FALSE;
}

//to check next hwnd
return TRUE;
}

int main(int argc, char** argv)
{
//check title size,remove '\0'
size = sizeof(TITLE)/sizeof(char);
size--;

//check window is show or not
if(EnumWindows((WNDENUMPROC)EnumWindowsProc,0)==TRUE)
{
//if window not show, to execute it
WinExec(Executable,SW_SHOW);
}

return 0;
}

沒有留言: