نمایش نتایج 1 تا 2 از 2

نام تاپیک: خطا در اجرا

  1. #1

    Unhappy خطا در اجرا

    // DirectXDraw.cpp: implementation of the CDirectXDraw class.
    // DirectXDraw.cpp - Copyright (C) 2012 rezvan yaghobi from iran



    #include "stdafx.h"
    #include "DirectXDraw.h"


    #ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif

    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    CDirectXDraw::CDirectXDraw()
    {
    m_pDD = NULL;
    m_pddsFrontBuffer = NULL;
    m_pddsStoreBuffer = NULL;
    pcClipper = NULL;
    m_bInitial = FALSE;

    }

    CDirectXDraw::~CDirectXDraw()
    {
    Terminate();
    }

    // old DirectDraw Initialization stuff. Set a window mode DirectDraw Display.
    BOOL CDirectXDraw::Init(HWND hWnd)
    {
    HRESULT hRet;
    CRect rect;
    HRESULT hr;
    DDSURFACEDESC2 ddsd;


    this->hWnd = hWnd;
    GetClientRect(hWnd,rect);
    nFullClientWidth = rect.Width();
    nFullClientHeight= rect.Height();
    hRet = DirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL);
    if(hRet != DD_OK)
    {
    AfxMessageBox("Failed to create directdraw object.");
    return FALSE;
    }
    hRet = m_pDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
    if(hRet != DD_OK)
    {
    AfxMessageBox("Failed to set directdraw display behavior.");
    return FALSE;
    }
    ZeroMemory( &ddsd, sizeof( ddsd ) );
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

    if(FAILED(hr = m_pDD->CreateSurface(&ddsd, &m_pddsFrontBuffer, NULL)))
    {
    AfxMessageBox("Failed to create primary surface.");
    return FALSE;
    }

    // Create the backbuffer surface
    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
    ddsd.dwWidth = nFullClientWidth;
    ddsd.dwHeight = nFullClientHeight;

    if(FAILED(hr = m_pDD->CreateSurface(&ddsd, &m_pddsStoreBuffer, NULL)))
    {
    AfxMessageBox("Failed to create back buffer surface.");
    return FALSE;
    }

    if(FAILED(hr = m_pDD->CreateClipper(0, &pcClipper, NULL)))
    {
    AfxMessageBox("Failed to create clipper.");
    return FALSE;
    }

    if(FAILED(hr = pcClipper->SetHWnd(0, hWnd)))
    {
    pcClipper->Release();
    AfxMessageBox("Failed to create primary surface.");
    return FALSE;
    }

    if(FAILED(hr = m_pddsFrontBuffer->SetClipper(pcClipper)))
    {
    pcClipper->Release();
    AfxMessageBox("Failed to create primary surface.");
    return FALSE;
    }
    m_bInitial = TRUE;
    return TRUE;
    }

    // make sure all stuff are terminated. and set to NULL when application ends.
    void CDirectXDraw::Terminate()
    {
    if (m_pDD != NULL)
    {
    if (m_pddsFrontBuffer != NULL)
    {
    if (m_pddsStoreBuffer != NULL)
    {
    m_pddsStoreBuffer->Release();
    m_pddsStoreBuffer = NULL;
    }

    if (pcClipper != NULL)
    {
    pcClipper->Release();
    pcClipper = NULL;
    }

    m_pddsFrontBuffer->Release();
    m_pddsFrontBuffer = NULL;
    }
    m_pDD->Release();
    m_pDD = NULL;
    }
    m_bInitial = FALSE;
    }

    // clear both off csreen buffer and primary buffer.
    void CDirectXDraw::Clear()
    {
    HRESULT hRet;
    DDBLTFX fx;
    fx.dwSize = sizeof(fx);
    fx.dwFillColor = 0x000000;

    while (TRUE)
    {
    hRet = m_pddsFrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &fx);
    if (hRet == DD_OK)
    break;
    else if (hRet == DDERR_SURFACELOST)
    {
    m_pddsFrontBuffer->Restore();
    }
    else if (hRet != DDERR_WASSTILLDRAWING)
    break;
    }

    while (TRUE)
    {
    hRet = m_pddsStoreBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &fx);
    if (hRet == DD_OK)
    break;
    else if (hRet == DDERR_SURFACELOST)
    {
    m_pddsStoreBuffer->Restore();
    }
    else if (hRet != DDERR_WASSTILLDRAWING)
    break;
    }

    }

    void CDirectXDraw::CellDraw(char *m_cArray, COLORREF cellColor,CRect &rectView,BOOL bGrid)
    {
    if(!m_bInitial)
    return;

    HRESULT hRet;
    HDC dc;
    hRet = m_pddsStoreBuffer->GetDC(&dc);
    if (hRet != DD_OK)
    return;

    int nCellWidth = rectView.Width()/CONST_INT_GRIDNUMBER;
    int nCellHeight = rectView.Height()/CONST_INT_GRIDNUMBER;
    int x,y;

    CDC *pDC = CDC::FromHandle(dc);
    CRect rect;
    CPen pen(PS_SOLID,1,RGB(192,192,192));
    m_redBrush.DeleteObject();
    m_redBrush.CreateSolidBrush(cellColor);
    pDC->FillSolidRect(&rectView, RGB(255,255,255));
    pDC->SelectObject(m_redBrush);
    pDC->SelectObject(&pen);

    rect.SetRect(0,0,nCellWidth*CONST_INT_GRIDNUMBER,n CellHeight*CONST_INT_GRIDNUMBER);

    pDC->SetWindowOrg(-(rectView.Width()-rect.Width())/2,-(rectView.Height()-rect.Height())/2);

    if(bGrid)
    {
    for(int i = 0;i<= CONST_INT_GRIDNUMBER;i++)
    {
    pDC->MoveTo(nCellWidth*i,0);
    pDC->LineTo(nCellWidth*i,rect.Height());
    pDC->MoveTo(0,nCellHeight*i);
    pDC->LineTo(rect.Width(),nCellHeight*i);
    }
    }

    for(int i=0;i<CONST_INT_GRIDNUMBER;i++)
    {
    for(int j=0;j<CONST_INT_GRIDNUMBER;j++)
    {
    x = nCellWidth*i;
    y = nCellHeight*j;
    rect.top= y;
    rect.left = x;
    rect.bottom = y+nCellHeight;
    rect.right = x+nCellWidth;
    if(m_cArray[i*CONST_INT_GRIDNUMBER+j])
    pDC->Ellipse(&rect);
    }
    }
    m_pddsStoreBuffer->ReleaseDC(dc);
    }


    void CDirectXDraw::BarDraw(int *m_nNumberArray, COLORREF barColor,CRect &rectView)
    {
    if(!m_bInitial)
    return;
    HRESULT hRet;
    HDC dc;
    hRet = m_pddsStoreBuffer->GetDC(&dc);

    if (hRet != DD_OK)
    return;

    int nBarWidthWithInterval = (rectView.Height()/CONST_INT_BARNUMBER);
    int nBarWidth = (int)((rectView.Height()/CONST_INT_BARNUMBER)*0.8);
    int y,cx,cy;

    CDC *pDC = CDC::FromHandle(dc);
    pDC->FillSolidRect(&rectView, RGB(255,255,255));

    for(int i=0;i<CONST_INT_BARNUMBER;i++)
    {
    y = nBarWidthWithInterval*i;
    cx =(int)(rectView.Width()*((double)m_nNumberArray[i]/CONST_INT_BARNUMBER));
    cy = nBarWidth;
    pDC->FillSolidRect(0,y,cx,cy,barColor);
    }

    m_pddsStoreBuffer->ReleaseDC(dc);
    }

    // Load images from offscteen buffer to primary buffer and for display.
    void CDirectXDraw::Display()
    {
    if(!m_bInitial)
    return;

    HRESULT hRet;
    RECT rt;
    POINT p = {0, 0};

    ClientToScreen(hWnd, &p);
    rt.left = 0 + p.x; rt.top = 0 + p.y; rt.right = nFullClientWidth + p.x; rt.bottom = nFullClientHeight + p.y;
    while( TRUE )
    {
    hRet = m_pddsFrontBuffer->Blt(&rt, m_pddsStoreBuffer, NULL, DDBLT_WAIT, NULL);
    if (hRet == DD_OK)
    break;
    else if(hRet == DDERR_SURFACELOST)
    {
    m_pddsFrontBuffer->Restore();
    m_pddsStoreBuffer->Restore();
    }
    else if(hRet != DDERR_WASSTILLDRAWING)
    return;
    }
    }



    این خطا مربوط به چیست؟ کلاسها رو چه طور باید تعریف کرد که خطا نده.من کد رو از نت کپی کردم وکردمش پروژه. حالا این خطا که در زیر اومده مربوط به چیه؟
    error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types



  2. #2
    کاربر دائمی آواتار ASGGSA
    تاریخ عضویت
    دی 1390
    محل زندگی
    همین نزدیکی ها
    پست
    128

    نقل قول: خطا در اجرا

    تابع های AfxMessageBox را بصورت زیر تغییر بدهید.

    AfxMessageBox(CString("پیغام مورد نظر"));

    به علت اینکه کلاس CString به عنوان آرگومان تابع AfxMessageBox تعریف شده است.
    آخرین ویرایش به وسیله ASGGSA : یک شنبه 27 فروردین 1391 در 00:36 صبح

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •