How to resize MDI window fitting image ??

I make application that displays image on MDI Child window.
I use VC SDK,, and MDI windowing method. but, the MDI child
window is not resize precisely to show image.

I want to know how to resize mdi child window to fit to show
full image.

I hope your fast answer.. :-)
Who is Participating?
nietodConnect With a Mentor Commented:
AdjustWindowRectEx() will work, but I don't have your window styles.  I'll send some code as best I can, you will have to adjust.
sjlee092297Author Commented:
Edited text of question
sjlee092297Author Commented:
Edited text of question
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Hi sjlee,

check out the CWnd::CalcWindowRect function. It calculates the window
size from a given client rect. The client rect in your case is the size of the image
you want to display.


sjlee092297Author Commented:
I dont use MFC method to program.
I want to know that in SDK programming.
It is easy to implement that in MFC programming. Using CScrollView::ResizeParentToFit, You can just do it.

Anyway, Thank you for your kind answer, ppeck.  :-)
sjlee092297Author Commented:
Adjusted points to 200
Note--If you are not using an expert's answer you should reject it.

The functions AdjustWindowRect() and AdjustWindowRectEx() can be used to determine the size of a window needed to give you a desired client area size.  Is that what you need or are we missunderstanding your question?
You  don't mean you don't know how to actually move the window to the desired size and position do you?  If so you can do that with MoveWindow() or SetWindowPos().
sjlee092297Author Commented:
Hello, everyone.
My question is that I want to display image files(e.g *.bmp, *.jpg...) which have their size
(e.g. 320X240...) on the mdi child window.
So, if the mdi child window is fitted to image, it is good to view the image.
If you have ever used the Paint Shop Pro, or Adobe Paint Shop, the child window is fitted to the size of image to view.

So, I want to know How to fit the MDI child window to the size of image and if you have
the source code for doing such, please show me...

thank you for your precise answer and code, previously...  :-)

Lee S.J.
HWND WndHnd = ????; // somehow you have a window handle.
RECT Rct = {0,0,320,240};

// You can get the window styles like this or just use "hardcoded" values
// that you created the window with.  I don't have the hardcoded values
// so I'll get them this way.
DWORD Style = GetWindowLong(WndHnd,GWL_STYLE);
DWORD ExStyle = GetWindowLong(WndHnd,GWL_EXSTYLE);


Now the bottom and right edges of the Rct are adjusted.  the following is the width and height you need to use for the window  (you have to deal with the location).
int Width = Rct.right - Rct.left;
int Height = Rct.bottom -;

Note, ussually you will not need to calculate the width and height.  Ussually you will just
adjust the rectangle to the right position rather than having it set to 0,0 for the top-left corner.  


here is the code to resize the client area of the mdi child window ´hwnd´
to 320x200 points. Bonus: the window keeps its current position, it just
changes size.

              HWND hWnd; // the window to resize
      RECT cr, wr;
      POINT wp;
      DWORD style;

      // set the desired client rect size
      // get the window style
      style=DWORD(GetWindowLong(hWnd, GWL_STYLE));
      // calculate window size
      AdjustWindowRect(&cr, style, FALSE);
      // move the window
      GetWindowRect(hWnd, &wr); // current window size and position (screen coordinates)
      ScreenToClient(GetParent(hWnd), &wp); // convert position to client coordinates
      MoveWindow(hWnd, wp.x, wp.y, cr.right-cr.left,, TRUE);

I suggest you step through the code with your debugger and see what happens. Also
view the documentation of the API-functions involved (GetWindowLong, MoveWindow etc.)

Hope this helped,


sjlee092297Author Commented:
Thank you for your excellent answer,  especially, ppeck..  :-)
                                                          - sjlee
Do you know that you graded my answer, not ppeck's?  

The expert with the pending answer is the one that gets the grade.  If you feel that one expert has contributed more in a comment than the expert that posted the pending answer, then you should reject the pending answer and ask the expert that posted the comment to submit a "dummy" answer.  That way you can grade the expert that is most helpful.
sjlee092297Author Commented:

I knew that both of you and ppeck get the grade.

I am sorry, ppeck. Because I dont have  many chances to grade the answer,
I might mistake. But, Your answer is excellent. :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.