0

As simple as it gets, I just want to put mouse cursor in my system for my project using C. I have just started my study in programming recently and we are learning basic C programming right now. So, our project is based on C programming.(OS:Windows 10, IDE: Turbo C++)

Kuroko
  • 9
  • 3
  • 4
    What does "put mouse cursor" mean? Change the positioning of the cursor? It depends on the platform, what platform are you talking about? – CherryDT Sep 27 '21 at 05:05
  • 5
    ISO C does not have a notion of a keyboard or a mouse. It only has the notion of a standard input stream. Therefore, if you want your program to be able to interface with the mouse, you will require platform-specific functionality. For this reason, please specify which platform (operating system) your question applies to. – Andreas Wenzel Sep 27 '21 at 05:09
  • Details are updated in question. – Kuroko Sep 27 '21 at 06:00
  • 4
    The "edit summary" field should not be used for adding important information, as most people will not read it. The fact that you are using a 15 year old compiler (Turbo C++) is very important information. Please put that information into the question itself. – Andreas Wenzel Sep 27 '21 at 06:02
  • 1
    Also "Turbo C++" doesn't necessarily refer to the somewhat modern RAD tool released around 2005 somewhere, but could refer to the ancient DOS one or anything in between. – Lundin Sep 27 '21 at 06:14
  • 1
    The graphics mode of Turbo C++ is very outdated. I don't recommend that you continue using it. There are many modern alternatives. Since you state that you are using Windows 10, I suggest that you download Microsoft Visual Studio Community Edition (which is free), learn [the basics](https://learn.microsoft.com/en-us/windows/win32/learnwin32/introduction-to-windows-programming-in-c--), and then take a look at [Windows graphics](https://learn.microsoft.com/en-us/windows/win32/learnwin32/module-3---windows-graphics). – Andreas Wenzel Sep 27 '21 at 06:23
  • please edit the question and include all the related information. And Turbo C++ obviously can't run on Windows 10 (unless you're using 32-bit Windows 10) – phuclv Sep 27 '21 at 08:53
  • @AndreasWenzel Turbo C++ was released in 1990 so it's definitely not a 15-year-old compiler. It far predates the first C++ standard – phuclv Sep 27 '21 at 08:54
  • @phuclv: You seem to be assuming that OP is using the first version of the compiler from 1990, and not the latest version from 2006. – Andreas Wenzel Sep 27 '21 at 09:02
  • You have added info to your question. At least you tried.... Good. But do you see that additional info in your question post now? Please try again, by [edit]ing to change the body of your question - instead of putting info in the very well-hidden "edit summary" field. – Yunnosch Sep 27 '21 at 09:19
  • @AndreasWenzel most people use the Turbo C++ 3.0 version from 1991. Turbo C++ 4.5 runs on Windows and is very rarely used. I suppose the same applies to Turbo C++ 2006. Besides it seems the version 2006 belongs to the Borland line which is even less common. If you see the DOS version then it's almost always 3.0 – phuclv Sep 27 '21 at 11:03
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 05 '21 at 09:42

2 Answers2

2

Mouse input (unlike eg. stdin) is not a C feature, therefore this can't be realistically done in C alone.

What I can recommend instead is to create a brand new program for mouse-enabled, GUI-oriented environment - like Windows or Gnome. But that's neither a C question nor "adding to your existing program".

/edit:

For the Windows way, I wholeheartedly recommend Charles Petzold's book "Programming Windows", 4th or 5th edition, from 1998 (don't go for 6th, he switched to C#). It's about Win32 C API and general transition from writing commandline programs into GUI apps. Although it's not very modern as well, it gives great insight into how a GUI-oriented system works under the hood. IMHO it's a must for every C programmer.

Agent_L
  • 4,960
  • 28
  • 30
1

This is not standard language functionality. You'll need to use either a graphics or GUI library to use this interface to the OS. It's not just "put mouse in" - you either change your window mode from text (what you usually start from) to graphical (where you need to specify coordinates to draw things, cannot just output to stdout), or to forms application (which is a wrapper around graphical mode).

For GUI the simplest would be to make a forms / graphical window application native to your OS. Visual Studio has a wizard for this.

Arguably better practice would be to use a cross-platform library, such as Qt (C++) or GTK+ (C). There are others. It may be non-trivial for a beginner to use such external libraries.

To just get a graphical window which would allow you to query mouse coordinates (but note that e.g. stdout will then not show on screen - you'll need to use text drawing functions) a standard library to use would be OpenGL. Personally I also have had good experience with the Allegro library which has a simple enough interface, but again - your app will become graphical.

Finally, if you wanted to retain a textual interface and add mouse input capability, you could use the widely used ncurses - but this is most likely nontrivial to use for a beginner, especially on Windows.

Thus your most realistic options in my opinion seem to be either Windows Forms, or a graphical library, such as Allegro.

You can also see the related (unfortunately, closed) SO question: Cross Platform C library for GUI Apps?

Yuri Feldman
  • 2,354
  • 1
  • 20
  • 23