locked
how to invoke contacts application from my application RRS feed

  • Question

  • Hi All,
           I Can open contacts application from my application and now I want to enter letter into search filed without user event.How can I send data into search field virtually.
    Friday, October 9, 2009 6:26 AM

Answers

  • WaitForSingleObject (ShExecInfo.hProcess, INFINITE);

    Above code will block the execution as long as the poutlook.exe is running. Replace this with some sleep before sending the keystrokes.

    I tried  the following when Contacts application is active and it works fine.

            keybd_event('A', 0, 0, 0);
            keybd_event('A', 0, KEYEVENTF_KEYUP, 0);

    - Onkar
    http://www.42gears.com
    • Marked as answer by sumanthmara Friday, October 9, 2009 12:51 PM
    Friday, October 9, 2009 11:11 AM
  • Something like the following function should work. Note the input is ascii string. Change it for UNICODE if you need to.

    void SendString(char* pszString)
    {
        while (*pszString != NULL)
        {
            keybd_event(*pszString, 0, 0, 0);
            keybd_event(*pszString, 0, KEYEVENTF_KEYUP, 0);
            pszString++;
        }
    }

    - Onkar





    http://www.42gears.com
    • Marked as answer by sumanthmara Friday, October 9, 2009 12:51 PM
    Friday, October 9, 2009 9:56 AM

All replies

  • 1. Once contacts application is in the foreground, you can use keybd_event to send keystrokes of the text that you want to input. By default they will go to the search field.

    Or

    2. You can find the edit control window where you want to input the text and then use SetWindowText() API to input the search text. Use Spy++ to find out the search edit control windows handle. I found the following on WM 6.1

    MSContactsUI -> ToolbarWindow32 -> Edit

    - Onkar

    http://www.42gears.com
    Friday, October 9, 2009 8:03 AM
  • Can I get code how to use keybd_event after once I open my contacts window.once It open How can i send char 's' to search field.

    I used below code to open contacts windows:

        SHELLEXECUTEINFO ShExecInfo = {0};
        ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
        ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
        ShExecInfo.hwnd = NULL;
        ShExecInfo.lpVerb = NULL;
        ShExecInfo.lpFile = _T("poutlook.exe");       
        ShExecInfo.lpParameters = _T("contacts");   
        ShExecInfo.lpDirectory = NULL;
        ShExecInfo.nShow = SW_SHOW;
        ShExecInfo.hInstApp = NULL;   
        ShellExecuteEx(&ShExecInfo);
    Friday, October 9, 2009 8:56 AM
  • Something like the following function should work. Note the input is ascii string. Change it for UNICODE if you need to.

    void SendString(char* pszString)
    {
        while (*pszString != NULL)
        {
            keybd_event(*pszString, 0, 0, 0);
            keybd_event(*pszString, 0, KEYEVENTF_KEYUP, 0);
            pszString++;
        }
    }

    - Onkar





    http://www.42gears.com
    • Marked as answer by sumanthmara Friday, October 9, 2009 12:51 PM
    Friday, October 9, 2009 9:56 AM
  • How can I send char 's'.can u send me code plz.
    Friday, October 9, 2009 10:09 AM
  • Hi used this two lines of code after

    keybd_event('a', 0, 0, 0);
        keybd_event('a', 0, KEYEVENTF_KEYUP, 0);

    like this

    SHELLEXECUTEINFO ShExecInfo = {0};
        ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
        ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
        ShExecInfo.hwnd = NULL;
        ShExecInfo.lpVerb = NULL;
        ShExecInfo.lpFile = _T("poutlook.exe");        //tmail.exe for email and sms.
        ShExecInfo.lpParameters = _T("contacts");   
        ShExecInfo.lpDirectory = NULL;
        ShExecInfo.nShow = SW_SHOW;
        ShExecInfo.hInstApp = NULL;   
        ShellExecuteEx(&ShExecInfo);
        WaitForSingleObject (ShExecInfo.hProcess, INFINITE);

       

        HWND softkeyMB=SHFindMenuBar(GetForegroundWindow());

       
        //// Post the WM_HOTKEY message into Softkey like this:
        //// For Left Softkey
        //PostMessage(softkeyMB,WM_HOTKEY,0,MAKELPARAM(0,VK_F1));
        //PostMessage(softkeyMB,WM_HOTKEY,0,MAKELPARAM(4096,VK_F1));

        // For Right Softkey
        PostMessage(softkeyMB,WM_HOTKEY,0,MAKELPARAM(0,VK_F2));
        PostMessage(softkeyMB,WM_HOTKEY,0,MAKELPARAM(4096,VK_F2));

        keybd_event('a', 0, 0, 0);
        keybd_event('a', 0, KEYEVENTF_KEYUP, 0);


    but I cant see any char in search filed.please  reply me
    Friday, October 9, 2009 10:12 AM
  • WaitForSingleObject (ShExecInfo.hProcess, INFINITE);

    Above code will block the execution as long as the poutlook.exe is running. Replace this with some sleep before sending the keystrokes.

    I tried  the following when Contacts application is active and it works fine.

            keybd_event('A', 0, 0, 0);
            keybd_event('A', 0, KEYEVENTF_KEYUP, 0);

    - Onkar
    http://www.42gears.com
    • Marked as answer by sumanthmara Friday, October 9, 2009 12:51 PM
    Friday, October 9, 2009 11:11 AM
  • Here is a better implementation than what I posted earlier.

    http://www.42gears.com/blog/?p=236

    Handles lower and uppercase character inputs.

    - Onkar
    http://www.42gears.com
    Monday, October 12, 2009 3:52 AM