CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 1999
    Posts
    2

    Programmatically created buttons & strings



    In my project I have to display strings as well as buttons with lables. The number & content of text strings, buttons and their positions in the window can only be determined at run time. It is, of course, necessary to be able to detect which button has been pressed by the user. I am most grateful if someone could give me some hints on how to go about doing it.


    Thanks



  2. #2
    Join Date
    Apr 1999
    Posts
    32

    Re: Programmatically created buttons & strings



    Creating buttons on the fly is quite a simple matter. You just need something like this:

    <P>

    // this is the buttons identifier. It's used in the parent's command<BR>

    // handler<BR>

    #define BTN_ID_1 100<BR>

    <P>

    CRect btnRect(5,5,25,25);<BR>

    CButton *pButton = new CButton();<BR>

    <P>

    pButton.Create ("Click me", BS_PUSHBUTTON, btnRect, this, BTN_ID_1 );<BR>

    <BR>

    // button is created. Rememeber to delete it later (delete pButton)<BR>

    <P>

    Somewhere you need a Command handler, this will be in the buttons' parent

    window (or dialog)

    <P>

    BOOL CMyDialog::OnCommand( WPARAM wParam, LPARAM lParam )<BR>

    {<BR>

    switch (LOWORD(wParam))<BR>

    {<BR>

    case BTN_ID_1:<BR>

    //...<BR>

    break;<BR>

    }<BR>

    }<BR>

    I hope this answersthe question. If not, please do feel free to email me any questions directly and I will do my best

    to answer them.

  3. #3
    Join Date
    Mar 1999
    Posts
    2

    Re: Programmatically created buttons & strings



    Thanks, I'll try it. Since the number of buttons will vary (from 0 to 35), can they ALL be handled by a single command handler and identified by a single BTN_ID ? We must then detect the button being pressed by its position. Is it possible for the command handler to detect the position of the pressed button?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured