响应SetFocus消息:添加下面代码//CBitmap bmp;非局部变量 bmp.DeleteObject(); CDC mdc; CDC * dc = CDC::FromHandle(::GetWindowDC(::GetDesktopWindow())); mdc.CreateCompatibleDC(dc); bmp.CreateCompatibleBitmap(dc,2,30); CDC * edit_dc = mEdit1.GetWindowDC(); COLORREF clr = edit_dc->GetPixel(CPoint(2,2));//获取背景色 { BYTE r = clr&0xff; BYTE g = (clr>>8)&0xff; BYTE b = (clr>>16)&0xff; clr = RGB(255-r,255-g,255-b);//颜色反转 } HBITMAP holdbmp = (HBITMAP)mdc.SelectObject(bmp); mdc.FillSolidRect(0,0,3,30,clr); HBITMAP hBmpNew = (HBITMAP)mdc.SelectObject(holdbmp); mEdit1.CreateCaret(CBitmap::FromHandle(hBmpNew)); mEdit1.ShowCaret(); mdc.DeleteDC();
时间: 2024-11-07 06:38:57