基于dialog,用create的方式创建的窗口,画花了。

ruoge2007 2010-06-07 10:13:59
基于dialog,用create的方式创建两个窗口,这两个窗口都不停的画。在界面上有重叠,窗口A,窗口B的内容交错显示。这是什么原因呢。我知道有层的概念,两个窗口在创建的顺序不同,应该就在不同的层中。这样下面的层应该不显示啊。。。求解了。。。。
...全文
134 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2010-06-15
  • 打赏
  • 举报
回复
您好
我是本版版主
此帖已多日无人关注
请您及时结帖
如您认为问题没有解决可按无满意结帖处理
另外本版设置了疑难问题汇总帖
并已在版面置顶
相关规定其帖子中有说明
您可以根据规定提交您帖子的链接
如您目前不想结帖只需回帖说明
我们会删除此结帖通知

见此回复三日内无回应
我们将强制结帖
相关规定详见界面界面版关于版主结帖工作的具体办法
muzizongheng 2010-06-07
  • 打赏
  • 举报
回复
dlg里不能创建子dlg,尤其是2个子dlg, 因为dlg是捕获消息泵, 系统不清楚消息发往哪个dlg。
只能为popup, 不然就会出现焦点和重画的问题。

ruoge2007 2010-06-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 muzizongheng 的回复:]

窗口的风格为child的缘故,
[/Quote]
窗口为什么风格才可以呢?的确是用的child窗口。
ruoge2007 2010-06-07
  • 打赏
  • 举报
回复
代码如下,记得是从codeproject上下的。
调用处:

//下面这段代码,调用两次,生成两个包含m_pictureExStatus的类实例。是基于dialog的。
CRect rcPic;
RECT _rect;
m_staticStatus.GetWindowRect( &rcPic);
ScreenToClient( &rcPic);
_rect.left = rcPic.left;
_rect.right = rcPic.right;
_rect.top = rcPic.top;
_rect.bottom = rcPic.bottom;
//m_shockWaveFlash.Create( NULL, WS_CHILD|WS_VISIBLE, m_rect, this, 0xFF);
m_pictureExStatus.Create( _T(""), WS_CHILD|WS_VISIBLE, _rect, this);
///
m_staticType.GetWindowRect( &rcPic);
ScreenToClient( &rcPic);
_rect.left = rcPic.left;
_rect.right = rcPic.right;
_rect.top = rcPic.top;
_rect.bottom = rcPic.bottom;
m_pictureExType.Create( _T(""), WS_CHILD|WS_VISIBLE, _rect, this);

CString strModulePath, strGifFile;
strModulePath = CDirectory2::GetModulePath();
strGifFile = strModulePath + LSF_ZONE_NORMAL;
m_pictureExStatus.Load( strGifFile);
m_pictureExStatus.Draw();

.cpp

//////////////////////////////////////////////////////////////////////
// PictureEx.cpp: implementation of the CPictureEx class.
//
// Picture displaying control with support for the following formats:
// GIF (including animated GIF87a and GIF89a), JPEG, BMP, WMF, ICO, CUR
//
// Written by Oleg Bykov (oleg_bykoff@rsdn.ru)
// Copyright (c) 2001
//
// To use CPictureEx, follow these steps:
//////////////////////////////////////////////////////////////////////
BOOL CPictureEx::Draw()
{
if (!m_bIsInitialized)
{
TRACE(_T("Call one of the CPictureEx::Load() member functions before calling Draw()\n"));
return FALSE;
};

if (IsAnimatedGIF())
{
// the picture needs animation
// we'll start the thread that will handle it for us

unsigned int nDummy;
m_hThread = (HANDLE) _beginthreadex(NULL,0,_ThreadAnimation,this,
CREATE_SUSPENDED,&nDummy);
if (!m_hThread)
{
TRACE(_T("Draw: Couldn't start a GIF animation thread\n"));
return FALSE;
}
else
ResumeThread(m_hThread);
}
else
{
if (m_pPicture)
{
long hmWidth;
long hmHeight;
m_pPicture->get_Width(&hmWidth);
m_pPicture->get_Height(&hmHeight);
if (m_pPicture->Render(m_hMemDC, 0, 0, m_PictureSize.cx, m_PictureSize.cy,
0, hmHeight, hmWidth, -hmHeight, NULL) == S_OK)
{
Invalidate(FALSE);
return TRUE;
};
};
};

return FALSE;
}



BOOL CPictureEx::Load(LPCTSTR szResourceName, LPCTSTR szResourceType)
{
ASSERT(szResourceName);
ASSERT(szResourceType);

HRSRC hPicture = FindResource(AfxGetResourceHandle(),szResourceName,szResourceType);
HGLOBAL hResData;
if (!hPicture || !(hResData = LoadResource(AfxGetResourceHandle(),hPicture)))
{
TRACE(_T("Load (resource): Error loading resource %s\n"),szResourceName);
return FALSE;
};
DWORD dwSize = SizeofResource(AfxGetResourceHandle(),hPicture);

// hResData is not the real HGLOBAL (we can't lock it)
// let's make it real

HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD,dwSize);
if (!hGlobal)
{
TRACE(_T("Load (resource): Error allocating memory\n"));
FreeResource(hResData);
return FALSE;
};

char *pDest = reinterpret_cast<char *> (GlobalLock(hGlobal));
char *pSrc = reinterpret_cast<char *> (LockResource(hResData));
if (!pSrc || !pDest)
{
TRACE(_T("Load (resource): Error locking memory\n"));
GlobalFree(hGlobal);
FreeResource(hResData);
return FALSE;
};
CopyMemory(pDest,pSrc,dwSize);
FreeResource(hResData);
GlobalUnlock(hGlobal);

BOOL bRetValue = Load(hGlobal,dwSize);
GlobalFree(hGlobal);
return bRetValue;
}
UINT WINAPI CPictureEx::_ThreadAnimation(LPVOID pParam)
{

ASSERT(pParam);
CPictureEx *pPic = reinterpret_cast<CPictureEx *> (pParam);

pPic->m_bIsPlaying = TRUE;
pPic->ThreadAnimation();
pPic->m_bIsPlaying = FALSE;

// this thread has finished its work so we close the handle
CloseHandle(pPic->m_hThread);
// and init the handle to zero (so that Stop() doesn't Wait on it)
pPic->m_hThread = 0;
return 0;
}

void CPictureEx::ThreadAnimation()
{
// first, restore background (for stop/draw support)
// disposal method #2
if (m_arrFrames[m_nCurrFrame].m_nDisposal == 2)
{
HBRUSH hBrush = CreateSolidBrush(m_clrBackground);
if (hBrush)
{
RECT rect = {
m_arrFrames[m_nCurrFrame].m_frameOffset.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy,
m_arrFrames[m_nCurrFrame].m_frameOffset.cx + m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy + m_arrFrames[m_nCurrFrame].m_frameSize.cy };
FillRect(m_hMemDC,&rect,hBrush);
DeleteObject(hBrush);
};
}
else
// disposal method #3
if (m_hDispMemDC && (m_arrFrames[m_nCurrFrame].m_nDisposal == 3) )
{
// put it back
BitBlt(m_hMemDC,
m_arrFrames[m_nCurrFrame].m_frameOffset.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy,
m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameSize.cy,
m_hDispMemDC,0,0, SRCCOPY);
// init variables
SelectObject(m_hDispMemDC,m_hDispOldBM);
DeleteDC(m_hDispMemDC); m_hDispMemDC = NULL;
DeleteObject(m_hDispMemBM); m_hDispMemBM = NULL;
};

while (!m_bExitThread)
{
if (m_arrFrames[m_nCurrFrame].m_pPicture)
{
///////////////////////////////////////////////////////
// Before rendering a frame we should take care of what's
// behind that frame. TFrame::m_nDisposal will be our guide:
// 0 - no disposal specified (do nothing)
// 1 - do not dispose (again, do nothing)
// 2 - restore to background color (m_clrBackground)
// 3 - restore to previous

//////// disposal method #3
if (m_arrFrames[m_nCurrFrame].m_nDisposal == 3)
{
// prepare a memory DC and store the background in it
m_hDispMemDC = CreateCompatibleDC(m_hMemDC);
m_hDispMemBM = CreateCompatibleBitmap(m_hMemDC,
m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameSize.cy);

if (m_hDispMemDC && m_hDispMemBM)
{
m_hDispOldBM = reinterpret_cast<HBITMAP> (SelectObject(m_hDispMemDC,m_hDispMemBM));
BitBlt(m_hDispMemDC,0,0,
m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameSize.cy,
m_hMemDC,
m_arrFrames[m_nCurrFrame].m_frameOffset.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy,
SRCCOPY);
};
};
///////////////////////

long hmWidth;
long hmHeight;
m_arrFrames[m_nCurrFrame].m_pPicture->get_Width(&hmWidth);
m_arrFrames[m_nCurrFrame].m_pPicture->get_Height(&hmHeight);

if (m_arrFrames[m_nCurrFrame].m_pPicture->Render(m_hMemDC,
m_arrFrames[m_nCurrFrame].m_frameOffset.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy,
m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameSize.cy,
0, hmHeight, hmWidth, -hmHeight, NULL) == S_OK)
{
Invalidate(FALSE);
};

if (m_bExitThread) break;

// if the delay time is too short (like in old GIFs), wait for 100ms
if (m_arrFrames[m_nCurrFrame].m_nDelay < 5)
WaitForSingleObject(m_hExitEvent, 100);
else
WaitForSingleObject(m_hExitEvent, 10*m_arrFrames[m_nCurrFrame].m_nDelay);

if (m_bExitThread) break;

// disposal method #2
if (m_arrFrames[m_nCurrFrame].m_nDisposal == 2)
{
HBRUSH hBrush = CreateSolidBrush(m_clrBackground);
if (hBrush)
{
RECT rect = {
m_arrFrames[m_nCurrFrame].m_frameOffset.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy,
m_arrFrames[m_nCurrFrame].m_frameOffset.cx + m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy + m_arrFrames[m_nCurrFrame].m_frameSize.cy };
FillRect(m_hMemDC,&rect,hBrush);
DeleteObject(hBrush);
};
}
else
if (m_hDispMemDC && (m_arrFrames[m_nCurrFrame].m_nDisposal == 3) )
{
// put it back
BitBlt(m_hMemDC,
m_arrFrames[m_nCurrFrame].m_frameOffset.cx,
m_arrFrames[m_nCurrFrame].m_frameOffset.cy,
m_arrFrames[m_nCurrFrame].m_frameSize.cx,
m_arrFrames[m_nCurrFrame].m_frameSize.cy,
m_hDispMemDC,0,0, SRCCOPY);
// init variables
SelectObject(m_hDispMemDC,m_hDispOldBM);
DeleteDC(m_hDispMemDC); m_hDispMemDC = NULL;
DeleteObject(m_hDispMemBM); m_hDispMemBM = NULL;
};
};
m_nCurrFrame++;
if (m_nCurrFrame == m_arrFrames.size())
{
m_nCurrFrame
= 0;
// init the screen for the first frame,
HBRUSH hBrush = CreateSolidBrush(m_clrBackground);
if (hBrush)
{
RECT rect = {0,0,m_PictureSize.cx,m_PictureSize.cy};
FillRect(m_hMemDC,&rect,hBrush);
DeleteObject(hBrush);
};
};
};
}
BOOL CPictureEx::PrepareDC(int nWidth, int nHeight)
{
SetWindowPos(NULL,0,0,nWidth,nHeight,SWP_NOMOVE | SWP_NOZORDER);

HDC hWinDC = ::GetDC(m_hWnd);
if (!hWinDC) return FALSE;

m_hMemDC = CreateCompatibleDC(hWinDC);
if (!m_hMemDC)
{
::ReleaseDC(m_hWnd,hWinDC);
return FALSE;
};

m_hBitmap = CreateCompatibleBitmap(hWinDC,nWidth,nHeight);
if (!m_hBitmap)
{
::ReleaseDC(m_hWnd,hWinDC);
::DeleteDC(m_hMemDC);
return FALSE;
};

m_hOldBitmap = reinterpret_cast<HBITMAP>
(SelectObject(m_hMemDC,m_hBitmap));

// fill the background
m_clrBackground = GetSysColor(COLOR_3DFACE);
RECT rect = {0,0,nWidth,nHeight};
FillRect(m_hMemDC,&rect,(HBRUSH)(COLOR_WINDOW));

::ReleaseDC(m_hWnd,hWinDC);
m_bIsInitialized = TRUE;
return TRUE;
}






muzizongheng 2010-06-07
  • 打赏
  • 举报
回复
窗口的风格为child的缘故,
liudafei1 2010-06-07
  • 打赏
  • 举报
回复
你画的时候是不是用的getDC画的,如果是的话要记得releaseDC因为DC是一种互斥资源。另外交错显示的原因应该是你在不停地交替激活两个窗口
xidong_bao 2010-06-07
  • 打赏
  • 举报
回复
逻辑有问题吗
是在不停建吧
Eleven 2010-06-07
  • 打赏
  • 举报
回复
贴代码看看。。。
社会栋梁 2010-06-07
  • 打赏
  • 举报
回复
怎么不停的画的?有代码吗

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧