7 个解决方案
#1
仔细检查代码, 没有代码没法帮你
#2
CNikeDlg::CNikeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNikeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNikeDlg)
m_55 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_pdcBoard=new CDC;//储存棋盘图案的 DC
m_pdcBack=new CDC;//缓冲 DC
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
a[0]=AfxGetApp()->LoadIcon(IDI_ICON1);//将棋子图片放入数组.
a[1]=AfxGetApp()->LoadIcon(IDI_ICON2);
a[2]=AfxGetApp()->LoadIcon(IDI_ICON3);
a[3]=AfxGetApp()->LoadIcon(IDI_ICON4);
a[4]=AfxGetApp()->LoadIcon(IDI_ICON5);
a[5]=AfxGetApp()->LoadIcon(IDI_ICON6);
a[6]=AfxGetApp()->LoadIcon(IDI_ICON7);
a[7]=AfxGetApp()->LoadIcon(IDI_ICON8);
a[8]=AfxGetApp()->LoadIcon(IDI_ICON9);
a[9]=AfxGetApp()->LoadIcon(IDI_ICON10);
a[10]=AfxGetApp()->LoadIcon(IDI_ICON11);
a[11]=AfxGetApp()->LoadIcon(IDI_ICON12);
a[12]=AfxGetApp()->LoadIcon(IDI_ICON13);
ChuShiHuanZhoBiao();//因为我设计的是军棋,这个函数是用来初始化棋盘的
}
: CDialog(CNikeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNikeDlg)
m_55 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_pdcBoard=new CDC;//储存棋盘图案的 DC
m_pdcBack=new CDC;//缓冲 DC
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
a[0]=AfxGetApp()->LoadIcon(IDI_ICON1);//将棋子图片放入数组.
a[1]=AfxGetApp()->LoadIcon(IDI_ICON2);
a[2]=AfxGetApp()->LoadIcon(IDI_ICON3);
a[3]=AfxGetApp()->LoadIcon(IDI_ICON4);
a[4]=AfxGetApp()->LoadIcon(IDI_ICON5);
a[5]=AfxGetApp()->LoadIcon(IDI_ICON6);
a[6]=AfxGetApp()->LoadIcon(IDI_ICON7);
a[7]=AfxGetApp()->LoadIcon(IDI_ICON8);
a[8]=AfxGetApp()->LoadIcon(IDI_ICON9);
a[9]=AfxGetApp()->LoadIcon(IDI_ICON10);
a[10]=AfxGetApp()->LoadIcon(IDI_ICON11);
a[11]=AfxGetApp()->LoadIcon(IDI_ICON12);
a[12]=AfxGetApp()->LoadIcon(IDI_ICON13);
ChuShiHuanZhoBiao();//因为我设计的是军棋,这个函数是用来初始化棋盘的
}
#3
BOOL CNikeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_BoardBitmap.LoadBitmap(IDB_BITMAP6);//里面的是棋盘图片
BITMAP bm;
m_BoardBitmap.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CClientDC dc(this);
m_BackBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight);
m_pdcBack->CreateCompatibleDC(&dc);
m_pdcBoard->CreateCompatibleDC(&dc);
m_pdcBoard->SelectObject(&m_BoardBitmap);
m_pdcBack->SelectObject(&m_BackBitmap);
return TRUE; // return TRUE unless you set the focus to a control
}
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_BoardBitmap.LoadBitmap(IDB_BITMAP6);//里面的是棋盘图片
BITMAP bm;
m_BoardBitmap.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CClientDC dc(this);
m_BackBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight);
m_pdcBack->CreateCompatibleDC(&dc);
m_pdcBoard->CreateCompatibleDC(&dc);
m_pdcBoard->SelectObject(&m_BoardBitmap);
m_pdcBack->SelectObject(&m_BackBitmap);
return TRUE; // return TRUE unless you set the focus to a control
}
#4
void CNikeDlg::BaiQi(CDC *pdc)
{CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP6);//将棋盘的图片(bmp)放入对话框
BITMAP bm;
bmp.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CDC MemDC;
MemDC.CreateCompatibleDC(pdc);
CBitmap* pOldBmp=MemDC.SelectObject(&bmp);
m_pdcBack->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBmp);
//将原始棋子阵形放入棋盘
m_pdcBack->BitBlt(0,0,nWidth,nHeight,m_pdcBoard,0,0,SRCCOPY);
int i=1,distance=0,x0=18,y0=18,j,k,x1=18+39*4,y1=18+39*12;
CString str;
//site[i][j][1]的意思是座标为X=i,Y=j里面的棋子的代号如果这个座标没有棋子则值为13
//zhituan=1为正方为0为反方.
for(j=0;j<5;j++){//对手的棋子,背面统一颜色
for(k=0;k<13;k++){
if(zhituan==0){
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[site[j][k][1]]);y0=y0+39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[0]);y0=y0+39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y0=y0+39;}
else {
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[site[j][k][1]]);y1=y1-39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[0]);y1=y1-39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y1=y1-39;}
}//for(k=0;k<12;k++)
if(zhituan==0){y0=18;x0=x0+39;}
else {y1=18+39*12;x1=x1-39;}
}//for(j=0;j<5;j++)
pdc->BitBlt(70,80,nWidth,nHeight,m_pdcBack,0,0,SRCCOPY);
}
{CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP6);//将棋盘的图片(bmp)放入对话框
BITMAP bm;
bmp.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CDC MemDC;
MemDC.CreateCompatibleDC(pdc);
CBitmap* pOldBmp=MemDC.SelectObject(&bmp);
m_pdcBack->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBmp);
//将原始棋子阵形放入棋盘
m_pdcBack->BitBlt(0,0,nWidth,nHeight,m_pdcBoard,0,0,SRCCOPY);
int i=1,distance=0,x0=18,y0=18,j,k,x1=18+39*4,y1=18+39*12;
CString str;
//site[i][j][1]的意思是座标为X=i,Y=j里面的棋子的代号如果这个座标没有棋子则值为13
//zhituan=1为正方为0为反方.
for(j=0;j<5;j++){//对手的棋子,背面统一颜色
for(k=0;k<13;k++){
if(zhituan==0){
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[site[j][k][1]]);y0=y0+39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[0]);y0=y0+39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y0=y0+39;}
else {
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[site[j][k][1]]);y1=y1-39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[0]);y1=y1-39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y1=y1-39;}
}//for(k=0;k<12;k++)
if(zhituan==0){y0=18;x0=x0+39;}
else {y1=18+39*12;x1=x1-39;}
}//for(j=0;j<5;j++)
pdc->BitBlt(70,80,nWidth,nHeight,m_pdcBack,0,0,SRCCOPY);
}
#5
但奇怪的是棋盘和下半部分的棋子可以显示出来,上半部分即对家的棋子显示不出来,
================================================================================
会不会是被棋盘覆盖了,没有刷新啊?
================================================================================
会不会是被棋盘覆盖了,没有刷新啊?
#6
唉,我花了半个钟检查你的代码,没有错误(下次写代码上去写好看一点),我知道你什么原因了,你的程序还应该有很多代码吧,你最好在你建立每个新的类型之后在"编译"那里找到重建全部,点击,相信可以解决你的问题.
#7
搞定了,像阿辉所说就行了,跟大家说声谢谢
#1
仔细检查代码, 没有代码没法帮你
#2
CNikeDlg::CNikeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNikeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNikeDlg)
m_55 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_pdcBoard=new CDC;//储存棋盘图案的 DC
m_pdcBack=new CDC;//缓冲 DC
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
a[0]=AfxGetApp()->LoadIcon(IDI_ICON1);//将棋子图片放入数组.
a[1]=AfxGetApp()->LoadIcon(IDI_ICON2);
a[2]=AfxGetApp()->LoadIcon(IDI_ICON3);
a[3]=AfxGetApp()->LoadIcon(IDI_ICON4);
a[4]=AfxGetApp()->LoadIcon(IDI_ICON5);
a[5]=AfxGetApp()->LoadIcon(IDI_ICON6);
a[6]=AfxGetApp()->LoadIcon(IDI_ICON7);
a[7]=AfxGetApp()->LoadIcon(IDI_ICON8);
a[8]=AfxGetApp()->LoadIcon(IDI_ICON9);
a[9]=AfxGetApp()->LoadIcon(IDI_ICON10);
a[10]=AfxGetApp()->LoadIcon(IDI_ICON11);
a[11]=AfxGetApp()->LoadIcon(IDI_ICON12);
a[12]=AfxGetApp()->LoadIcon(IDI_ICON13);
ChuShiHuanZhoBiao();//因为我设计的是军棋,这个函数是用来初始化棋盘的
}
: CDialog(CNikeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNikeDlg)
m_55 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_pdcBoard=new CDC;//储存棋盘图案的 DC
m_pdcBack=new CDC;//缓冲 DC
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
a[0]=AfxGetApp()->LoadIcon(IDI_ICON1);//将棋子图片放入数组.
a[1]=AfxGetApp()->LoadIcon(IDI_ICON2);
a[2]=AfxGetApp()->LoadIcon(IDI_ICON3);
a[3]=AfxGetApp()->LoadIcon(IDI_ICON4);
a[4]=AfxGetApp()->LoadIcon(IDI_ICON5);
a[5]=AfxGetApp()->LoadIcon(IDI_ICON6);
a[6]=AfxGetApp()->LoadIcon(IDI_ICON7);
a[7]=AfxGetApp()->LoadIcon(IDI_ICON8);
a[8]=AfxGetApp()->LoadIcon(IDI_ICON9);
a[9]=AfxGetApp()->LoadIcon(IDI_ICON10);
a[10]=AfxGetApp()->LoadIcon(IDI_ICON11);
a[11]=AfxGetApp()->LoadIcon(IDI_ICON12);
a[12]=AfxGetApp()->LoadIcon(IDI_ICON13);
ChuShiHuanZhoBiao();//因为我设计的是军棋,这个函数是用来初始化棋盘的
}
#3
BOOL CNikeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_BoardBitmap.LoadBitmap(IDB_BITMAP6);//里面的是棋盘图片
BITMAP bm;
m_BoardBitmap.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CClientDC dc(this);
m_BackBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight);
m_pdcBack->CreateCompatibleDC(&dc);
m_pdcBoard->CreateCompatibleDC(&dc);
m_pdcBoard->SelectObject(&m_BoardBitmap);
m_pdcBack->SelectObject(&m_BackBitmap);
return TRUE; // return TRUE unless you set the focus to a control
}
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_BoardBitmap.LoadBitmap(IDB_BITMAP6);//里面的是棋盘图片
BITMAP bm;
m_BoardBitmap.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CClientDC dc(this);
m_BackBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight);
m_pdcBack->CreateCompatibleDC(&dc);
m_pdcBoard->CreateCompatibleDC(&dc);
m_pdcBoard->SelectObject(&m_BoardBitmap);
m_pdcBack->SelectObject(&m_BackBitmap);
return TRUE; // return TRUE unless you set the focus to a control
}
#4
void CNikeDlg::BaiQi(CDC *pdc)
{CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP6);//将棋盘的图片(bmp)放入对话框
BITMAP bm;
bmp.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CDC MemDC;
MemDC.CreateCompatibleDC(pdc);
CBitmap* pOldBmp=MemDC.SelectObject(&bmp);
m_pdcBack->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBmp);
//将原始棋子阵形放入棋盘
m_pdcBack->BitBlt(0,0,nWidth,nHeight,m_pdcBoard,0,0,SRCCOPY);
int i=1,distance=0,x0=18,y0=18,j,k,x1=18+39*4,y1=18+39*12;
CString str;
//site[i][j][1]的意思是座标为X=i,Y=j里面的棋子的代号如果这个座标没有棋子则值为13
//zhituan=1为正方为0为反方.
for(j=0;j<5;j++){//对手的棋子,背面统一颜色
for(k=0;k<13;k++){
if(zhituan==0){
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[site[j][k][1]]);y0=y0+39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[0]);y0=y0+39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y0=y0+39;}
else {
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[site[j][k][1]]);y1=y1-39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[0]);y1=y1-39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y1=y1-39;}
}//for(k=0;k<12;k++)
if(zhituan==0){y0=18;x0=x0+39;}
else {y1=18+39*12;x1=x1-39;}
}//for(j=0;j<5;j++)
pdc->BitBlt(70,80,nWidth,nHeight,m_pdcBack,0,0,SRCCOPY);
}
{CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP6);//将棋盘的图片(bmp)放入对话框
BITMAP bm;
bmp.GetBitmap(&bm);
int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
CDC MemDC;
MemDC.CreateCompatibleDC(pdc);
CBitmap* pOldBmp=MemDC.SelectObject(&bmp);
m_pdcBack->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBmp);
//将原始棋子阵形放入棋盘
m_pdcBack->BitBlt(0,0,nWidth,nHeight,m_pdcBoard,0,0,SRCCOPY);
int i=1,distance=0,x0=18,y0=18,j,k,x1=18+39*4,y1=18+39*12;
CString str;
//site[i][j][1]的意思是座标为X=i,Y=j里面的棋子的代号如果这个座标没有棋子则值为13
//zhituan=1为正方为0为反方.
for(j=0;j<5;j++){//对手的棋子,背面统一颜色
for(k=0;k<13;k++){
if(zhituan==0){
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[site[j][k][1]]);y0=y0+39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x0,y0,a[0]);y0=y0+39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y0=y0+39;}
else {
if(site[j][k][0]==zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[site[j][k][1]]);y1=y1-39;}//若是正方且该点有棋子在
if(site[j][k][0]!=zhituan&&site[j][k][1]<13){
m_pdcBack->DrawIcon(x1,y1,a[0]);y1=y1-39;}//若是反方只显示背面
if(site[j][k][1]==14||site[j][k][1]==15)y1=y1-39;}
}//for(k=0;k<12;k++)
if(zhituan==0){y0=18;x0=x0+39;}
else {y1=18+39*12;x1=x1-39;}
}//for(j=0;j<5;j++)
pdc->BitBlt(70,80,nWidth,nHeight,m_pdcBack,0,0,SRCCOPY);
}
#5
但奇怪的是棋盘和下半部分的棋子可以显示出来,上半部分即对家的棋子显示不出来,
================================================================================
会不会是被棋盘覆盖了,没有刷新啊?
================================================================================
会不会是被棋盘覆盖了,没有刷新啊?
#6
唉,我花了半个钟检查你的代码,没有错误(下次写代码上去写好看一点),我知道你什么原因了,你的程序还应该有很多代码吧,你最好在你建立每个新的类型之后在"编译"那里找到重建全部,点击,相信可以解决你的问题.
#7
搞定了,像阿辉所说就行了,跟大家说声谢谢