Solved

ATL Composite control - Resizing at run time

Posted on 2003-12-01
12
521 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now