1.static透明
添加WM_CTLCOLOR消息的处理函数,然后添加如下代码
if (nCtlColor == CTLCOLOR_STATIC)
{
for (int i = 0; i < sizeof(m_staticText);i++)
{
if (pWnd->GetDlgCtrlID() == m_staticText[i])//m_staticText是存放static ID的数组
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255, 255, 255));
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}
}
}
2.窗口背景透明
添加WM_PAINT消息处理函数,添加如下代码
CRect rect;
GetClientRect(&rect); //获取对话框长宽
CDC dcBmp; //定义并创建一个内存设备环境
dcBmp.CreateCompatibleDC(&dc); //创建兼容性DC
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP_BACK_GROUND); //载入资源中图片
BITMAP m_bitmap; //图片变量
bmpBackground.GetBitmap(&m_bitmap);
//将位图选入临时内存设备环境
CBitmap *pbmpOld = dcBmp.SelectObject(&bmpBackground);
//调用函数显示图片StretchBlt显示形状可变
dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &dcBmp, 0, 0, m_bitmap.bmWidth, m_bitmap.bmHeight, SRCCOPY);
3.为pushbutton添加bitmap,按下和弹起效果
①、将bitmap添加到res资源中
②、在OnInitDialog函数添加如下代码
m_btnExit.LoadBitmaps(IDB_BITMAP_BACKUP_UP, IDB_BITMAP_BACKUP_DOWN, IDB_BITMAP_BACKUP_UP, IDB_BITMAP_BACKUP_UP);
m_btnExit.SubclassDlgItem(IDC_BTN_SYSTEM_EXIT, this);//button ID
m_btnExit.SizeToContent();
4.窗口全屏自适应
- 在OnInitDialog函数添加如下代码
CRect rect;
GetClientRect(&rect);
old.x = rect.right - rect.left;
old.y = rect.bottom - rect.top;
WINDOWPLACEMENT m_struOldWndpl;
//get current system resolution
int g_iCurScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int g_iCurScreenHeight = GetSystemMetrics(SM_CYSCREEN);
//for full screen while backplay
GetWindowPlacement(&m_struOldWndpl);
CRect rectWholeDlg;//entire client(including title bar)
CRect rectClient;//client area(not including title bar)
CRect rectFullScreen;
GetWindowRect(&rectWholeDlg);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectClient);
ClientToScreen(&rectClient);
rectFullScreen.left = rectWholeDlg.left - rectClient.left;
rectFullScreen.top = rectWholeDlg.top - rectClient.top;
rectFullScreen.right = rectWholeDlg.right + g_iCurScreenWidth - rectClient.right;
rectFullScreen.bottom = rectWholeDlg.bottom + g_iCurScreenHeight - rectClient.bottom - 30;//避免覆盖windows底部状态栏
//enter into full screen;
WINDOWPLACEMENT struWndpl;
struWndpl.length = sizeof(WINDOWPLACEMENT);
struWndpl.flags = 0;
struWndpl.showCmd = SW_SHOWNORMAL;
struWndpl.rcNormalPosition = rectFullScreen;
SetWindowPlacement(&struWndpl);
- 添加WM_SIZE消息处理函数并添加如下代码
float fsp[2];
POINT Newp; //获取现在对话框的大小
CRect recta;
GetClientRect(&recta); //取客户区大小
Newp.x = recta.right - recta.left;
Newp.y = recta.bottom - recta.top;
fsp[0] = (float)Newp.x / old.x;
fsp[1] = (float)Newp.y / old.y;
CRect Rect;
int woc;
CPoint OldTLPoint, TLPoint; //左上角
CPoint OldBRPoint, BRPoint; //右下角
HWND hwndChild = ::GetWindow(m_hWnd, GW_CHILD); //列出所有控件
int comboDis = 0;
while (hwndChild)
{
woc = ::GetDlgCtrlID(hwndChild);//取得ID
comboDis = 0;
TCHAR szClass[64 + 1] = { 0 };
if (GetClassName(hwndChild, szClass, 64)
&& _tcsicmp(szClass, _T("COMBOBOX")) == 0) //判断是否是COMBOBOX控件
{
//::SendMessage(hwndChild, CB_SETITEMHEIGHT, 0, Rect.Height() + 200);
comboDis = 90;//修改combox的大小
}
else
{
}
GetDlgItem(woc)->GetWindowRect(Rect);
ScreenToClient(Rect);
OldTLPoint = Rect.TopLeft();
TLPoint.x = long(OldTLPoint.x*fsp[0]);
TLPoint.y = long(OldTLPoint.y*fsp[1]);
OldBRPoint = Rect.BottomRight();
BRPoint.x = long(OldBRPoint.x *fsp[0]);
BRPoint.y = long(OldBRPoint.y *fsp[1]+comboDis);
Rect.SetRect(TLPoint, BRPoint);
GetDlgItem(woc)->MoveWindow(Rect, TRUE);
hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT);
}
old = Newp;
5.重绘标题栏的想法
https://blog.csdn.net/shenya1314/article/details/71172519
还没有自己试过,先留着参考