Resizing a static variable
-
Here is a description of my problem. I have a modal dialogue window. In my OnInitDialog function, I may have to adjust the size of the window and it's contents manually because sometimes when the dialogue is constructed, an argument is passed into the constructor that turns off the display of certain controls within the window. So when the controls are off, I want to change the size of the window and remaining controls so that everything looks nicer (I don't want a huge blank spot in the middle of the window in this case). So everything was working fine; I tried changing the window size of the dialogue and that worked fine. I know I can move buttons around and adjust them just like you do when a dialogue box is resizable by the user. But how do I resize a static group control? The group box is a border rectangle that surounds the controls and is just inside of the main dialogue. When I run the below bits of code, the GetClientRectangle function causes my system to crash. The group box is a CStatic control which inherits from CWnd. So it must have a rectangle, within the object, to describe it's coordinates. So why does GetClientRect fail? Is this not a valid function call for a CStatic control? If not, how do I get it's coordinates? mGroupBox.GetClientRect(&myRect); //Crash!!! //This would then adjust the height by 25% mGroupBox.SetWindowPos(NULL, 0, 0, myRect.Width(), (myRect.Height() - (myRect.Height()/4)), SWP_NOMOVE | SWP_NOZORDER);
-
Here is a description of my problem. I have a modal dialogue window. In my OnInitDialog function, I may have to adjust the size of the window and it's contents manually because sometimes when the dialogue is constructed, an argument is passed into the constructor that turns off the display of certain controls within the window. So when the controls are off, I want to change the size of the window and remaining controls so that everything looks nicer (I don't want a huge blank spot in the middle of the window in this case). So everything was working fine; I tried changing the window size of the dialogue and that worked fine. I know I can move buttons around and adjust them just like you do when a dialogue box is resizable by the user. But how do I resize a static group control? The group box is a border rectangle that surounds the controls and is just inside of the main dialogue. When I run the below bits of code, the GetClientRectangle function causes my system to crash. The group box is a CStatic control which inherits from CWnd. So it must have a rectangle, within the object, to describe it's coordinates. So why does GetClientRect fail? Is this not a valid function call for a CStatic control? If not, how do I get it's coordinates? mGroupBox.GetClientRect(&myRect); //Crash!!! //This would then adjust the height by 25% mGroupBox.SetWindowPos(NULL, 0, 0, myRect.Width(), (myRect.Height() - (myRect.Height()/4)), SWP_NOMOVE | SWP_NOZORDER);
;)well..... i dontsee anthing wrong..... mGroupBox.GetClientRect(&myRect).....where mGroupBox happenz to be the CStatic Object the "mGroupBox" IS A CWnd type and pointing to the static window(have u given the DDX control??).....once this is done.....use the SetWindowPos function(i have not used this,but i think maybe U HAVENT LINKED THE VARIABLE TO THE WINDOW USIND DDX maybe thatzthe prob)..... best of luck..... happy programmin...... cheerz..... :-D
-
;)well..... i dontsee anthing wrong..... mGroupBox.GetClientRect(&myRect).....where mGroupBox happenz to be the CStatic Object the "mGroupBox" IS A CWnd type and pointing to the static window(have u given the DDX control??).....once this is done.....use the SetWindowPos function(i have not used this,but i think maybe U HAVENT LINKED THE VARIABLE TO THE WINDOW USIND DDX maybe thatzthe prob)..... best of luck..... happy programmin...... cheerz..... :-D
The problem was that I was trying to implement the aforementioned code in my OnInitDialog method, prior to calling CDialog::OnInitDialog like so BOOL UDxFilterDlg::OnInitDialog() { //NO! NO! Can't do this here. Must call //CDialog::OnInitDialog(); first! CRect rect; mGroupBox.GetClientRect(&rect); mGroupBox.SetWindowPos(NULL, 0, 0, rect.Width(), (rect.Height() - (rect.Height()/3)), SWP_NOMOVE | SWP_NOZORDER); CDialog::OnInitDialog(); //Resize the group box below this point and it works fine! //..rest of code }