[RESOLVED] Showing the buttons pressed in a GUI Application
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: [RESOLVED] Showing the buttons pressed in a GUI Application

  1. #1
    Join Date
    Jun 2016
    Posts
    12

    [RESOLVED] Showing the buttons pressed in a GUI Application

    Hello there, i have a program with 5 buttons:
    Abyssal Scepter -> Writes something into ChampionName-SummonersRift.txt
    Aegis of the Legion -> Same thing, different id
    Beep -> Send a Beep Sound
    Show File Content -> Show What is currently in ChampionName-SummonersRift.txt
    AutoBuddy.... -> Simple MessageBox with a Static text
    Quit -> Terminates the program and removes that last character of the .txt file

    I want the "Beep" button to show on screen what buttons have been pressed (Not keyboard button, the GUI's buttons) [EX: You have pressed This,That,This,These ]
    What can i do?
    Please help
    Code: http://pastebin.com/haHBShVp

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,597

    Re: Showing the buttons pressed in a GUI Application

    1. Please, attach your code to your post. Read the Announcements section "Before you post...."

    2. Where and how would you like to show the information:
    • as a tooltip for the button
    • in some static control on the GUI
    • in a status bar
    • ...
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2016
    Posts
    12

    Re: Showing the buttons pressed in a GUI Application

    I can't find the edit button.
    1.I have now readed the rules.
    2.The project has been attached.
    3.I want the Output ( list of the GUI's buttons that have been pressed) to be shown ONScreen in a pop-up window (Just how the "Show file Content" button works
    4.//IF POSSIBLE: I want to be able to select (Via mouse1) & copy the text in that window.
    Thank you
    Attached Files Attached Files

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,597

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by n0thing17 View Post
    I can't find the edit button.
    I hope you will find it after four or five posts.

    Quote Originally Posted by n0thing17 View Post
    3.I want the Output ( list of the GUI's buttons that have been pressed) to be shown ONScreen in a pop-up window (Just how the "Show file Content" button works
    Then you could use MessageBox function.

    Quote Originally Posted by n0thing17 View Post
    4.//IF POSSIBLE: I want to be able to select (Via mouse1) & copy the text in that window.
    Thank you
    In case of MessageBox it should work with Ctrl+C to copy into the clipboard.
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2016
    Posts
    12

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by VictorN View Post
    I hope you will find it after four or five posts.

    Then you could use MessageBox function.

    In case of MessageBox it should work with Ctrl+C to copy into the clipboard.
    1.I hope too.
    2.I don't know how to tell the program to show what buttons have been pressed but i know how to create the Messagebox (Does it make sense? | "I want the "Beep" button to show on screen what buttons have been pressed (Not keyboard button, the GUI's buttons) [EX: You have pressed This,That,This,These ]
    What can i do?")
    3.I know i can Ctrl+C, Ctrl+C copies all, including the Title and the "OK" button // How can i select only a few words?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,597

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by n0thing17 View Post
    2.I don't know how to tell the program to show what buttons have been pressed but i know how to create the Messagebox (Does it make sense? | "I want the "Beep" button to show on screen what buttons have been pressed (Not keyboard button, the GUI's buttons) [EX: You have pressed This,That,This,These ]
    What can i do?")
    I guess you handle the "button-press" for all your buttons in a window procedure. So depending on the button ID you could determine which button has been pressed...

    Quote Originally Posted by n0thing17 View Post
    3.I know i can Ctrl+C, Ctrl+C copies all, including the Title and the "OK" button // How can i select only a few words?
    Then the easiest way would be implementing your own dialog window with the feature of "copy only the text you need".
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2016
    Posts
    12

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by VictorN View Post
    I guess you handle the "button-press" for all your buttons in a window procedure. So depending on the button ID you could determine which button has been pressed...

    Then the easiest way would be implementing your own dialog window with the feature of "copy only the text you need".
    I only understand only Very Basic Stuff of C++, atleast tell me what function to use to "handle" the button-pressed?

    //EDIT : Copy pasting from the window is not that important.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,252

    Re: Showing the buttons pressed in a GUI Application

    Let's get back to the basics. In the program that you want to capture the button clicks, do you want to modify this program (and have the source code to modify)?

    Or do you want to intercept the button clicks without modifying the original program?

  9. #9
    Join Date
    Dec 2012
    Location
    England
    Posts
    4,174

    Re: Showing the buttons pressed in a GUI Application

    I want the "Beep" button to show on screen what buttons have been pressed (Not keyboard button, the GUI's buttons) [EX: You have pressed This,That,This,These ]
    What can i do?
    Use a vector of string. In the event handler for each button you want to show later, add the required text to the vector. In the event handler for the beep button, simply show the various elements of the vector in a messagebox (or how you want to display them) and then clear the vector.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
    C, C++ Compiler: Microsoft VS2015

  10. #10
    Join Date
    Jun 2016
    Posts
    12

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by 2kaud View Post
    Use a vector of string. In the event handler for each button you want to show later, add the required text to the vector. In the event handler for the beep button, simply show the various elements of the vector in a messagebox (or how you want to display them) and then clear the vector.
    I think i know what you are talking about. I hope'd there is a better way of doing that (Main program has 190 buttons ) Silly me. I will edit my comment when i am done. If some problem pops-up i will let you know.
    Thank you!

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,597

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by n0thing17 View Post
    ... (Main program has 190 buttons )
    It sounds like not a good or just poor design!
    Victor Nijegorodov

  12. #12
    Join Date
    Jun 2016
    Posts
    12

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by 2kaud View Post
    Use a vector of string. In the event handler for each button you want to show later, add the required text to the vector. In the event handler for the beep button, simply show the various elements of the vector in a messagebox (or how you want to display them) and then clear the vector.
    Quote Originally Posted by VictorN View Post
    It sounds like not a good or just poor design!
    I don't know how to create a "vector of string", i just created a normal string and tried adding some text while in append mode. Failed
    Can you guys help more ? I know you consider this task easy...but for me is hard. Otherwise i will do the only thing i know to do, make another txt file and assigning the Buttons to write the Actual name of the Buttons [I.Ex, i Press XY....program writes XY.. in the txt file]

  13. #13
    Join Date
    Dec 2012
    Location
    England
    Posts
    4,174

    Re: Showing the buttons pressed in a GUI Application

    Code:
    #include <vector>
    #include <string>
    
    ...
    std::vector<std::string> events;
    ...
    events.push_back("event1");
    ...
    events.push_back("event2");
    See http://www.cplusplus.com/reference/vector/vector/

    If the event handler for all these buttons are from the WM_COMMAND message, then in the initial code for WM_COMMAND just write the control ID to a vector instead of a string and then use a look-up table to get a text message from a control ID - or you could obtain the button window text from the id etc etc - so you won't need different code for each button, the same short piece of code will serve for all buttons.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
    C, C++ Compiler: Microsoft VS2015

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,469

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by n0thing17 View Post
    I hope'd there is a better way of doing that
    There really is. Button clicks come to window procedure in a form of WM_COMMAND. So, you can intercept the clicks in one place and collect the button names as button window texts showing at the moment of pressing.

    Code:
    vector<string> btnNames;
    
    static void pushButton(HWND hwndCtrl)
    {
        if (hwndCtrl)
        {
            char btnName[200] = {0};
            GetWindowText(hwndCtrl, btnName, 200);
            btnNames.push_back(btnName);
        }
    }
    
    static void pushButtonDump(string& dump)
    {
        vector<string>::iterator iter = btnNames.begin();
        for (; iter != btnNames.end(); iter++)
        {
            dump += *iter;
            dump += "\n";
        }
    }
    Code:
        case WM_COMMAND:
        {
            pushButton((HWND)lParam);
    
            if (LOWORD(wParam) == 1) {
                myfile << "3001:Buy,";
            }
    Code:
            if (LOWORD(wParam) == 183) {
                Beep(432, 500);
                string names;
                pushButtonDump(names);
                MessageBox(hwnd, names.c_str(), "Button Names", MB_OK);
            }
    Attached Images Attached Images  
    Last edited by Igor Vartanov; June 9th, 2016 at 03:29 AM.
    Best regards,
    Igor

  15. #15
    Join Date
    Jun 2016
    Posts
    12

    Re: Showing the buttons pressed in a GUI Application

    Quote Originally Posted by Igor Vartanov View Post
    There really is. Button clicks come to window procedure in a form of WM_COMMAND. So, you can intercept the clicks in one place and collect the button names as button window texts showing at the moment of pressing.

    Code:
    vector<string> btnNames;
    
    static void pushButton(HWND hwndCtrl)
    {
        if (hwndCtrl)
        {
            char btnName[200] = {0};
            GetWindowText(hwndCtrl, btnName, 200);
            btnNames.push_back(btnName);
        }
    }
    
    static void pushButtonDump(string& dump)
    {
        vector<string>::iterator iter = btnNames.begin();
        for (; iter != btnNames.end(); iter++)
        {
            dump += *iter;
            dump += "\n";
        }
    }
    Code:
        case WM_COMMAND:
        {
            pushButton((HWND)lParam);
    
            if (LOWORD(wParam) == 1) {
                myfile << "3001:Buy,";
            }
    Code:
            if (LOWORD(wParam) == 183) {
                Beep(432, 500);
                string names;
                pushButtonDump(names);
                MessageBox(hwnd, names.c_str(), "Button Names", MB_OK);
            }
    This is exactly what i needed, Thank you. I will use that for sure.
    Can you take a look at my biggest problem atm? http://forums.codeguru.com/showthrea...17#post2200317
    //Solved, you may close this thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


HTML5 Development Center