MFC Programming Help - CView Window Width

  • Thread starter pervect
  • Start date
  • Tags
    Programming
In summary, the conversation discusses finding the width of a MFC CView window in order to properly display text. The individual has tried using the device context pointer pDC and the function pDC->GetWindowExtent(), but only receives a size of 1,1. They then suggest trying a different method using the GetClientRect() function to get the width and height of the window.
  • #1
pervect
Staff Emeritus
Science Advisor
Insights Author
10,303
1,474
Are there any good sites for MFC programming help? (THat's Microsoft Foundation Classes - C++ version 6.0 to be specific).

In case anyone here can help:

I'm trying to find the width of a MFC CView window, so I can do line-breaking in the ondraw() function, so that my displayed text lines fit the window.

Unfortunately taking the device context pointer pDC and evaulating pDC->GetWindowExtent() gives me a size of 1,1. Since I was in the default mode MM_TEXT, I thought I should get a window size in pixels. I don't know if I'm using the wrong function, or have set anything up wrong in the window (but most everything about the window the APPwizard default for SDI (single document) application).
 
Computer science news on Phys.org
  • #2
Try this:

RECT rect;
GetClientRect(&rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
 
  • #3



There are many good sites for MFC programming help, including the official Microsoft documentation and forums, as well as various online communities and forums dedicated to MFC programming. Some popular sites for MFC programming help include Stack Overflow, CodeProject, and MSDN. Additionally, there are many books and tutorials available that can provide valuable insights and guidance on MFC programming.

In regards to your specific issue with the CView window width, it's possible that you may be using the wrong function or have set something up incorrectly in your window. It may be helpful to consult the official Microsoft documentation or seek assistance from experienced MFC programmers on forums or communities. They may be able to provide specific guidance and solutions to your problem.
 

Related to MFC Programming Help - CView Window Width

1. How do I set the width of a CView window in MFC programming?

To set the width of a CView window in MFC programming, you can use the SetWindowPos function and specify the new width as a parameter. This function is part of the CWnd class and allows you to change the size and position of a window.

2. Can I resize a CView window dynamically during runtime?

Yes, you can resize a CView window dynamically during runtime by handling the WM_SIZE message in your CView class. In the message handler, you can use the SetWindowPos function to change the width of the window based on the user's input or any other conditions.

3. How do I get the current width of a CView window in MFC?

You can use the GetWindowRect function to retrieve the current width of a CView window in MFC. This function returns a CRect object containing the coordinates and dimensions of the window.

4. Is it possible to set the minimum and maximum width for a CView window?

Yes, you can set the minimum and maximum width for a CView window by handling the WM_GETMINMAXINFO message in your CView class. In the message handler, you can modify the MINMAXINFO structure to set the minimum and maximum width for the window.

5. How can I resize child windows within a CView window?

You can use the SetWindowPos function to resize child windows within a CView window. This function allows you to change the size and position of any window, including child windows, based on your desired width and height.

Similar threads

  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
16
Views
4K
  • Computing and Technology
Replies
1
Views
4K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
5
Views
957
  • Electrical Engineering
Replies
6
Views
1K
Replies
2
Views
5K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
9
Views
3K
Back
Top