Thread: VC++

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    307

    VC++

    i have a c++ console program i wrote

    but i am wanting to make a GUI program

    started a windows form app, and really dont know how to go from there!

    i have a vellman k8055 relay board, and a touchscreen computer running windows xp

    i am wanting to make a gui that has 8 "lights" (prefer jpg or bmp)

    when each relay is on, the corrisponding "light" is green, when off is red.

    when i click (touch) the light, it toggles the light, and sends the command to turn on or off the light....

    any insite to where i go to get the gui to work, at the moment WITHOUT the board and dll?

    not looking for someone to do this for me, but guide me to where i go, seeing i know c and c++ but not the coding for windows form application.

    thanks

  2. #2
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    ok step one i am trying to find. Basically a keypad on my form. buttons numbered 0-9, and a toggle button...

    trying to find a way to click on 1, and it places a 1 in the text box, then click 2, and the text box says 12

    then when click "toggle" it takes what is in the text box, and sends it to lets say X, then clears text box, and uses the X

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Probably best to start by going through this trivial Windows Forms tutorial: Creating a Windows Forms Application By Using the .NET Framework (C++)

    Just to familiarise yourself with the GUI and controls.

    Each control (e.g. button or picture) on your form can have a number of functions associated with the various events it can trigger. E.g. something to do on mouse over, click, double click....

    For your first question - I think using PictureBox controls to display a red or green picture and switch between images when clicked will work.
    Interfacing to your DLL could be more of a hassle though -- Windows Forms are Managed code - Wikipedia, the free encyclopedia, whereas your DLL is presumably not. Often you have to do some battle with managed/unmanaged types to get everything looking sensible. Recommend googling around for calling an unmanaged DLL from managed Windows Forms code -- just to make sure you do everything you need to.

    For your second -- if you, for example, created the text box in the GUI then named the text box "textbox1"m you should be able to find that textbox1 object in the source code for Form1.h. Then you'd add an onClick handler to each button which altered the text box. Something like (this is a complete random guess, but it's the right sort of thing):
    Code:
     textbox1->Text = textbox1->Text + this->Text;

  4. #4
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    Thank you, got the 1 and 2 keys going with this
    Code:
    textBox1->Text = textBox1->Text +"1";
    Next step would be to take the "enter" button click to take the text in the textbox, and set it to X (an int)

    but i think that will be another day!!!

    going to finish my 0-9 then close it!

    thank you for the start!

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Great You're very welcome!

    Just to correct myself: this was partly nonsense:

    Quote Originally Posted by smokeyangel View Post
    Code:
     textbox1->Text = textbox1->Text + this->Text;
    As you can no doubt see in your code, the button onClick function is just a function in the form -- onClick isn't a member of the Button class, so me suggesting using the this pointer was wrong. If you scroll around you'll probably see the generated code that ties the events and handling functions together.

    If you wanted to avoid writing 10 separate functions, you should be able to get at the button that was clicked by examining the sender argument:
    Code:
    void button1_Click( Object^ sender, System::EventArgs^ /*e*/ )
    {
        Button^ thisbutton = safe_cast<Button^>(sender);
    Then you could get the value of the button from button's "Text" property, so you could use one handler for all of your button clicks.

    Glad you've managed to get started. The reference docs for the controls (MSDN) are pretty decent, once you've gotten over the initial hurdle.

  6. #6
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    couldnt sleep!!! so i made an image of a red light, and one of a green light, made the green not visible, and red visible, stacked one on top of the other, then a button under the lights.

    then added
    Code:
        
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    if (pictureBox1->Visible == true)
             {
                 pictureBox1->Visible = false;
                 pictureBox2->Visible = true;
                 SetDigitalChannel(1);
             }
       else
            {
                 pictureBox2->Visible = false;
                 pictureBox1->Visible = true;
                 ClearDigitalChannel(1);
            }
    }
    
    so the button toggles the relay on and off, while having the green light visible for on, and red for off!!!

    GREAT Start already!!!

    Oh for adding the coding for the DLL, i just copied there Demo program sections, including the "search for card" grouping!

    if you want, ill post the form1.h file for you to look at.
    Last edited by Crossfire; 12-29-2012 at 07:37 AM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Just to add...
    Windows Form is for C++/CLI, which is not C++. You may get better help if you post these kinds of threads in the future in TechTalk instead of here since this covers only native C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    Quote Originally Posted by Elysia View Post
    Just to add...
    Windows Form is for C++/CLI, which is not C++. You may get better help if you post these kinds of threads in the future in TechTalk instead of here since this covers only native C++.
    um....huh???

    VC++ set everything up for me, all i did was add to the form!!!

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Like I said, forms are not C++. Visual Studio is an IDE from Microsoft that compresses all their technologies into one product. You are not using C++, you are using C++/CLI.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Elysia you are not a moderator yet.

  11. #11
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    ok got it, question i have also, can i make a win32 gui program from just c++ or C? cause i would like that MUCH better then this vc++ crap, and easier for touch screen then console

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by whiteflags View Post
    Elysia you are not a moderator yet.
    Meh. If I were a moderator, I would move this and just say "Don't do this, or I'll ban you"

    Quote Originally Posted by Crossfire View Post
    ok got it, question i have also, can i make a win32 gui program from just c++ or C? cause i would like that MUCH better then this vc++ crap, and easier for touch screen then console
    Yes, it's possible.
    Easier or not is debatable. Regardless of what you choose, you need to learn how to use it properly.
    Anyway, a popular GUI Framework for native C++ is Qt.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by Elysia View Post
    Meh. If I were a moderator, I would move this and just say "Don't do this, or I'll ban you"
    I look forward to you getting evicted for such casual abuse.

  14. #14
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    well i made my first gui program in c!!!
    Code:
    #include <windows.h>
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
    {
    MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
    return 0;
    }
    ps now that i know forms are NOT c++ as i thought it was, you can move this to where it needs to go!!!

    thanks!

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    o_O
    Nah, I wouldn't do that. I would only do that in my nightmares.
    I would only move the thread, and the rest would be the same as now.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed