该程序的下载地址:http://download.csdn.net/source/1059066 在Dialg.h文件中
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
);在Dialg.cpp文件中
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
//RECT rrr;
//rrr.left = 0;
//rrr.top = 0;
//rrr.right = 300;
//rrr.bottom = 30;
//m_edit.Create( WS_VISIBLE, rrr, this, 1000 );
//m_edit.ModifyStyleEx( 0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);
parent = this;
EnumChildProc( 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::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();
}

}在该程序资源的对话框中我添加AcitveX控件,执行该程序。发现一个问题,Active控件能随着对话框大小按比例缩放,但是缩放后用鼠标点击该ActiveX控件后,该ActiveX会缩放到初始时的位置及大小,但是工具箱中标准的控件没有此问题。不知道什么原因?可能是AcitveX控件封装它自己的onsize后的重绘方法??希望大家能帮帮我 ,此问题 困扰我好几天啦 

解决方案 »

  1.   


    该程序的下载地址:http://download.csdn.net/source/1059066 
      

  2.   

    比如你加个adobe PDF Reader这个activex控件,先给它关联一个变量 
    然后把你那个程序里的onsize函数写成这样 
    while( t->next ) 

    if (m_pdf.GetSafeHwnd() == t->next->h) 

    m_pdf.MoveWindow( 
    ( 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 ), 
    TRUE); 

    else 

    ::MoveWindow(t->next->h, 
    ( 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 ), 
    TRUE); 
    } t = t->next; 

    就有你要的效果了
      

  3.   

    void CXXDlg::OnSize(UINT nType, int cx, int cy) 
    { CDialog::OnSize(nType, cx, cy); if   (GetSafeHwnd())  
    {
    if(m_gg.GetSafeHwnd())
    {
    m_gg.MoveWindow(1,1,cx-2,59);
    }
    }
    }
    m_gg 为你的控件的对象
      

  4.   


    哎,你试下不就知道行不行了,我用SetWindowPos试过了,不行~
    MoveWindow可以~