Solved

How to resize MDI window fitting image ??

Posted on 1998-07-24
14
555 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
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!

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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