Solved

How to resize MDI window fitting image ??

Posted on 1998-07-24
14
548 Views
Last Modified: 2012-08-13
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
Comment
Question by:sjlee092297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 

Author Comment

by:sjlee092297
ID: 1168580
Edited text of question
0
 

Author Comment

by:sjlee092297
ID: 1168581
Edited text of question
0
 
LVL 1

Expert Comment

by:ppeck
ID: 1168582
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
Independent Software Vendors: 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!

 

Author Comment

by:sjlee092297
ID: 1168583
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
 

Author Comment

by:sjlee092297
ID: 1168584
Adjusted points to 200
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168585
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168586
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
 

Author Comment

by:sjlee092297
ID: 1168587
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
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1168588
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168589
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
 
LVL 1

Expert Comment

by:ppeck
ID: 1168590
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
 

Author Comment

by:sjlee092297
ID: 1168591
Thank you for your excellent answer,  especially, ppeck..  :-)
                                                          - sjlee
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168592
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
 

Author Comment

by:sjlee092297
ID: 1168593
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maze travler 6 66
C++ assignment question 7 268
Fully specialized class template function 21 146
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 161
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question