MFC Programming Help - CView Window Width

  • Thread starter Thread starter pervect
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary
For MFC programming help, particularly with version 6.0, users are seeking effective methods to determine the width of a CView window for proper line-breaking in the OnDraw() function. A common issue arises when using the device context pointer pDC and calling pDC->GetWindowExtent(), which returns a size of 1,1, leading to confusion about whether the correct function is being used or if there are setup issues with the window. To accurately obtain the window dimensions, utilizing the GetClientRect function is recommended. This involves defining a RECT structure, calling GetClientRect to fill it, and then calculating the width and height based on the RECT values. This approach ensures that the displayed text lines fit appropriately within the window.
pervect
Staff Emeritus
Science Advisor
Homework Helper
Insights Author
Messages
10,436
Reaction score
1,599
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
Try this:

RECT rect;
GetClientRect(&rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
3K
Replies
5
Views
2K
Replies
2
Views
6K
  • · Replies 75 ·
3
Replies
75
Views
6K
Replies
23
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K