Link to home
Start Free TrialLog in
Avatar of alexatsearidge
alexatsearidgeFlag for Canada

asked on

Need to resize ActiveX control at start up. OnSize of dialog is called before ActiveX Control is a window and cannot be used.

Hello and happy Friday everyone; I have yet another question.  

I have an activeX control on my dialog that I resize by using a method ResizeControl, in the OnSize message of my dialog.  
This works properly once the program is running.  If I resize the dialog my control positions and resizes perfectly.

My problem is that at startup the ResizeControl is not called and my control always starts in the top left corner.
For safety sake I need to make sure that the Dialog and the Control are both Windows before calling ResizeControl.
Is there any init method that I could use where the Window and the Control would both be windows so I could call ResizeControl?

Thanks,
Avatar of mahesh1402
mahesh1402
Flag of India image

>>For safety sake I need to make sure that the Dialog and the Control are both Windows before calling ResizeControl

you may use IsWindow() API  function at startup to determine if window is really created and exist..

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/iswindow.asp


-MAHESH
e.g. At startup you may use IsWindow like :

if(IsWindow(m_MyDialog.m_hWnd)==TRUE) //m_MyDIalog is member variable for CDialog
{
//Resize Dialog
}

if(IsWindow(m_Ctrl.m_hWnd)==TRUE) //m_Ctrl is member variable of your control
{
//Resize Control
}


-MAHESH

Avatar of alexatsearidge

ASKER

Thanks Mahesh,

I am currently using IsWindow to double check.  The problem is that my code is in the OnSize of my main dialog and the first call to OnSize is before the dialog is a window.  This means that I cannot make a call to my ActiveX control yet because it is not a window.  

I need another method that I can use that will be called at start up but only after the window has been created.
So you may perform resizing only if window is created otherwise return from function...so that your resize code will execute if and only if your dialog / control is fully created

CMyDialog::OnSize()
{

if(IsWindow(m_Control.m_hWnd)==TRUE) // OR if(IsWindow(m_Control.GetSafeHwnd ( )==TRUE)
  //Proceed with Resize
else
 return;

}

-MAHESH
ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mahesh I think perhaps I wasn't expressing myself properly.

I needed someway of redrawing my ActiveX control on a property page at start up.  The problem is that the control was being created after OnSize and OnInitDialog so that if I try to resize it there I could not because the window was not created yet.

I've solved the problem by calling the resize in the first tick of my timer.  
Thanks for your help though.
alexatsearidge,
You could use FindWindow() API function for this purpose too..you may pass class name or window title name to detect window is present or not..

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/findwindow.asp?frame=true

-MAHESH