Thread: VC++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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
    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

  11. #11
    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.

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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.

  13. #13
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    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
    I'd also recommend Qt. I haven't used it for years - but my memories of it are that it had a slightly steeper initial learning curve than Windows Forms (have to understand a bit more and have less autogenerated for you). But the more I worked with it the more comfortable I was: whereas with Windows Forms I seem to get more perplexed and confused every time I use them. There's a point when they seem to just stop making much sense. The "it's not C++" fact gets more and more glaring too.

    My views might be coloured by using Windows Forms mostly for hacky prototypes -- so I haven't really taken the time to learn how it's meant to all fit together. I just keep bashing it until it behaves, which C++/CLI makes so fun and not at all frustrating

  14. #14
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    using C because i am stronger in C then C++ at the moment, as i been tutoring C for a while now, and have done very little in c++ in the last 4 years.

    and yeah the windows form app i made, i did just that, "I just keep bashing it until it behaves" lol

    basically i am taking a circuit i made for the parallel port (8 data outs + 2 control outs) and instead of using the parallel port (as everything after win me BLOCKED direct writes to the port unless you install a modified driver, and of course parallel ports are getting scarse, and usb to parallel dont work as expected)

    i replaced the parallel port with the vellman 8055 usb "adapter". using the 8 data outs and 2 analog outs.

    the program/circuit uses a "6 pass write" to send data. send one byte(data), trigger flip flop, send i byte (steering) trigger flipflop, then 1 of 320 relays are on.

    well my program was running in console in c++, but now that i am using a toughbook with the vellman board as the center of the controller, i want to be able to "see" all 320 "lights" and click the light or a button underneith to switch them. vc++ seemed the way to go, untill i discovered forms ISNT C++!!! so in short falling back to C like i said, becuase i know it better!

    is there another route that would be better?? like actually using a C++ GUI, over a C GUI?

    my orig program i was already using functions from the api.
    Code:
    void GetWindowSize()
      {
      CONSOLE_SCREEN_BUFFER_INFO csbi;
      if (GetConsoleScreenBufferInfo(
            GetStdHandle( STD_OUTPUT_HANDLE ),
            &csbi
            ))
        {
        lines   = csbi.srWindow.Bottom -csbi.srWindow.Top  +1;
        columns = csbi.srWindow.Right  -csbi.srWindow.Left +1;
        }
      else lines = columns = 0;
      }
    void SetWindowSize(int lines,int columns )
      {
      CONSOLE_SCREEN_BUFFER_INFO csbi;
      if (GetConsoleScreenBufferInfo(
            GetStdHandle( STD_OUTPUT_HANDLE ),
            &csbi
            ))
        {
        // Make sure the new size isn't too big
        if (lines   > csbi.dwSize.Y) lines   = csbi.dwSize.Y;
        if (columns > csbi.dwSize.X) columns = csbi.dwSize.X;
        // Adjust window origin if necessary
        if ((csbi.srWindow.Top  +lines)   > csbi.dwSize.Y) csbi.srWindow.Top  = csbi.dwSize.Y -lines   -1;
        if ((csbi.srWindow.Left +columns) > csbi.dwSize.Y) csbi.srWindow.Left = csbi.dwSize.X -columns -1;
        // Calculate new size
        csbi.srWindow.Bottom = csbi.srWindow.Top  +lines   -1;
        csbi.srWindow.Right  = csbi.srWindow.Left +columns -1;
        SetConsoleWindowInfo(
          GetStdHandle( STD_OUTPUT_HANDLE ),
          true,
          &csbi.srWindow
          );
        }
      } 
     
     
    
    void GetLocation()
    {
        HANDLE hStdout = GetStdHandle( STD_OUTPUT_HANDLE );
        CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo = { 0 };
        GetConsoleScreenBufferInfo( hStdout, &ScreenBufferInfo );
        X=ScreenBufferInfo.dwCursorPosition.X;
        Y=ScreenBufferInfo.dwCursorPosition.Y;
    }
    void GotoXY( short x, short y ) 
    { 
        HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ; 
        COORD position = { x, y } ; 
         
        SetConsoleCursorPosition( hStdout, position ) ; 
    }

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

Popular pages Recent additions subscribe to a feed