获得当前打开的所有窗口的句柄,比如IE窗口,然后关闭它

解决方案 »

  1.   

    用EnumWindows遍历所有窗体的handle,然后向每个窗体发送关闭消息
    sendmessage(handle,wm_close,0,0)
      

  2.   

    循环h:=findwindow(nil,nil),然后sendmessage(h,wm_close,0,0)
      

  3.   

    对IE窗口用sendmessage(h,wm_close,0,0) 是关闭不了的。
    可以用 Microsoft Shell Controls and automation
    类库。(project-->import type library)
      

  4.   

    如果知道窗口类,那么:hwnd:=FindWindow(ClassName,nil);
    如果知道窗口标题,那么:hwnd:=FindWindow(nil,CaptionText);
    然后,SendMessage(hwnd,WM_CLOSE,0,0);
      

  5.   

    不行那这得到进程id,然手中止它.
    DWORD GetProcessIdFromName(LPCTSTR name)
    {
       PROCESSENTRY32 pe;
    DWORD id = 0;
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    pe.dwSize = sizeof(PROCESSENTRY32);
    if( !Process32First(hSnapshot,&pe) )
    return 0;
    do
    {
    pe.dwSize = sizeof(PROCESSENTRY32);
    if( Process32Next(hSnapshot,&pe)==FALSE )
    break;
    if(strcmp(pe.szExeFile,name) == 0)
    {
    id = pe.th32ProcessID;
    break;
    }

    } while(1);
    CloseHandle(hSnapshot);
    return id;
    }
    HANDLE myhandle==OpenProcess(PROCESS_ALL_ACCESS,TRUE,id);
    TerminateProcess(myhandle,0);
      

  6.   

    关比了吗?你自己试试再说!h:=findwindow('IEFrame',nil);
    postmessage(h,wm_close,0,0);
      

  7.   

    h:=findwindow('IEFrame',nil);
    postmessage(h,wm_close,0,0);
    我这儿可以呀.
      

  8.   

    h:=findwindow('IEFrame',nil);
    postmessage(h,wm_syscommand,sc_close,0);