Getting CView window width for text line-breaking in MFC

  • Thread starter Thread starter pervect
  • Start date Start date
  • Tags Tags
    Programming
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
Staff Emeritus
Science Advisor
Homework Helper
Insights Author
Messages
10,491
Reaction score
1,639
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).
 
Physics news on Phys.org
Try this:

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