在公司裏寫的一個自動啓動Notes的小程序

/**********************************************************************
 此函數用於傳入一個完整路徑來啓動程序
***********************************************************************/

int CStartAllDlg::StartProcess(char *szPath)
{
 STARTUPINFO si;
    PROCESS_INFORMATION pi;
 
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
 
    // Start the child process.
    if( !CreateProcess( NULL, // No module name (use command line).
        szPath, // Command line.
        NULL,             // Process handle not inheritable.
        NULL,             // Thread handle not inheritable.
        FALSE,            // Set handle inheritance to FALSE.
        0,                // No creation flags.
        NULL,             // Use parent's environment block.
        NULL,             // Use parent's starting directory.
        &si,              // Pointer to STARTUPINFO structure.
        &pi )             // Pointer to PROCESS_INFORMATION structure.
  )
    {
  return -1;
    }
 
    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
    return 0;
}

 

 

#define ZTE_NOTES_PATH   "C://Program Files//lotus//notes//notes"

#define ZTE_NOTES_PSWD  "your pwd"

 

/**********************************************************************
 此函數用於傳入一個完整路徑來啓動程序
***********************************************************************/

void CStartAllDlg::OnNotes()
{
 // TODO: Add your control notification handler code here
 HWND pHandle;
 HWND cHandle;
 int  count;
 
 StartProcess(ZTE_NOTES_PATH);
    /* Note啓時間20秒 */
 count = 400;
 do
 {
  Sleep(50);
  pHandle = ::FindWindow(NULL, "Lotus Notes");
  cHandle = ::FindWindowEx(pHandle, NULL, "IRIS.password", NULL);
  count--;
 } while((pHandle == 0 || cHandle == 0) && count);

 if (pHandle == 0 || cHandle == 0)
 {
  return;
 }
 
 ::SendMessage(cHandle, WM_SETTEXT, NULL, (long)ZTE_NOTES_PSWD);
 cHandle = FindWindowEx(pHandle, NULL, NULL, "確定");
 ::SendMessage(cHandle, BM_CLICK, NULL, NULL);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章