Solved

ATL Composite control - Resizing at run time

Posted on 2003-12-01
12
549 Views
Last Modified: 2013-11-25
Hi
I'm developing an ATL composite control which has two components (a button and a list box). The list box won't be visible initially; when the button is clicked the list box should appear. The initial area of the composite control just accomodates the button. Only when the button is clicked the composite control area should be increased to accomodate the list box. I tried changing the values of m_sizeExtent and m_sizeNormal; it didn't work. Is there a way to solve this issue? Your suggestions will be valuable.
Thanks.

Regards
Saravanan.
0
Comment
Question by:SaravananMP
  • 7
  • 4
12 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9851033
Is the pCtrl->SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE) of any use - cx  and cy are the new width/height you want and pCtrl is a pointer to the control.
0
 

Author Comment

by:SaravananMP
ID: 9855809
Hi
The issue here is the control has to resize itself. SetWindowPos didn't work. The control area is decided by the variables m_sizeExtent and m_sizeNatural. Can by some means these variables be changed after the construction of the control to change the control area?
0
 
LVL 12

Accepted Solution

by:
migel earned 300 total points
ID: 9857350
Hi!
In general you have to inform host about control size changing
for example:
///

      // Toggle control size here.
      RECT newPos;
      newPos = m_rcPos;
      newPos.right += 5;
      newPos.bottom  += 5;
            
      HRESULT hRet;
      CComPtr<IOleInPlaceSite> spCtlSite;
      hRet = InternalGetSite(IID_IOleInPlaceSite, (void**)&spCtlSite);
      if (SUCCEEDED(hRet))
      {
            if (spCtlSite != NULL)
            {
                  // (Try) to change control size,
                  // provided the container cooperates.
                  hRet = spCtlSite->OnPosRectChange (&newPos);
            }
      }
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SaravananMP
ID: 9858814
Could change the control size. While testing, I had a button control right below my composite control in the host window. As expected the button got hidden when the list box in my composite control dropped down. When I tried selecting an item in the list box through mouse click, the button (which is hiding) below my control is clicked and the button is visible there after. Sorry to bother you. Can this be solved?
Thanks.
0
 
LVL 12

Expert Comment

by:migel
ID: 9859545
hm...
It is another question isn`t it? :-)
It`s so strange may be it is a bug of the ActiveX host you use.
Do you check it under VB?
0
 

Author Comment

by:SaravananMP
ID: 9864264
Thanks.
I will check it.
0
 

Author Comment

by:SaravananMP
ID: 9962496
Hi
The call to spCtlSite->OnPosRectChange (&newPos); returned E_NOTIMPL when I tried using this control in an ATL container. I was testing this in MFC and it worked fine. Our requirement is to host this control in an ATL composite control. Any pointers to solve this issue?

Thanks & Regards
Saravanan.
0
 
LVL 12

Expert Comment

by:migel
ID: 9962801
Hi!
It is known ATL hosting bug:
In this case you can manually resize your control by:

          hRet = spCtlSite->OnPosRectChange (&newPos);
          if(FAILED(hRet))
{
          //Change the control's extents
          SIZE size;
          size.cx=m_rcPos.right;
          size.cy=m_rcPos.botom;
         
          HWND hwndContainer=GetContainerWindow(m_spClientSite);
          HDC hdc=::GetDC(hwndContainer);
          DPtoHIMETRIC(hdc, &size);
          ::ReleaseDC(hwndContainer,hdc);
          SetExtent(DVASPECT_CONTENT,&size);
}
}
0
 

Author Comment

by:SaravananMP
ID: 9963998
Hi
Thanks for your response.
The code didn't compile when I tried this method. The error is
'GetContainerWindow' : undeclared identifier. Is there are a method equivalent to GetContainerWindow?

Thanks & regards
Saravanan.
0
 

Author Comment

by:SaravananMP
ID: 9964088
Hi
DPtoHIMETRIC too is undeclared. I guess, DPtoHIMETRIC is a member of CDC class and I won't be able to use CDC in my ATL control class.
0
 
LVL 12

Expert Comment

by:migel
ID: 9965361
oops sorry - this was an old project snippet.
here is right code
  SIZEL szlMetric;
           size.cx=m_rcPos.right;
          size.cy=m_rcPos.botom;
 
   AtlPixelToHiMetric(&szlPixels, &szlMetric);
   // IOleObjectImpl
   SetExtent(DVASPECT_CONTENT, &szlMetric);

0
 

Author Comment

by:SaravananMP
ID: 9989613
Hi
I tried this; It didn't work. When I searched for a work around, I found this article:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q242994
Thanks.

Regards
Saravanan.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS 2010 Convert to SSIS 2013 On Different Box 3 63
wordmultiple challenge 12 156
Detect file exist or not 3 202
Authentication of Web Services 3 96
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

733 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