1、CDC画半透明(用于菜单项选中时候的选择色)
int nAlpha = 100;
// 透明度,在0~254之间取值,越大越不透明
BLENDFUNCTION stBlend = {AC_SRC_OVER, 0, nAlpha, 0};
CDC dcAlphaRect;
CBitmap bmpAlphaRect;
dcAlphaRect.CreateCompatibleDC(pDC);
bmpAlphaRect.CreateCompatibleBitmap(pDC,selRect.Width(),selRect.Height());
CBitmap* pOld_Bitmap = dcAlphaRect.SelectObject(&bmpAlphaRect);
dcAlphaRect.FillSolidRect( 0, 0, selRect.Width(), selRect.Height(), COLOR_SEL );
AlphaBlend(pDC->m_hDC,
selRect.left, selRect.top,
selRect.Width(), selRect.Height(),
dcAlphaRect.m_hDC,
0,0,
selRect.Width(), selRect.Height(),
stBlend);
dcAlphaRect.SelectObject(pOld_Bitmap);
dcAlphaRect.DeleteDC();
bmpAlphaRect.DeleteObject();
ModifyStyleEx(0, WS_EX_LAYERED);
SetLayeredWindowAttributes(0,100,LWA_ALPHA);
ModifyStyleEx(0, WS_EX_LAYERED);
COLORREF crKey = RGB(160, 160, 160);
SetLayeredWindowAttributes(crKey,100,LWA_COLORKEY | LWA_ALPHA);
DWORD menuStyle = (DWORD)GetWindowLongPtrW(pWPS->hwnd, GWL_EXSTYLE);
SetWindowLongPtrW(pWPS->hwnd, GWL_EXSTYLE, menuStyle | WS_EX_LAYERED);
SetLayeredWindowAttributes(pWPS->hwnd, 0, 100, LWA_ALPHA);
pDC->Rectangle(selRect);
int r1,g1,b1;
//读取渐变起点的颜色值
r1 = GetRValue(COLOR_BK_FROM);
g1 = GetGValue(COLOR_BK_FROM);
b1 = GetBValue(COLOR_BK_FROM);
int r2,g2,b2;
//读取渐变终点的颜色值
r2 = GetRValue(COLOR_BK_TO);
g2 = GetGValue(COLOR_BK_TO);
b2 = GetBValue(COLOR_BK_TO);
float r3,g3,b3;//菜单区域水平方向每个点RGB值应该变化的度(范围)
r3 = ((float)(r2-r1)); // / (float)(itemRect.Width());
g3 = (float)(g2-g1); // /(float)(itemRect.Width());
b3 = (float)(b2-b1); // /(float)(itemRect.Width());
float average = r3>g3 ? (r3>b3 ? r3 : b3) : (g3>b3 ? g3 : b3);
average = average>(float)selRect.Width() ? (float)selRect.Width() : average;
r3 /= average;
g3 /= average;
b3 /= average;
COLORREF r,g,b;//菜单区域水平方向每个点的颜色值
CPen* m_oldpen = NULL;
for (int i = selRect.left;iSelectObject(&m_pen);
pDC->MoveTo(i,selRect.top);
pDC->LineTo(i,selRect.bottom);
}
pDC->SelectObject(m_oldpen);
在一开始想创建好字体供整体使用,但是实在找不到哪里可以获取LOGFONT结构体,所以自己创建。但是字体除了字体字号粗斜体以外,还有一些会被忽略的参数,此时可以在定义了LOGFONT了参数以后,调用CFontDialog,传入LOGFONT,查看返回的LOGFONT各参数哪些和定义的不一样,来确保LOGFONT,设置完成。
END