• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 570
  • Last Modified:

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.. :-)
0
sjlee092297
Asked:
sjlee092297
  • 7
  • 5
  • 2
1 Solution
 
sjlee092297Author Commented:
Edited text of question
0
 
sjlee092297Author Commented:
Edited text of question
0
 
ppeckCommented:
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.

Regards,
Patrick

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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.  :-)
0
 
sjlee092297Author Commented:
Adjusted points to 200
0
 
nietodCommented:
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?
0
 
nietodCommented:
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().
0
 
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.
0
 
nietodCommented:
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.
0
 
nietodCommented:
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);

AdjustWindowRect(&Rct,Style,false,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 - Rct.top;

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.  



0
 
ppeckCommented:
Hi,

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
      cr.left=0;
      cr.right=320;
      cr.top=0;
      cr.bottom=200;
      // 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)
      wp.x=wr.left;
      wp.y=wr.top;
      ScreenToClient(GetParent(hWnd), &wp); // convert position to client coordinates
      MoveWindow(hWnd, wp.x, wp.y, cr.right-cr.left, cr.bottom-cr.top, 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,

Patrick


0
 
sjlee092297Author Commented:
Thank you for your excellent answer,  especially, ppeck..  :-)
                                                          - sjlee
0
 
nietodCommented:
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.
0
 
sjlee092297Author Commented:
Oops!

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. :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now