我的是基于对话框的程序,双击标题栏后,全屏显示,但是中间会闪屏一下。我的代码是这样写的
在onsize里面。
UpdateWindow();
CRect rect;
GetClientRect(&rect);
InvalidateRect(rect,true);
SendMessage(WM_PAINT);
不知道怎么改写。大侠帮忙啊!

解决方案 »

  1.   

    搜索 “双缓存”
    http://blog.csdn.net/lizhigang34/archive/2008/05/28/2491594.aspx
      

  2.   

    把onsize里这些代码都去掉
    OnSize本身会引起窗口重绘的
      

  3.   

    UpdateWindow()The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent. InvalidateRect()
    The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function. The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window. If the bErase parameter is TRUE for any part of the update region, the background is erased in the entire region, not just in the specified part. SendMessage(WM_PAINT)
    刷新太多
      

  4.   

    前段时间我在将3D MAX场景重现程序的调试中,发现两个问题:
    1.MDI工程中子窗口开启的时候不是最大化  
    2.拖动主窗口,屏幕出现严重的抖动闪烁。
          针对子窗口开启没有最大化的问题,在网上很快就找到答案了,如下:
          在CChildFrame::PreCreateWindow(CREATESTRUCT&   cs)函数中,在if( !CMDIChildWnd::PreCreateWindow(cs) )  return FALSE;之前加入cs.style |= WS_VISIBLE|WS_MAXIMIZE;这行代码即可。
          而屏幕闪烁问题,在网上找解决方案找了很久,这种问题是属于常见问题,网上很多大侠都已经对这种问题产生的原因、解决的方法做了详细的分析,我试了不少方法,并且查了不少资料,最后定为在问题的原因是MFC反复重绘背景造成闪烁,有一个非常简单的解决方法,就是对WM_ERASEBKGND这个消息响应进行处理,为MyDrawView这个类添加消息响应函数OnEraseBkgnd(),在MSDN中看一下这个函数的介绍:An overridden OnEraseBkgnd should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If it returns 0, the window will remain ed as needing to be erased. (Typically, this means that the fErase member of the PAINTSTRUCT structure will be TRUE.) 看完这段我尝试着重写OnEraseBkgnd()函数,可是还是没有实现,接下来,我又找了一些资料,根据资料的提示,发现程序非常简单,如下所示:1BOOL CMyDrawView::OnEraseBkgnd(CDC* pDC)
    2{
    3    // TODO: Add your message handler code here and/or call default
    4    return TRUE;
    5    //return CView::OnEraseBkgnd(pDC);
    6}
          代码非常简单,只是自己对MFC的具体细节不熟悉。然后保存,编译运行,拖动窗口,不再有闪烁了,这个问题解决了。希望我的这些方法能给你些帮助.
      

  5.   

    我的程序里面有定时器,更新不上。来不及更新。如果不写这个的话。void CDbxipianADODlg::OnSize(UINT nType, int cx, int cy) 
    {
    CDialog::OnSize(nType, cx, cy); if (change_flag)//如果确定oninitdlg已经调用完毕.
    {
    ReSize(IDC_static1); //标题
    ReSize(IDC_static2);
    ReSize(IDC_comboxsel);//选择框
    ReSize(IDC_bthisrecor);//历史记录查询
    ReSize(IDC_bt1read);//读数据库 ReSize(IDC_STATIC333); //机号片种组合框
    ReSize(IDC_stajihao); //机号
    ReSize(IDC_stajihao1);//机号内容 ReSize(IDC_stacopy); //片种
    ReSize(IDC_stapianzhong1); //片种1
    ReSize(IDC_SHOCKWAVEFLASH1); //FLASH ReSize(IDC_STATIC666); //流量温度窗
    ReSize(IDC_staliul1);//流量内容
    ReSize(IDC_staliul);//流量
    ReSize(IDC_statemp);//温度
    ReSize(IDC_statemp1);//温度内容 ReSize(IDC_STATIC555);  //机器速度和时间
    ReSize(IDC_statime); //时间
    ReSize(IDC_statime1);//时间值
    ReSize(IDC_staspeed1);//机速度值
    ReSize(IDC_staticNUM);//机速
    ReSize(IDCANCEL);//取消按钮


    /* ReSize(IDC_btload);
    ReSize(IDC_btplay);
    ReSize(IDC_btstop);
    ReSize(IDOK);
    *///这四个控件没有显示
    //恢复放大倍数,并保存 (确保还原时候能够还原到原来的大小)
    m_Multiple_width = float(1)/ m_Multiple_width ; 
    m_Mutiple_heith = float(1)/m_Mutiple_heith ; 
    if (m_Multiple_width>1)
    {
    MAX_FLAG=true; //放大FLASH
    }
    if (m_Multiple_width<1)
    {
    MAX_FLAG=false;  //缩小FLASH
    }
    // ::SetWindowPos(::GetDlgItem(0,IDC_static1),0,0,0,cx,cy,SWP_NOMOVE);
    // this->Invalidate();
    } UpdateWindow(); CRect rect;
    GetClientRect(&rect);
    InvalidateRect(rect,true);
    SendMessage(WM_PAINT);
    // Invalidate(false);
    // Invalidate(true);
    // change_flag=false;
    if (m_Multiple_width>1)
    {
    MAX_FLAG=true; //放大FLASH
    }
    if (m_Multiple_width<1)
    {
    MAX_FLAG=false;  //缩小FLASH
    }
    // TODO: Add your message handler code here

    }
    void CDbxipianADODlg::ReSize(int nID)
    {
    if (nID!=IDC_SHOCKWAVEFLASH1)
    {
    CRect Rect; 
    GetDlgItem(nID)->GetWindowRect(Rect); 
    ScreenToClient(Rect); 
    //计算控件左上角点 
    CPoint OldTLPoint,TLPoint; 
    OldTLPoint = Rect.TopLeft(); 
    TLPoint.x = long(OldTLPoint.x *m_Multiple_width); 
    TLPoint.y = long(OldTLPoint.y * m_Mutiple_heith );
    //计算控件右下角点
    CPoint OldBRPoint,BRPoint; 
    OldBRPoint = Rect.BottomRight(); 
    BRPoint.x = long(OldBRPoint.x *m_Multiple_width); 
    BRPoint.y = long(OldBRPoint.y * m_Mutiple_heith ); 
    //移动控件到新矩形
    Rect.SetRect(TLPoint,BRPoint); 
    GetDlgItem(nID)->MoveWindow(Rect,TRUE); 
    // MessageBox(_T("最小化")); }不知道问什么???
      

  6.   

    楼主,建议你用双缓存来解决这类问题。
    void CSDlg::OnPaint() 
    {
    CPaintDC dc(this); 
     
    //add code
      CDC MemDC; //首先定义一个显示设备对象 
    CBitmap MemBitmap;//定义一个位图对象 
    //随后建立与屏幕显示兼容的内存显示设备 
    MemDC.CreateCompatibleDC(&dc); 
    //这时还不能绘图,因为没有地方画 ^_^ 
    //下面建立一个与屏幕显示兼容的位图,至于位图的大小嘛,可以用窗口的大小 
    CRect rect;
    GetWindowRect(&rect);
    int nWidth = rect.Width();
    int nHeight = rect.Height();
    MemBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight); 

    //将位图选入到内存显示设备中 
    //只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上 
    MemDC.SelectObject(&MemBitmap); 
    //先用背景色将位图清除干净,这里我用的是白色作为背景 
    //你也可以用自己应该用的颜色  Cards.SelectObject(&beijing);
    CRect rect2;
    GetClientRect(&rect2);
    BITMAP bmp;
    beijing.GetBitmap(&bmp);
    MemDC.StretchBlt(0,0,rect2.Width(),rect2.Height(),&Cards,
    0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
    MemBitmap.DeleteObject(); 
    MemDC.DeleteDC();
    }
    这是我以前项目里面的代码,你最好还是在网上搜一下,系统学一下,再写!
      

  7.   


    我不是这个意思
    我是说你用定时器控制
    还在OnSize里调整控件
    还在OnSize调用UpdateWindow
    为什么这么处理