2009-01-26 146 views

回答

6

我發現得到在Vista中按鈕的位置所需要的功能:

http://msdn.microsoft.com/en-us/library/aa969436.aspx(WM_GETTITLEBARINFOEX)

這個鏈接也顯示了讓所有的間距正確(恥辱它所需的系統指標儘管沒有完整的對話框圖片)。這在Vista中完美運行,並且大多數在XP中(在XP中,按鈕之間的間隔稍微有些過大)。

http://shellrevealed.com/photos/blog_images/images/4538/original.aspx

如果該鏈接被打破,你可以嘗試互聯網檔案館(感謝Dan Groom!):
http://web.archive.org/web/20070301202835/http://shellrevealed.com/photos/blog_images/images/4538/original.aspx

3

GetSystemMetrics給出了所有這些信息。要在窗飾內繪製,請使用GetWindowDC

+0

這個職位呢? – 2009-01-26 10:36:16

+0

如果你正在繪製自己的控件,你不應該根據自己的需要自己選擇這些值嗎? – fbonnet 2009-01-26 11:04:13

+0

嗯,我正在繪製自己的背景等,在XP上我們繪製了我們自己的min/restore/close按鈕 - 但是在Vista上我們想要在正確的位置繪製正確的vista按鈕。 – 2009-01-26 11:25:37

0

GetSystemMetrics函數應該幫助你一個大小(SM_CYSIZE和SM_CXSIZE參數)。

編輯

我不知道,你可以找到使用此功能的位置,但你可能看看emule source code,他們已經成功地將按鈕添加到窗口標題。

1

下面的代碼是從「全球標題欄掛鉤」例如,我發現在適應http://www.catch22.net/content/snippets。我修改了這個例子,使它對MFC友好。它返回最左邊標題欄按鈕的X座標,但可以輕鬆修改它以查找任何按鈕的位置。

#define B_EDGE 2 

int CMyWindow::CalcRightEdge() 
{ 
if(GetStyle() & WS_THICKFRAME) 
    return GetSystemMetrics(SM_CXSIZEFRAME); 
else 
    return GetSystemMetrics(SM_CXFIXEDFRAME); 
} 


int CMyWindow::findNewButtonPosition() 
{ 
int nButSize = 0; 
DWORD dwStyle = GetStyle(); 
DWORD dwExStyle = GetExStyle(); 

if(dwExStyle & WS_EX_TOOLWINDOW) 
{ 
    int nSysButSize = GetSystemMetrics(SM_CXSMSIZE) - B_EDGE; 

    if(GetStyle() & WS_SYSMENU) 
    nButSize += nSysButSize + B_EDGE; 

    return nButSize + CalcRightEdge(); 
} 
else 
{ 
    int nSysButSize = GetSystemMetrics(SM_CXSIZE) - B_EDGE; 

// Window has Close [X] button. This button has a 2-pixel 
// border on either size 
    if(dwStyle & WS_SYSMENU) 
    nButSize += nSysButSize + B_EDGE; 

// If either of the minimize or maximize buttons are shown, 
// Then both will appear (but may be disabled) 
// This button pair has a 2 pixel border on the left 
    if(dwStyle & (WS_MINIMIZEBOX | WS_MAXIMIZEBOX)) 
    nButSize += B_EDGE + nSysButSize * 2; 

// A window can have a question-mark button, but only 
// if it doesn't have any min/max buttons 
    else if(dwExStyle & WS_EX_CONTEXTHELP) 
    nButSize += B_EDGE + nSysButSize; 

// Now calculate the size of the border...aggghh! 
    return nButSize + CalcRightEdge(); 
} 
} 
相關問題