Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create controls in run time and arrange it to certain position on screen.

Posted on 1999-06-30
9
Medium Priority
?
208 Views
Last Modified: 2013-11-20
I used to create a control set (eg: buttons) on a screen in run time using Visual Basic ......BUTTON_NAME(index), where index = 0,1,2,.....n , Calculate the screen size and arrange them into columns and rows.

Can somebody tell me how to do that in VC++.
Thx for your time :)
0
Comment
Question by:jiada
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 

Expert Comment

by:eetay
ID: 1308433
Hello.

The code would be something like:

CButton *pButtons = new CButton[10];
for (int i=0; i<10; i++)
{
   pButtons[i].Create(...);
}

-- Eetay
0
 

Expert Comment

by:eetay
ID: 1308434
Create(
    "MyButtonCaption",
    WS_CHILD|WS_VISIBLE,
    CRect(...), //the button position
    pParent, //the dialog's CWnd pointer
    i // the index of the 'for' statement, just index number for the button, so i can use GetDlgItem to get the buttons from the dialog if I want
    );
0
 

Author Comment

by:jiada
ID: 1308435
Adjusted points to 50
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Expert Comment

by:Extreme
ID: 1308436
eetay looks good to me, a similar approach I used in an app has one button already on screen (m_PB_FIRST) and each dynamic button added under the last as follows:

// in header
CArray< CWnd*, CWnd*>      m_aButtons;
long lButtonHeight

// in cpp
      RECT rOriginalButton;
      m_PB_FIRST.GetWindowRect(&rOriginalButton);
      lButtonHeight = (rOriginalButton.bottom - rOriginalButton.top);

      CButton* pButton = new CButton;

      RECT rDialog;
      this->GetWindowRect(&rDialog);
      RECT rNewButton;
      m_PB_FIRST.GetWindowRect(&rNewButton);

      ScreenToClient( &rNewButton);
      long lPos = (m_aButtons.GetSize() +1) * lButtonHeight;
      rNewButton.top += lPos;
      rNewButton.bottom += lPos;

      if( pButton->Create( strName,
                              BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
                              rNewButton,
                              this,
                              BUTTON_START_ID + m_aButtons.GetSize()))
      {
            m_aButtons.Add( pButton);
            CFont* pFont = m_PB_OOPS.GetFont();

            pButton->SetFont( pFont);

            pButton->ShowWindow( SW_NORMAL);

      }

0
 

Expert Comment

by:Extreme
ID: 1308437
sorry :o), the m_PB_OOPS up there is supposed to be m_PB_FIRST, (my fat fingers)
0
 

Expert Comment

by:Extreme
ID: 1308438
screen size can then be calculated using:

            SetWindowPos(      &wndTopMost,
                                    rDialog.left,
                                    rDialog.top,
                                    rDialog.right - rDialog.left,
                                    rDialog.bottom - rDialog.top + rNewButton.bottom - rNewButton.top,
                                    SWP_SHOWWINDOW);

0
 

Author Comment

by:jiada
ID: 1308439
Hello everybody. Thanks for all your ideas :)

I believe that the above codes can help us to create controls in run time. but how to change the button's size for different screen resolution in a always-maximized dialog?

eg: if screen size = dialog size = 1000X, 1000Y
    button1 will always set to position 200X 300Y,
        with width 200X and height 100Y;      
    button2 will always set to position 400X 300Y,
        with width 200X and height 100Y;        etc.


0
 

Accepted Solution

by:
Extreme earned 240 total points
ID: 1308440
the MoveWindow function:

CWnd* pButton = whatever button you have :o)
RECT rButton;
pButton->GetWindowRect(&rButton);
ScreenToClient( &rButton);
// Calc coordinates for
rButton.bottom = ?;
rButton.top = ?;
rButton.left = ?;
rButton.right = ?;
pButton->MoveWindow(&rButton);


0
 

Author Comment

by:jiada
ID: 1308441
I am newbie in vc++, sorry I don't how to apply your ideas in my code with my poor skill. Could anybody please send to me a sample project which can do all the functions discussed above to jiada@hotmail.com by July 23, or I will award the points to Extreme.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question