Thread: Problem in processing the buttons created at runtime

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    4

    Question Problem in processing the buttons created at runtime

    Hello everybody,
    I am developing a small game using MFC in which the game options like new game, save, open, exit etc. can be selected from the menu as well as from the buttons inside the window. I have no problems with the menu but the buttons do not seem to work at all.
    The buttons are created at runtime using CButton class. To associate the buttons with the corresponding functions, I just used the same resource ID for the buttons as the menu options, but that did not work. When I click on the buttons, nothing happens. If I assign different resource IDs to the buttons, how do I handle the message map entries? Do I have to write different message map entries for the menus and the buttons while their function is exactly the same?

    Thanks for your time.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Try double-clicking the buttons or right-clicking them to add an event handler for them. You don't need to mess with the resource IDs.
    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.

  3. #3
    Registered User
    Join Date
    Oct 2014
    Posts
    4
    Thanks for the reply Elysia, but I could not follow your reply. As I have already said, the buttons are created at runtime, so where do I right click? The buttons are created on the client area of the output window. Plus, I'm not using Visual C++ studio, if you are referring to that. VC++ did not run on my computer and I'm using borland c++ 5.02 (where nothing happens by right-clicking or even double clicking ).
    Could you please elaborate about the event handlers? I don't have much knowledge about them, and I guess that's what I'm missing!

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I missed the tidbit of how you "create" your buttons at runtime. Then I don't know. MFC does not allow for "hot plugging" buttons into the framework at runtime as far as I know. You may have to steal the window proc and do it the old way.
    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.

  5. #5
    Registered User
    Join Date
    Oct 2014
    Posts
    4
    Quote Originally Posted by Elysia View Post
    MFC does not allow for "hot plugging" buttons into the framework at runtime as far as I know. You may have to steal the window proc and do it the old way.

    I'm already using MFC to create the buttons at runtime. They don't work yet, but if it was not allowed, I would not be able to create them anyway, I guess?
    I don't like the old ways of using the windows APIs. Its like using the DOS instead of the windows, which I don't like at all.


    P.S. To create the buttons at runtime, I'm using CButton class inside the OnDraw function of the View class (Doc/View Architecture).

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    Registered User
    Join Date
    Oct 2014
    Posts
    4
    I'm trying to use that in my application. Thanks for the link.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-20-2012, 09:27 PM
  2. Replies: 3
    Last Post: 08-13-2012, 02:03 AM
  3. buttons problem
    By pastitprogram in forum C++ Programming
    Replies: 2
    Last Post: 09-03-2008, 05:41 PM
  4. Runtime problem
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 10-30-2005, 06:30 PM
  5. Buttons & Toolbars Problem.
    By dug in forum Windows Programming
    Replies: 9
    Last Post: 07-31-2003, 09:23 AM

Tags for this Thread