Bionicoder's Blog

Windows software development and business blog

Posts Tagged ‘atl’

Dynamically resize ActiveX control

Posted by bionicoder on July 9, 2009

Resize ActiveX control is like other  control resize.  After getting HWAND handle or CWnd object, you can call MoveWindow() or SetWindowPos() functions to resize and place the control in the specified size and area. It is not hard.  However resizing an hosted ActiveX control is not that easy. It requires more work to complete resize.  The issue is although MoveWindow() can place the hosted ActiveX in the expected size and area,  however it will go back to original place and size once you click it.

I found this problem in one of my projects.  I searched in Internet and found this solution provided by BitBucket.  This solution works well. Basically the idea is the size and area of the hosted ActiveX contro is controled by container not the ActiveX control.  As soon as the hosted Dialog resize, the container get the ActiveX control IOleInPlaceSite object and call OnPosRectChange() to place the control.

The drawback of above solution is obvious. It requires more code to complete resize. If you provide an ActiveX control to other developers to use, the above solution is not perfect.  The other possible solution is to implete OnPosRectChange within ActiveX control. Everytime, AcitveX control size change, it auto resize it self.  Need more research on this.


Posted in ActiveX, MFC, windows development | Tagged: , , , | 1 Comment »