void CPngButton::SetPngRegion(int index)
{ CDC * p = this->GetWindowDC();
Graphics g(p->m_hDC);
HRGN hrgn = rgn[index]->GetHRGN(&g);
CRgn * crgn = CRgn::FromHandle(hrgn);
SetRgn(index, crgn);
ReleaseDC(p);
DeleteObject(hrgn);
}
void CPngButton::SetRgn(int nIndex, CRgn *region)
{
m_rgn[nIndex] = ::CreateRectRgn(0, 0, 0, 0);
CombineRgn(m_rgn[nIndex], region->operator HRGN(), NULL, RGN_COPY);
m_trgn[nIndex] = ::CreateRectRgn(0, 0, 0, 0);
CombineRgn(m_trgn[nIndex], region->operator HRGN(), NULL, RGN_COPY);
}
其中rgn[]是已经读取资源的Regin *rgn[]。不懂为什么GetHRGN后获取了HRGN 后又得弄成CRgn,然后又->operator HRGN?????
使用时 不必 考虑 HRGN hrgn
这是个啥?
你能看到 空气吗?也就是说 你不必考虑 HRGN hrgn 了
我自定义一个对话框。在其父窗口创建。然后重载Onpaint里面
,但是每次拖拉父窗口。子对话框的图片不能立即刷新。把它最小化后还原出图片。在父窗口调用m_DlgTest.Invalidate(),强制刷新也可以出背景图片。我想问下为什么??????void CPngBTNDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
m_DlgTest.MoveWindow(140*iHeight/130,70*iHeight/130,60*iHeight/130,60*iHeight/130);// m_DlgTest.Invalidate(); CDialogEx::OnPaint();
}
}void CDlgTest::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
PaintBkImage(&dc,&rect,TRUE ,RGB(0,0,90),m_pImageBack);
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CDialog::OnPaint()
}void PaintBkImage(CDC *pDC, const CRect &rect, BOOL bStretch,COLORREF clrBack,Image* pImage)
{
if ((pImage == NULL)||(pDC == NULL))
{
return;
} CDC m_memDC;
CBitmap m_memBitmap,*m_pOldBitmap;
m_memDC.CreateCompatibleDC(pDC);
m_memBitmap.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height()); m_pOldBitmap = m_memDC.SelectObject(&m_memBitmap);
m_memDC.FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(100,100,100)); Graphics graph(m_memDC.m_hDC);
//graph.DrawImage(pImage,0,0,pImage->GetWidth(),pImage->GetHeight());
int nPngWidth, nPngHeight ;
nPngWidth = pImage->GetWidth();
nPngHeight = pImage->GetHeight(); int nleft = rect.left;
int ntop = rect.top;
int nright = nleft;
int nbottom = ntop;
if (bStretch)
{
nright = rect.Width();
nbottom = rect.Height();
Point points[] = {Point(nleft, ntop), Point(nright, ntop), Point(nleft, nbottom)};
graph.DrawImage(pImage, points, 3);
}
else
{
for(int i=0;i<rect.Width();i++)
{
nright += nPngWidth;
nbottom = rect.Height();
Point points[] = {Point(nleft, ntop), Point(nright, ntop), Point(nleft, nbottom)};
graph.DrawImage(pImage, points, 3);
nleft = nright;
i += nPngWidth-1;
} }
pDC ->BitBlt(0,0,rect.Width(),rect.Height(),&m_memDC,0,0,SRCCOPY);
pDC ->SelectObject(m_pOldBitmap);
m_memBitmap.DeleteObject();
m_memDC.DeleteDC();}
但是背景图片必须调用了Invalidate才会绘制出来。结果也是进的Onpaint里面。不懂其中原因。
写成这样试试
void CPngBTNDemoDlg::OnPaint()
{
CPaintDC dc(this);
m_DlgText.MoveWindow();
}
我把Onpaint注释掉就OK了。。
讲解下原因吧。。
CreateProcess怎么辨别一个单实例的程序。就是该程序是用CreateMutex标识了的。