简体   繁体   中英

Some problems with the functions GetCursorPos() and SetCursorPos() in C++

I am a new user of C++ and do not know all about types of variables.

I have this code but it doesn't work normally. For normal i mean - after starting cursor must be random moves for -25 to 25 pixel of screen.

Sorry if i provided few information. Ask me i can send what you want. And sorry for my bad English.

#include <iostream>
#include "MyForm1.h"
#include <windows.h>
#include <cstdlib>
#include <winuser.h>
#include <playsoundapi.h>
using namespace System;
using namespace System::Windows::Forms;
using namespace std;




// Cursor random moving here :3

int shakecursor() {
    POINT p;

    int __cdecl GetCursorPos(int &p);
    cout <<  p.x << p.y << endl;

    int x_p1;
    int y_p1;

    x_p1 = rand() % 0 -25;
    y_p1 = rand() % 0 -25;

    int x_p = p.x + x_p1;
    int y_p = p.y + y_p1;

    int __cdecl SetCursorPos(int x_p1, int y_p1);


    Sleep(10);
    return 0;
}

[STAThreadAttribute]
int main(cli::array<System::String ^> ^args) {





    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    My3yPaB::MyForm mainForm;
    Application::Run(%mainForm);

    bool shaking = true;

    while (shaking = true) {
        shakecursor();

    }

}```

These

int __cdecl GetCursorPos(int &p);
int __cdecl SetCursorPos(int x_p1, int y_p1);

are not function calls. they are function declarations.

Instead it seems you mean

GetCursorPos( p );

and

SetCursorPos( x_p, y_p );

So i fixed this problem and program doesn't do anything here code:

#include <iostream>
#include "MyForm1.h"
#include <windows.h>
#include <cstdlib>
#include <winuser.h>
#include <Mmsystem.h> 
#include <playsoundapi.h>
#pragma comment (lib, "User32.lib")
using namespace System;
using namespace System::Windows::Forms;
using namespace std;
int shakecursor() {
    POINT p;

    GetCursorPos(&p);
    cout <<  p.x << p.y << endl;

    int x_p1;
    int y_p1;

    x_p1 = rand() % 51 - 25;
    y_p1 = rand() % 51 - 25;

    int x_p = p.x + x_p1;
    int y_p = p.y + y_p1;

    SetCursorPos(x_p, y_p);


    Sleep(10);
    return 0;
}
[STAThreadAttribute]
int main(cli::array<System::String ^> ^args) {
    //PlaySound(L"start.mp3", NULL, NULL);
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    My3yPaB::MyForm mainForm;
    Application::Run(%mainForm);
    bool shaking = true;
    while (shaking = true) {
        shakecursor();      
    }

}```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM