Solved

ATL Composite control - Resizing at run time

Posted on 2003-12-01
12
509 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
I will check it.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:SaravananMP
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now