Thread: buttons problem

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    99

    buttons problem

    hi again. Im having a few problems to do with a few of the components on my program. Firstly I have a button that once pressed allows the user to select a file and store its path in a variable. I would like to be able to access this variable whenever other buttons are used in my program but I cnt seem to find a way to pass the variable to each of my button components. Im not totally sure but I dont think its possible to make a variable global from within a button, and from looking around the only over thing i have come across is creating its own .h file which is something i have no clue about and would like to avoid if possible.

    thanks any help will be appreciated

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    At this forum, we generally believe that one should walk before one runs. We also believe that you should write console programs to learn the basics of programming before you use an interface editor to create a GUI with buttons.

    The button is the wrong place for this variable. In your program organization, the right place for the variable is probably the form containing the button. How you put the variable there and how to access it from the buttons, though, is for you to figure out.
    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

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I am starting to seriously wonder about your level of aptitude for doing whatever it is that you are doing. SetWindowLongPtr() is great for setting or retreiving some sort of data from a button control (assuming you are even using windows), but its not the best way of doing things unless you are actually wanting another process to have some sort of access to your button.

    What are you doing? I mean that in the must blunt sense of the question. Can you explain why you are saving variables within a button, and how you are doing so. I somehow have a feeling you are not creatively using the GWLP_USERDATA or DWLP_USER flags with SetWindowLongPtr() to accomplish this task, so I can only assume you are setting the button text to a value and retreiving that value...

    I may be wrong, so feel free to enlighten me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM