Solved

ATL Composite control - Resizing at run time

Posted on 2003-12-01
12
534 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 97
Problem to DocumentFormat 8 94
EvenOdd challenge 10 108
Access 2013: API code to put hidden database icon in taskbar? 8 79
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

810 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