在一个按钮单击消息中创建一个对话框,希望能控制他的尺寸,那么如何能使这个对话框以及上面的控件按比例缩放而不是被截断或扩大呢?谢谢大家了

解决方案 »

  1.   

    举个例子,这个例子没有经过仔细测试在.h中声明/////////////////////////////////////////////////////////////////////////////
    // CSize1Dlg dialog
    struct MyRect
    {
    double left;
    double top;
    double right;
    double bottom;
    };
    struct MyControlSize
    {
    struct MyRect r;
    HWND h;
    struct MyControlSize *next;
    struct MyControlSize *last;
    };BOOL CALLBACK EnumChildProc(
      HWND hwnd,      // handle to child window
      LPARAM lParam   // application-defined value
    ); void MyDelete( void );在.cpp中
    /////////////////////////////////////////////////////////////////////////////
    // CSize1Dlg message handlers
    struct MyControlSize first;
    CSize1Dlg *parent;
    struct MyRect pr;
    int ttt;
    int ppp;BOOL CALLBACK
    EnumChildProc( HWND hwnd, LPARAM lParam )
    {
    struct MyControlSize *t;
    t = &first;
    while( t->next )
    {
    t = t->next;
    }
    t->next = new struct MyControlSize;
    t->next->next = NULL;
    t->next->h = hwnd;
    t->next->last = t;
    RECT r;
    ::GetWindowRect( hwnd, &r );
    t->next->r.left = ( double )r.left;
    t->next->r.top = ( double )r.top;
    t->next->r.right = ( double )r.right;
    t->next->r.bottom = ( double )r.bottom;
    return 1;
    }BOOL CSize1Dlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    parent = this;
    EnumChildWindows( this->m_hWnd, EnumChildProc, 0 );
    RECT r;
    RECT rr;
    GetClientRect( &r );
    GetWindowRect( &rr );
    ppp = ( rr.right - r.right ) / 2;
    ttt = rr.bottom - r.bottom - ppp;
    pr.left = ( double ) r.left;
    pr.top = ( double )r.top;
    pr.right = ( double )r.right;
    pr.bottom = ( double )r.bottom;

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CSize1Dlg::OnOK() 
    {
    // TODO: Add extra validation here
    MyDelete();
    CDialog::OnOK();
    }void CSize1Dlg::OnCancel() 
    {
    // TODO: Add extra cleanup here
    MyDelete();
    CDialog::OnCancel();
    }
    void
    CSize1Dlg::MyDelete( void )
    {
    struct MyControlSize *t = &first;
    while( t->next )
    {
    t = t->next;
    }
    while( t->last )
    {
    t = t->last;
    delete t->next;
    }
    }void CSize1Dlg::OnSize(UINT nType, int cx, int cy) 
    {
    CDialog::OnSize(nType, cx, cy);

    // TODO: Add your message handler code here
    static bool bfirst = false;
    if( !bfirst )
    {
    bfirst = true;
    }
    else
    {
    struct MyControlSize *t = &first;
    RECT r;
    GetClientRect( &r );
    double xx = ( r.right - r.left ) / ( pr.right - pr.left );
    double yy = ( r.bottom - r.top ) / ( pr.bottom - pr.top );
    while( t->next )
    {
    ::SetWindowPos( t->next->h,
    0,
    ( int )( ( t->next->r.left -ppp ) * xx ),
    ( int )( ( t->next->r.top - ttt ) * yy ),
    ( int )( ( t->next->r.right - t->next->r.left ) * xx ),
    ( int )( ( t->next->r.bottom - t->next->r.top ) * yy ),
    0 );
    t = t->next;
    }
    Invalidate();
    }

    }