Thread: button click

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    14

    button click

    ok I have another noobie question. In Visual C++ I have a button on "Form1", I want it to run a function in "program.cpp".


    I also have a label named "label1" and in the function in "program.cpp" I want to change the label's text but I cant figure out how to do this either

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    ??!?¿?!!!
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    sorry

    In Visual C++ I have a button on "Form1", I want it to run a function in "program.cpp" when it is clicked.

    Code:
    so: button is clicked
    
    in Form1.h
    -------------
    
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                                changetext();
    			 }
    
    in program.cpp
    ------------------
    
    void changetext() {
         label1->Text = "Hey";
    }
    
    
    But none of this works
    I also have a label named "label1" and in the function in "program.cpp" I want to change the label's text but I cant figure out how to do this either
    Last edited by Stringer; 10-12-2006 at 06:44 PM.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    You need to learn how to process "GUI messages".

    Do you have a book on GUI programming? You are going to need one.

    I assume this is Windows, so here's a tutorial.

    ok I have another noobie question...
    If you are new to C++ you need to learn standard (non-GUI) C++ before getting into this.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    yeah I learned basic coding and I am currently just beginning to learn "GUI programming"

    Is their a really good book I could buy that would teach me coding and GUI programming, I have one but its really outdated

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    I still cant understand how to do this, its driving me crazy

    in borland C++ builder when I put a button on a form and double click it I get something like "void __fastcall TForm1::ButtonClick...." but it puts it in the .cpp file not the header file. Then all I have to do is put code in that function.

    In visual C++ I cant do anything because it wont let me call functions or variables from .cpp to .h or .h to .cpp. I cant do anything with anything

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    GUI programming goes to a platform specific board.

    Code:
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                                changetext();
    			 }
    What the...? You call that Win32 API. If you don't, name the wrapper!
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It's C++/CLI, obviously (the only language where you might see a ^ after a type.)

    OP: your posts suggest that you don't know the basics well enough to start GUI programming yet. Also, C++/CLI is not C++, and thus not a good option for learning GUI programming in C++.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    That C++/CLI looks so ugly.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    I used windows forms when I was using visual basic, I hated it to be honest. Much prefer C++

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Windows Forms is a .Net technology. Not a Visual Basic one. You used it with VB.Net
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    this
    Code:
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    			 }
    was generated by Visual C++. I dont understand anything about it except that it does whatever is between {} when button1 is clicked on the form.

    I really need to figure this out even if im not ready for it yet, I can get almost everything to work in "Borland C++ Builder 6" but I switched to Microsoft "Visual C++ Express" because it makes everything else easier and this is the only thing holding me up.

    all I want to know is how to change the text of a label from the source file and how to run a function in the source file when a button is clicked. (In Microsoft Visual C++ Express)
    Last edited by Stringer; 10-13-2006 at 10:34 AM.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    System::Object^  sender, System::EventArgs^  e
    I've never seen that syntax before, except in Pascal. Are you sure they aren't *s?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    Why don't you just use standard VB coding? I mean, underneath your command button coding, just put which page you want to come with the button. Meaning let's say you made another page well .Hide the page with your command button and then .Show the next page you want to show up.

  15. #15
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by dwks
    Code:
    System::Object^  sender, System::EventArgs^  e
    I've never seen that syntax before, except in Pascal. Are you sure they aren't *s?
    That is C++/CLI, it's the newer way to use .NET in Visual Studio 2005, as Managed C++ is now deprecated.

    Essentially a compiler-specific extension to the language. ^ is a handle to a managed object (e.g. one that's automatically garbage collected).
    Last edited by Cat; 10-13-2006 at 10:34 PM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a function pointer from a button click event?
    By dxfoo in forum Windows Programming
    Replies: 20
    Last Post: 01-29-2008, 03:35 AM
  2. Button click out of WM_COMMAND
    By Sober in forum Windows Programming
    Replies: 8
    Last Post: 05-03-2007, 09:07 PM
  3. Updating window after button click?
    By ac251404 in forum Windows Programming
    Replies: 0
    Last Post: 07-18-2006, 10:20 AM
  4. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 08:53 AM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM