Simulating File Dialog Box using Winapi
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Simulating File Dialog Box using Winapi

  1. #1
    Join Date
    May 2009
    Posts
    15

    Lightbulb Simulating File Dialog Box using Winapi

    Hi guys,

    I have a WebView where I simulate a click to a button. Actually this button is to upload an image to the server. So, when you click to this button, a file dialog box opens and user needs to select whatever to upload. My task is to simulate this behavior because I already know what image to upload before.
    I created an application where clicking to the upload button is working like charm. No problem there, file dialog box opens. I can also click on the cancel button on the file dialog box. However, I couldn't select the file that I want to upload. I tried to write the fullpath + filename to the ComboBox text part but it doesn't write anything there. I thought perhaps there is a trick to do somewhere and wanted to ask you guys. Here is what I have so far:

    HWND handleForWindow = FindWindow(NULL, "Open"); //This finds the handle of the file dialog box, which comes correct. Checked with Spy++.
    HWND hwndComboBox = FindWindowEx(handleForWindow, 0, "ComboBox", ""); // This handle comes correct as well.

    //Here is the problem. I tried SendMessage and SetDlgItemText apis but didn't work.
    SendMessage(hwndComboBox , WM_SETTEXT, IDOK, (LPARAM)("path")); //I don't see any text written in the box.

    Any help is much appreciated.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Simulating File Dialog Box using Winapi

    You could try the SendInput API instead.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2009
    Posts
    15

    Re: Simulating File Dialog Box using Winapi

    Quote Originally Posted by VictorN View Post
    You could try the SendInput API instead.
    Hi,
    Thanks for your reply.
    I have tried the following codes but again no luck for some reason.

    keybd_event(VK_SPACE,MapVirtualKey(VK_SPACE,0),0,0) ;
    keybd_event(VK_SPACE,MapVirtualKey(VK_SPACE,0),KEYEVENTF_KEYUP,0) ;


    INPUT ip;

    ip.type = INPUT_KEYBOARD;
    ip.ki.time = 0;
    ip.ki.wVk = 0; //We're doing scan codes instead
    ip.ki.dwExtraInfo = 0;

    ip.ki.dwFlags = KEYEVENTF_SCANCODE;
    ip.ki.wScan = 0x1E; //Set a unicode character to use (A)

    SendInput(1, &ip, sizeof(INPUT));

    //Prepare a keyup event
    ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
    SendInput(1, &ip, sizeof(INPUT));

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Simulating File Dialog Box using Winapi

    What window has an input focus while you call this code?
    Victor Nijegorodov

  5. #5
    Join Date
    May 2009
    Posts
    15

    Re: Simulating File Dialog Box using Winapi

    Quote Originally Posted by VictorN View Post
    What window has an input focus while you call this code?
    There is something really fishy. Here is why:

    HWND handleForWindow = FindWindow(NULL, "Open");
    HWND hwndComboBox = FindWindowEx(handleForWindow, 0, "ComboBox", "");

    //Here if I say
    SetFocus(hwndComboBox);
    //Strange enough, it focuses on the combobox on the right side because when I press arrow-down key, that combo box opens. I am now wondering why it selects that combo box even though I say "" for the window name in the FindWindowEx call.

    This is the view when I press arrow down after running the code above.
    https://www.dropbox.com/s/2jypq5vppwse44j/1.png

    This is the spy++ when I search for the combobox that I want to add text.
    https://www.dropbox.com/s/oxpoyabqtbpr4jg/spy1.png

    This is the spy++ when I search for the combobox at the right hand side.
    https://www.dropbox.com/s/7qxcr7pjzzgpa2z/spy2.png

    Could you please tell me where I am doing wrong?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Simulating File Dialog Box using Winapi

    This
    Code:
    HWND hwndComboBox = FindWindowEx(handleForWindow, 0, "ComboBox", "");
    search for a combobox, But there may be more than one comboboxes and only first found is returned!
    The control ID for the combobox you got seems to be cmb1 while what you need is cmb13.
    See Explorer-Style Control Identifiers

    Besides, it would be better if you attached the images to your post than upload them to dropbox.
    Go Advanced -> Additional Options ->| button "Manage Attachments"...

    Or this toolbar button:
    Attached Images Attached Images  
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center