想进行下列操作:
  鼠标在对话框上点击一下,即在鼠标确定的某一矩形框内显示图片,由于图片数量不定,想不用控件来显示图片,可以吗?使用以下代码,图片显示不了!文字可显示!
void CDevice::Draw(CPaintDC *pDC)
{
CComponent::Draw(pDC);
//CString name=this->GetName();
CRect m_Rect;
m_Rect=GetRectTracker();
int width=m_Rect.Width();
int height=m_Rect.Height();
                 CDC   dcMem;     
                  dcMem.CreateCompatibleDC(pDC);     
                  CBitmap   bmpBackground;   
                  bmpBackground.LoadBitmap(IDB_BITMAP1);  
                  BITMAP   bitMap;   
                  bmpBackground.GetBitmap(&bitMap);   
                  CBitmap   *pbmpOld=dcMem.SelectObject(&bmpBackground);   
                 pDC->StretchBlt(0,0,m_Rect.Width(),m_Rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);     pDC->TextOut((int)(m_Rect.left+width*0.1),(int)(m_Rect.top+height*0.45),"New_Object");}

解决方案 »

  1.   

    可以  可以参考下这个
    void CTFDSFRDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting

    SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

    // Center icon in client rectangle
    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;

    // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    //绘制故障图片
    CPaintDC dc(this);

    //获取图像路径及故障范围
    // EnterCriticalSection(&g_cFaultImgSection);
    CString ImgPath = g_FaultImg.ImgPath;
    CRect rect = g_FaultImg.FPos;
    // LeaveCriticalSection(&g_cFaultImgSection);

    //空路径返回
    if (ImgPath.IsEmpty())
    {
    CDialog::OnPaint();
    return;
    }

    int dwidth,dheight;

    //图像获取失败处理
    if (GetJpgDimension(ImgPath,&dwidth,&dheight)==FALSE)
    {
    CDialog::OnPaint();
    return;
    }

    // int num = ImgPath.ReverseFind("_");

    //设定故障图像在Dialog中的显示位置
    CRect imgrect(580,300,972,591);

    int StartX = 580;
    int StartY = 300;

    BYTE* pvData = NULL;


    try
    {
    //获取图像信息
    CFileStatus fstatus;     
    CFile file;
    LONG cb;
    file.Open(ImgPath,CFile::modeRead);
    file.GetStatus(ImgPath,fstatus);
    cb = fstatus.m_size;

    pvData = new BYTE[cb];
    file.ReadHuge(pvData,cb);
    file.Close();

    //显示图像
    HDC hDC = dc.GetSafeHdc();
    LoadImage(hDC,imgrect,ImgPath,0,pvData);

    //画出故障位置
    CPen pen(PS_SOLID,1,RGB(255,0,0));
    CPen* pOldPen = dc.SelectObject(&pen);

    LOGBRUSH logBrush;
    logBrush.lbStyle = BS_HOLLOW;
    logBrush.lbColor = RGB(255, 0, 0);
    logBrush.lbHatch = HS_CROSS;
    CBrush brush;
    brush.CreateBrushIndirect(&logBrush);
    CBrush *pOldBrush = (CBrush *)dc.SelectObject(&brush);

    rect.left = StartX+rect.left/2;
    rect.right = StartX+rect.right/2;
    rect.top = StartY+rect.top/2;
    rect.bottom = StartY+rect.bottom/2;

    rect.InflateRect(10,10);
    rect.left = max(580,rect.left);
    rect.top = max(300,rect.top);
    rect.right = min(971,rect.right);
    rect.bottom = min(590,rect.bottom);

    //////////////////////////////////////////////////
    dc.Rectangle(rect);
    }
    catch (CFileException *e) 
    {
    e->Delete();
    }



    if (pvData!=NULL)
    delete []pvData;

    CDialog::OnPaint();
    }
    }
      

  2.   

    ...
    CBitmap  bmpBackground; 
    bmpBackground.CreateCompatibleBitmap( CDC* pDC, int nWidth, int nHeight );先要创建好设备相关位图吧,否则你在哪贴位图呢??
    bmpBackground.LoadBitmap(IDB_BITMAP1);  
    ...
      

  3.   

    创建Picture控件是在另一个自定义的类中完成的,而且也不想这么复杂。找到参考程序:
    CStatic *m_picture =   new   CStatic();   
    m_picture->Create(_T(""),WS_EX_TRANSPARENT|WS_CHILD|WS_VISIBLE|WS_TABSTOP,
      CRect(m_Rect.left,m_Rect.top,width,height),NULL,1);
    CBitmap   bmp;   
    bmp.LoadBitmap(IDB_BITMAP2);   
    m_picture->SetBitmap(bmp);因为不是在显示图片的对话框类中创建,Create中第4个参数不能使用this,但如果使用NULL,程序会中断,
    这个参数该如何设置了?