Jump to content

jjj93421

Member
  • Posts

    17
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United States

Posts posted by jjj93421

  1. Ok, I got it !!!! But, I have some bad news. This is the final code that works.

    #include <windows.h>
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>


    int main(){

    cout<<"hit enter to click button";
    cin.get();
    cin.get();


    SetCursorPos(404, 459);

    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);


    return 0;

    }

    sorry man. I couldn't ever get SendInput to work. I thought I should tell you in case you ever need to do the same thing. You the man, though. Later.

  2. Crap. It didn't like that. Here is the code now if you need it. It said this:

    Compiling...

    mouse 5.cpp

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(11) : warning C4005: 'WINVER' : macro redefinition

    c:\program files\microsoft visual studio\myprojects\mouse 5\mouse 5.cpp(0) : see previous definition of 'WINVER'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(49) : error C2143: syntax error : missing ';' before '->'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(49) : error C2501: 'InpPtr' : missing storage-class or type specifiers

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(49) : error C2040: 'InpPtr' : 'int' differs in levels of indirection from 'struct tagINPUT *'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(49) : error C2143: syntax error : missing ';' before '->'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(50) : error C2143: syntax error : missing ';' before '->'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(50) : error C2501: 'InpPtr' : missing storage-class or type specifiers

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(50) : error C2040: 'InpPtr' : 'int' differs in levels of indirection from 'struct tagINPUT *'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(50) : error C2143: syntax error : missing ';' before '->'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(51) : error C2143: syntax error : missing ';' before '->'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse 5\mouse 5.cpp(51) : error C2501: 'InpPtr' : missing storage-class or type specifiers

    mouse 5.obj - 56 error(s), 1 warning(s)

    #include <windows.h>
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <WinUser.h>
    #include <stdafx.h>


    #define _WIN32_WINNT 0x0501

    #define WINVER 0x0501





    int a,b;

    int xstart=-10;
    int ystart=-20;

    char dd;

    char * pch;
    HWND hwnd;
    char texttitle[255]={0};

    char word[255];



    BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
    {

    GetWindowText(hWnd, texttitle ,sizeof(texttitle));
    if(texttitle[0] != 0){
    pch=strstr (texttitle,word);
    if (pch!=NULL){
     hwnd=hWnd;}}


    return TRUE;
    }



    INPUT *InpPtr = new INPUT;

    InpPtr->type = INPUT_MOUSE;
    InpPtr->mi.dx = 380;
    InpPtr->mi.dy = 457;
    InpPtr->mi.mouseData = XBUTTON1;
    InpPtr->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    InpPtr->mi.time = 0;
    InpPtr->mi.dwExtraInfo = 0;


    INPUT *InpPtr2 = new INPUT;

    InpPtr2->type = INPUT_MOUSE;
    InpPtr2->mi.dx = 380;
    InpPtr2->mi.dy = 457;
    InpPtr2->mi.mouseData = XBUTTON2;
    InpPtr2->mi.dwFlags = MOUSEEVENTF_LEFTUP;
    InpPtr2->mi.time = 0;
    InpPtr2->mi.dwExtraInfo = 0;




    int main(){




    loop201:
    cout<<"Input a word from window title \n";
    cin.getline(word,255);




    EnumWindows(EnumWindowsProc,0);



    SetWindowPos( hwnd,
       HWND_TOP,
       xstart,
       ystart,
       2,
       2,
       SWP_NOSIZE
    );





    cout<<"Hit enter to automatically use mouse ";
    cin.get();
    cin.get();


    SendInput(1,InpPtr,sizeof(INPUT));
    SendInput(1,InpPtr2,sizeof(INPUT));

    delete InpPtr;



    return 0;



    }

    I also tried an #endif at the end of my code with the previous way but it didn't like that either.

  3. Hey, Hearts, I'm back. I got 3 errors when I tried to compile it. Also, do I need to use MOUSEINPUT , or is that just FYI . Sorry for so many questions. This is what it said:

    Compiling...

    mouse click 3.cpp

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse click 3\mouse click 3.cpp(65) : error C2146: syntax error : missing ';' before identifier 'test'

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse click 3\mouse click 3.cpp(65) : error C2501: 'INPUT' : missing storage-class or type specifiers

    C:\Program Files\Microsoft Visual Studio\MyProjects\mouse click 3\mouse click 3.cpp(65) : fatal error C1004: unexpected end of file found

    Error executing cl.exe.

    mouse click 3.obj - 3 error(s), 0 warning(s)

    Do I not have an #include that I need ? Here is the code:

    #include <windows.h>
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>


    int a,b;

    int xstart=-10;
    int ystart=-20;

    char dd;

    char * pch;
    HWND hwnd;
    char texttitle[255]={0};

    char word[255];

    BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
    {

    GetWindowText(hWnd, texttitle ,sizeof(texttitle));
    if(texttitle[0] != 0){
    pch=strstr (texttitle,word);
    if (pch!=NULL){
     hwnd=hWnd;}}


    return TRUE;
    }



    INPUT test;

    test.type = INPUT_MOUSE;
    test.mi.dx = 380;
    test.mi.dy = 457;
    test.mi.mouseData = XBUTTON1;
    test.mi.dwflags = MOUSEEVENTF_LEFTDOWN;
    test.mi.time = 0;
    test.mi.dwExtraInfo = 0;


    INPUT *InpPtr = test;


    int main(){


    loop201:
    cout<<"Input a word from window title \n";
    cin.getline(word,255);


    EnumWindows(EnumWindowsProc,0);



    SetWindowPos( hwnd,
       HWND_TOP,
       xstart,
       ystart,
       2,
       2,
       SWP_NOSIZE
    );


    cout<<"Hit enter to automatically use mouse ";
    cin.get();
    cin.get();


    SendInput(1,InpPtr,sizeof(INPUT));

    return 0;
    }

  4. Ok, appreciate the advice Hearts and Simon. What I don't understand is the SendInput function. I don't understand the parameters.

    Parameters

    nInputs

    [in] Specifies the number of structures in the pInputs array.

    pInputs

    [in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.

    cbSize

    [in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.

    ************************

    Number of structures in the inputs array ?? Huh ? Pointer to an array of input structures ? What does arrays have to do with this ? Ok the size of it but how do I find these things out ? Please help. The rest looks easy.

  5. I want to be able to automate a mouse click so that when I start up a program it will click on a button in a window automatically. I already have a handle to this window . I know the x and y coords. Can anyone help a beginning programmer out? I am using win32 and it is a console program. Also, this button won't move and the window is always in the same spot on my desktop, therefore the x and y coords will always be the same if this helps anyone out. I want to do it the easiest way possible. I know how to program with c++ but not that well and my windows programming is sketchy. If someone can get me started, a little experimenting on my part should solve what I need.

  6. Thanks for the help Hearts. I finally got it working. It feels good to see your program work. I did a double take when I saw the window move.

    I'm new to programming as you may have guessed so it feels good when something works especially when it is windows programming.

    Actually, I'm not sure I would have gotten without your help. thanks. I like setwindowpos better than movewindow.

  7. Thanks for the reply. The SWP_NOSIZE should make it ignore the height and width numbers (the 2's). This child window that I am trying to move wasn't created by me. It is an application.

    Right now, I'm having trouble getting a handle on the child window. The hwnd or whatever. Can you help?

    Basically, all I need to do is get a handle on the current child window on the screen just below my console program and move it over to the left and up. Thanks.

  8. Thanks. Use setwindowpos , you mean?

    I am using this now:

    It gives me errors saying:

    C:\Program Files\Microsoft Visual Studio\MyProjects\get pixel win32\getpixel7.cpp(18) : error C2059: syntax error : 'constant'

    C:\Program Files\Microsoft Visual Studio\MyProjects\get pixel win32\getpixel7.cpp(19) : error C2059: syntax error : 'constant'

    Error executing cl.exe.

    Here is the code:

    const char* caption = "Poker";
    HWND hwnd = FindWindow(NULL, caption);


    BOOL SetWindowPos( HWND hWnd,
       HWND HWND_TOP,
       100,
       100,
       2,
       2,
       UINT SWP_NOSIZE
    );

    How do you get the handle? Am I doing it right?

×
×
  • Create New...