Thread: Using scanf and mouse together

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question Using scanf and mouse together

    Hi!

    Anyone knows how to do that scanf function a mouse will work together in console-mode application for win32?

    Let's say that the user has to enter 5 different informations (name, surname, address, ...). Now I want to create a function that will allow the user to select what information he will enter first (it must work the same as EDIT component in windows).

    Code:
    Example:
    
    Name:    __________
    Surname: __________
    Address: __________
    
    User must be able to select what information he will enter first.
    Is there any other function (WINAPI) that will allow me to enter characters and that I will be allowed to use the mouse in the same time?

    This function must only work in CONSOLE MODE.

    I would be very grateful for some tips and hints.

    Thank you in advance.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    This is one of those things that people assume are easy to do just because they've seen it done before and they have done a couple console applications before. Yes, there was I time when I was as naive as you. Here is the deal with that. The mouse drivers are OS dependent. So you will need to use the win32 API. But don't fret, it is possible to do this without using the good old API. That answer is DOS. For this solution you will need to essentially need to write your own mouse drivers. But keep in mind that between the two using the win api is way easier.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    This is one of those things that people assume are easy to do just because they've seen it done before and they have done a couple console applications before. Yes, there was I time when I was as naive as you.
    At first let me tell you that I am not naive. And second I am not assuming that this thing is easy to program and I didn't see it before (only in Windows -> EDIT component), ok. So if you can help me than help me or shut up, ok?
    The mouse drivers are OS dependent. So you will need to use the win32 API. But don't fret, it is possible to do this without using the good old API. That answer is DOS. For this solution you will need to essentially need to write your own mouse drivers. But keep in mind that between the two using the win api is way easier.
    Did you even read my thread???


    So if anyone has any tip or hint how to do that please let me know.

    Is there any other function in WINAPI similar to scanf function?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Gape, I'm not sure I understand what you mean. Can you expand on this please:
    Is there any other function (WINAPI) that will allow me to enter characters and that I will be allowed to use the mouse in the same time?
    Do you mean you want to position the input cursor by using the mouse?
    Do you mean you want to copy/paste using the mouse?
    or what ?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Do you mean you want to position the input cursor by using the mouse?
    Yes.
    Do you mean you want to copy/paste using the mouse?
    This too, but at first I want to position the input cursor by using the mouse.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    OK, I wrote a post here that may help you with setting the cursor position using the mouse (look for my post in that thread). I think you should be able to modify it to do what you want (it's not exactly what you're after, but close enough to help you out).

    As for cut/pasting, you can use the "quickedit" option within the console windows properties. This is a standard Windows feature. However, turning this on will disable mouse events in your program, and therefore kills the first idea Apparently you can turn this feature on/off via code, but the samples I tried didn't work.

    Good luck
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Ok, thanks for the link which is nothing new to me beacuse the main part is missing. When I put the cursor on some x,y coordinate then I must be able to enter some data (string or a number). There must be a WINAPI function for this. I've looked into MSDN but I found nothing.

    Please help me .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by GaPe
    When I put the cursor on some x,y coordinate then I must be able to enter some data (string or a number). There must be a WINAPI function for this. I've looked into MSDN but I found nothing.
    Once you have set the position of the cursor, just use the normal input methods to get the data from the user. Here's a version using gotoxy() (I wrote it under Borland 5.5). It doesn't use the mouse input to set the position, but this is irrelevant at this point.
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
    	char name[10];
    	clrscr();
    	gotoxy(15,10);
    	printf ("enter name>");
    	fgets(name, 10, stdin);
    	gotoxy(15,15);
    	printf("Hello %s", name);
    	return 0;
    }
    Is this the kind of thing you mean?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Well yes but when I enter data I can't use the mouse.

    Look, I have to enter data let's say on coordinates (10, 2) and on coordinates (0, 0) is the X button. When the user clicks on the X the program close. Now I have to enter data on (10, 2) coordinates and I can do that of course but then I won't be able to click on the X until I press <RETURN>.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    OK, now I understand what you mean....

    I personally haven't done this, but I'd guess that you need to process the events using ReadConsoleInput() for both the keyboard and the mouse.

    When you receive a key event, determine what type of key it is and taken appropriate action. EG, if it's a character, add it to the input array and echo it to the screen. If it's <enter> terminate the input array with a NULL, and reposition cursor on next input field.

    When you receive a mouse event, process it as desired.

    Sorry, can't really help much more
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    TK
    Guest
    Go Here:
    http://msdn.microsoft.com/library/

    Choose these options in this order:

    UP ONE LEVEL/ USER INTERFACE DESIGN AND DEVELOPMENT/ WINDOWS MANAGEMENT/ WINDOWS USER INTERFACE/ USER INPUT/ MOUSE INPUT

  12. #12
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Hammer
    Yes that's right. I was looking in the MSDN library and this is the right answer. I'm writting the code right now (it's almost complete) and looks good. Thank you for helping me.
    TK
    Thanks.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed