I am writing a program, that will automatically post an image from a folder on my computer onto a blog of mine. I want to be able to have the program add a title for the post and maybe even fill in some tags. I don't know how to make a c++ program insert text anywhere. Any help would be great.

Not that it really matters will my question but here is the code so far.
(I am new, I know this is probably a crappy way to do this, but I am just trying to learn right now)

#include <windows.h>
#include <ctime>

int main()
{
   ShellExecute(NULL, "open", "http://somesiteofmine.org/somethingelse",
                NULL, NULL, SW_SHOWNORMAL);  
    
    Sleep(4000); // wait for 2000 ms.
    
    const int media = 1; // click for 1 second
    const int media_X = 381; // x-coordinate of mouse
    const int media_Y = 370; // y-coordinate of mouse
    
    SetCursorPos(media_X,media_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }   
    
    Sleep(2000); // wait for 2000 ms.
    
    const int select = 1; // click for 1 second
    const int select_X = 413; // x-coordinate of mouse
    const int select_Y = 337; // y-coordinate of mouse
    
    SetCursorPos(select_X,select_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    } 
    
    Sleep(1000); // wait for 1000 ms.
    
    const int document = 1; // click for 1 second
    const int document_X = 152; // x-coordinate of mouse
    const int document_Y = 100; // y-coordinate of mouse
    
    SetCursorPos(document_X,document_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    } 
    

    const int folder = 1; // click for 1 second
    const int folder_X = 137; // x-coordinate of mouse
    const int folder_Y = 100; // y-coordinate of mouse
    
    SetCursorPos(folder_X,folder_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    } 
    
    
    const int picture = 1; // click for 1 second
    const int picture_X = 137; // x-coordinate of mouse
    const int picture_Y = 100; // y-coordinate of mouse
    
    SetCursorPos(folder_X,folder_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    } 
    
    Sleep(5000); // wait for 5000 ms.

    const int scrolldown = 1; // click for 1 second
    const int scrolldown_X = 831; // x-coordinate of mouse
    const int scrolldown_Y = 636; // y-coordinate of mouse
    
    SetCursorPos(scrolldown_X,scrolldown_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    } 

    //This is where adding text will go when I figure it out...............

    const int center = 1; // click for 1 second
    const int center_X = 556; // x-coordinate of mouse
    const int center_Y = 549; // y-coordinate of mouse
    
    SetCursorPos(center_X,center_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }
    
    const int insert = 1; // click for 1 second
    const int insert_X = 403; // x-coordinate of mouse
    const int insert_Y = 624; // y-coordinate of mouse
    
    SetCursorPos(insert_X,insert_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }
    
    //This is where it will add the title when I figure it out
    
    Sleep(4000);
    
    const int post = 1; // click for 1 second
    const int post_X = 927; // x-coordinate of mouse
    const int post_Y = 450; // y-coordinate of mouse
    
    SetCursorPos(post_X,post_Y);
    

    {
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }

    
    return 0;
}

Ummm. I have no idea what you are trying to do. And I don't think that all those mouse events are relevant to the problem, and should probably not be included for clarity. Are you trying to write some sort of macro that automatically fills in textboxes for you? And are you calling events? That's a no-no in windows programming.

Yes I am just trying to set up a macro that fills in web forms

Yeah, that's really not a wonderful idea. Why don't you base your web blog on a database, and use a C++ program to connect to the database and add a new post that way? Your method depends way too much on hoping that everything will go as planned (window will open where you want it to, etc.). Also, you aren't even using the variables you set to the duration of each click.

Yeah if you want to work on macros that's one thing, but if you only want to accomplish the goal of auto-filling web forms then yeah you should really create a whole system with an XML file (or even an SQL database) generated by a C++ program which is parsed/interpreted by a PHP script or XSLT on the website. It would be much more robust and professional this way.

This article has been dead for over six months. Start a new discussion instead.