2009-01-10 14 views
27
 
     ::GetSystemMetrics (SM_CYBORDER) 

... 1 के साथ वापस आता है और मैं जानता हूँ कि शीर्षक पट्टी एक पिक्सेल से अधिक लंबी है:/विंडो सीमा चौड़ाई और ऊंचाई - मैं इसे कैसे प्राप्त करूं?

मैं भी करने की कोशिश की:

 
    RECT r; 
     r.left = r.top = 0; r.right = r.bottom = 400; 
     ::AdjustWindowRect (& r, WS_OVERLAPPED, FALSE); 
     _bdW = (uword)(r.right - r.left - 400); 
     _bdH = (uword)(r.bottom - r.top - 400); 

लेकिन सीमा डब्ल्यू, ज 0 के रूप में वापस आ गया।

मेरी WM_SIZE हैंडलर में, मैं तल पर यकीन है कि खिड़की की ऊंचाई पाठ की एक पूरी नई लाइन "चरण" में बदल कर, उदाहरण के लिए कोई "जून्की आंशिक लाइन अंतरिक्ष" के साथ खिड़की में फिट सकता बनाने की जरूरत है ।

लेकिन :: MoveWindow सीमा अंतरिक्ष में जोड़ा साथ आयाम की जरूरत है।

किसी इस से पहले किया होगा ... किसी भी मदद :)

+0

के लिये दस्तावेज 'AdjustWindowRect', का कहना है कि बल्कि असहाय रूप से, कि आप इसके साथ 'WS_OVERLAPPED' का उपयोग नहीं कर सकते हैं। – JWWalker

+0

@JWWalker: असल में, यह बल्कि सहायक है। अब यदि आप यह भी जानते हैं कि 'WS_OVERLAPPED' को '0x0' के रूप में परिभाषित किया गया है, तो यह भी स्पष्ट होना चाहिए, क्यों। – IInspectable

+0

@ अप्रत्याशित, नहीं, मुझे नहीं पता कि यह प्रासंगिक क्यों है कि 'WS_OVERLAPPED' 0. – JWWalker

उत्तर

38

GetWindowRect और GetClientRect फ़ंक्शंस का उपयोग सभी विंडो सीमाओं के आकार की गणना करने के लिए किया जा सकता है।

Suite101 पर resizing a window and the keeping client area at a know size पर एक लेख है।

GetClientRect(hWnd, &rcClient); 
GetWindowRect(hWnd, &rcWind); 
int border_thickness = ((rcWind.right - rcWind.left) - rcClient.right)/2; 

लेकिन "GetSystemMetrics (SM_CXSIZEFRAME)" में इस्तेमाल किया जा करने के लिए आसान है:

void ClientResize(HWND hWnd, int nWidth, int nHeight) 
{ 
    RECT rcClient, rcWind; 
    POINT ptDiff; 
    GetClientRect(hWnd, &rcClient); 
    GetWindowRect(hWnd, &rcWind); 
    ptDiff.x = (rcWind.right - rcWind.left) - rcClient.right; 
    ptDiff.y = (rcWind.bottom - rcWind.top) - rcClient.bottom; 
    MoveWindow(hWnd,rcWind.left, rcWind.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE); 
} 
+2

किसी दिए गए क्लाइंट क्षेत्र का आकार रखने के लिए विंडो का आकार बदलने के लिए एक WinAPI फ़ंक्शन है: AdjustWindowRectEx () – MrZebra

+1

मुझे लगता है कि मैं GetWindowRect() - GetClientRect() विधि के साथ रहूंगा। इस तरह मुझे बिल्ली से शैलियों के साथ गड़बड़ करने की ज़रूरत नहीं है। मुझे वही समस्या है जो मेरे पास GetSystemMetrics (जो भी हो) के साथ होगा ... सभी को धन्यवाद - यह जगह चट्टानें :) –

+0

यह समाधान काम नहीं करेगा यदि विंडो आकार –

9

के लिए धन्यवाद मुझे लगता है कि आप जो खोज रहे हैं SM_CYCAPTION है - यह शीर्षक पट्टी की ऊंचाई है। SM_CYBORDER खिड़की के क्षैतिज किनारों की ऊंचाई है।

+0

हैलो। मेरे [स्क्रीन कैप्चर के उपकरण] के रूप में (https://i.stack.imgur.com/Ikgeg.jpg), मुझे पता है कि शीर्षक पट्टी की ऊंचाई 28 है। लेकिन आपके 'GetSystemMetrics (SM_CYCAPTION)' बस '23' दें। – yode

+0

उस माप में खिड़की सीमा की तरह अन्य मीट्रिक शामिल हो सकते हैं। –

+0

क्या आप जानते हैं कि इसमें कौन से componenets शामिल हैं? – yode

2

हेड गीक विस्तृत उत्तर देता है: कैप्शन और सीमा बिट्स जोड़ने के लिए GetSystemMetrics का उपयोग करें। आप GetWindowRect और GetClientRect के बीच चौड़ाई/ऊंचाई पर भी अंतर कर सकते हैं। यह आपको सभी कैप्शन/सीमाओं/आदि का कुल योग देगा।

+0

एमएसडीएन पर GetSystemMetics: http://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx – stukelly

10
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); 

वास्तव में, ऊपर परिणाम के बराबर है:

यहाँ उनके नमूना कोड है।

2

स्टुकली द्वारा सुझाई गई विधि तब तक काम करेगी जब तक कि खिड़की कम नहीं हो जाती है या पूरी तरह से प्रारंभ नहीं होती है। एक वैकल्पिक दृष्टिकोण जो आपको इन शर्तों में सीमा का आकार देगा, AdjustWindowRectEx फ़ंक्शन का उपयोग करना है। यहाँ एक उदाहरण है:

CSize GetBorderSize(const CWnd& window) 
{ 
    // Determine the border size by asking windows to calculate the window rect 
    // required for a client rect with a width and height of 0 
    CRect rect; 
    AdjustWindowRectEx(&rect, window.GetStyle(), FALSE, window.GetExStyle()); 
    return rect.Size(); 
} 

आवेदन के आधार पर इसे stukelly के साथ इस दृष्टिकोण गठबंधन करने के लिए करता है, तो वर्तमान दृश्य बॉर्डर आकार के लिए आवश्यक है आवश्यक हो सकता है:

CSize GetBorderSize(const CWnd& window) 
{ 
    if (window.IsZoomed()) 
    { 
     // The total border size is found by subtracting the size of the client rect 
     // from the size of the window rect. Note that when the window is zoomed, the 
     // borders are hidden, but the title bar is not. 
     CRect wndRect, clientRect; 
     window.GetWindowRect(&wndRect); 
     window.GetClientRect(&clientRect); 
     return wndRect.Size() - clientRect.Size(); 
    } 
    else 
    { 
     // Determine the border size by asking windows to calculate the window rect 
     // required for a client rect with a width and height of 0. This method will 
     // work before the window is fully initialized and when the window is minimized. 
     CRect rect; 
     AdjustWindowRectEx(&rect, window.GetStyle(), FALSE, window.GetExStyle()); 
     return rect.Size(); 
    } 
} 
संबंधित मुद्दे