我想把輸入到寫字板的信息轉到我的程序中來,代碼如下:
STARTUPINFO si;
PROCESS_INFORMATION pi;
HWND hNotepad;
DWORD ID1, ID2;memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
LPTSTR lpszPath = TEXT("NOTEPAD.EXE");
CreateProcess(NULL, lpszPath, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
hNotepad = ::FindWindow("Notepad", NULL);ID1 = GetWindowThreadProcessId(hNotepad, NULL);
ID2 = GetCurrentThreadId();ASSERT( AttachThreadInput(ID1, ID2, true) != 0 ); //斷言錯誤通過GetLastError()得到的信息是無效的窗口句柄

解决方案 »

  1.   

    在BOOL CAutoshutDlg::OnInitDialog()后面this->PostMessage(SW_HIDE);重载LRESULT CAutoshutDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) LRESULT CAutoshutDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
    switch(message)
    {
    case SW_HIDE:
    ShowWindow(SW_HIDE);
    break;
    ...
      

  2.   

    把hNotepad = ::FindWindow("Notepad", NULL);改为hNotepad = 0;
    while(!hNotepad)
    {
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }

    hNotepad = ::FindWindow("Notepad", NULL);
    }因为CreateProcess之后窗口并不一定立即就出现