MFC Programming Help - CView Window Width

  • Thread starter Thread starter pervect
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary
SUMMARY

The discussion focuses on obtaining the width of an MFC CView window in Microsoft Foundation Classes (C++ version 6.0) for proper line-breaking in the ondraw() function. The user encountered an issue where the device context pointer pDC->GetWindowExtent() returned a size of 1,1, despite being in MM_TEXT mode. The suggested solution involves using the GetClientRect() function to retrieve the client area dimensions, calculating width and height from the RECT structure.

PREREQUISITES
  • Understanding of Microsoft Foundation Classes (MFC) programming
  • Familiarity with C++ programming language
  • Knowledge of device context (DC) in Windows programming
  • Experience with the GetClientRect() function in MFC
NEXT STEPS
  • Research MFC CView class functionalities and methods
  • Learn about device context management in MFC
  • Explore the implications of coordinate mapping modes in MFC
  • Investigate advanced text rendering techniques in MFC applications
USEFUL FOR

Developers working with MFC applications, particularly those involved in UI design and text rendering within CView windows.

pervect
Staff Emeritus
Science Advisor
Homework Helper
Insights Author
Messages
10,484
Reaction score
1,636
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;
 

Similar threads

Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
92K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K