是不是在模式对话框的调用中出现的问题,并不是很简单呀
在主主界面上有一个按钮,点击之后会弹出一个对话框,
我在这个弹出的对话框中简单的处理一下,想让其只显示一朵玫瑰,但是就是实现不了,代码绝对
没有问题,因为在主界面当中按照这段代码,就可以实现但是在这个弹出的对话框中
就是是实现不了,实在是没有办法了,帮我看看吧
我觉得是在调用模式对话框的时候,MFC在处理方面有点问题,但是还找不出来
问题在什么地方。
BOOL zzy::OnInitDialog()
{
CDialog::OnInitDialog();
m_bmBitmap = new CBitmap;
m_bmBitmap->LoadBitmap(IDB_BITMAP1);
// TODO: Add extra initialization here
CRect rcWnd;
GetWindowRect (rcWnd);
CRgn rgn;
rgn.CreateRectRgn (rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom);
CRect rcClient;
GetClientRect (rcClient);
ClientToScreen (rcClient);
CRgn rgnClient;
rgnClient.CreateRectRgn (rcClient.left, rcClient.top, rcClient.right,
rcClient.bottom);
// Subtract rgnClient from rgn
rgn.CombineRgn (&rgn, &rgnClient, RGN_XOR);
// Get a DC for the bitmap
CDC dcImage;
dcImage.CreateCompatibleDC (NULL);
CBitmap *pOldBitmap = dcImage.SelectObject (m_bmBitmap);
// Get the bitmap for width and height information
BITMAP bm;
m_bmBitmap->GetBitmap (&bm);
// Get window width and height
CRect rc;
GetClientRect (rc);
// Use the minimum width and height
int width = min (bm.bmWidth, rc.Width());
int height = min (bm.bmHeight, rc.Height());
// Use RLE (run-length) style because it goes faster.
// Row start is where the first opaque pixel is found. Once
// a transparent pixel is found, a line region is created.
// Then row_start becomes the next opaque pixel.
int row_start;
// Go through all rows
for (int y=0; y<height; y++)
{
// Start looking at the beginning
row_start = 0;
// Go through all columns
for (int x=0; x<width; x++)
{
// If this pixel is transparent
if (dcImage.GetPixel(x, y)==RGB(0,0,0))
{
// If we haven't found an opaque pixel yet, keep searching
if (row_start == x) row_start ++;
else
{
// We have found the start (row_start) and end (x) of
// an opaque line. Add it to the region.
CRgn rgnAdd;
rgnAdd.CreateRectRgn (rcClient.left+row_start,
rcClient.top+y, rcClient.left+x, rcClient.top+y+1);
rgn.CombineRgn (&rgn, &rgnAdd, RGN_OR);
row_start = x+1;
}
}
}
// If the last pixel is still opaque, make a region.
if (row_start != x)
{
CRgn rgnAdd;
rgnAdd.CreateRectRgn (rcClient.left+row_start, rcClient.top+y,
rcClient.left+x, rcClient.top+y+1);
rgn.CombineRgn (&rgn, &rgnAdd, RGN_OR);
}
}
SetWindowRgn (rgn, TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void zzy::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rc;
GetClientRect (rc);
// Get a DC for the bitmap
CDC dcImage;
dcImage.CreateCompatibleDC (&dc);
CBitmap *pOldBitmap = dcImage.SelectObject (m_bmBitmap);
// Get bitmap width and height
BITMAP bm;
m_bmBitmap->GetBitmap (&bm);
// Use the minimum width and height
int width = min (bm.bmWidth, rc.Width());
int height = min (bm.bmHeight, rc.Height());
// Draw the bitmap as the window background
dc.BitBlt (0, 0, rc.Width(), rc.Height(), &dcImage, 0, 0, SRCCOPY);
// TODO: Add your message handler code here