Solved

How to resize MDI window fitting image ??

Posted on 1998-07-24
14
526 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
  • 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now