MFC窗口不弹出!

wind4561906wind 2011-10-18 10:49:46
// 斗地主记牌器Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "斗地主记牌器.h"
#include "斗地主记牌器Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void MiddleStr(char *s,char *d,int n,int m=-1);
int FindChar(char *s,char ch,int n=1);
void CutSpace(char *s);
int data[]={ 0,4,4,4,4,4,4,4,4,4,4,4,4,4,2 };
int change(char c);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_out = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_EDIT_INPUT, m_input);
DDX_Text(pDX, IDC_EDIT_OUT, m_out);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_INPUT, OnButtonInput)
ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::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
::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE); //使观察器不被其他窗口覆盖
RenewData(); //显示初始化信息
return TRUE; // return TRUE unless you set the focus to a control
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CMyDlg::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
{
CDialog::OnPaint();
}
m_input.SetFocus(); //激活编辑框,打开对话框即可输入数据
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CMyDlg::OnButtonInput()
{
char card[]="134567890JQKA2W",d[101],s[101],c;
int lcard,ls,ld,i,j,p,p1,p2;
m_input.GetWindowText(d,99); //取出输入的数据
CutSpace(d); //删除所有空格
strupr(d);
lcard=strlen(card);
ld=strlen(d);
if(!ld) return;
while(d[0])
{
p=FindChar(d,',');
if(!p) p=ld+1;
MiddleStr(s,d,1,p-1);
MiddleStr(d,d,p+1);
ls=strlen(s);
for(i=0;i<ls;i++)
{
c=s[i];
for(j=0;j<lcard;j++)
if(card[j]==c) break;
if(j==lcard)
{
MessageBeep(0);
return;
}
p1=change(c);
if(s[i+1=='-'])
{
i+=2;
c=s[i];
for(j=0;j<lcard;j++)
if(card[j]==c) break;
if(j==lcard)
{
MessageBeep(0);
return;
}
p2=change(c);
if(p1>12 || p2>12 || p1>p2)
{
MessageBeep(0);
return;


}
for(j=p1;j<p2+1;j++)

if(data[j]) data[j]--;
RenewData();
continue;

}
if(data[p1]) data[p1]--;
RenewData();
}


}

m_input.SetWindowText("");
m_input.SetFocus();


}

void CMyDlg::OnButtonReset()
{

}

//刷新控件数据
void CMyDlg::RenewData()
{
char s[111]=" 3 4 5 6 7 8 9 0 J Q K A 2 W ";
char d[11];
int i;
for(i=1;i<15;i++) //根据data的值生成剩余牌输出结果
{
strcat(s," ");
if (!data[i]) strcpy(d," "); //该点数无牌是显示空格
if(data[i]>0 && data[i]<4) itoa(data[i],d,10); //不到四张牌时候显示实际数字
if(i==14 && data[i]==2) strcpy(d,"*"); //大小王都未出时显示炸弹标志
strcat(s,d);

}
m_out=s; //修改“输出”编辑框变量的值
UpdateData(false);
}

//将首字母表示的牌变成数字代码
int change(char c)

{
int p;
p=c-50;
if(c=='0') p=8; //10
if(c=='J') p=9;
if(c=='Q') p=10;
if(c=='K') p=11;
if(c=='A' || c=='1') p=12; //A
if(c=='2') p=13;
if(c=='W') p=14; //王
return p;


}



//查找指定字符(n<0反向查找,n=1)
int FindChar(char *s,char ch,int n)
{
int i,length=strlen(s);
if(n>0)
{

if(n>length) return 0;
for(i=n-1;i<length;i++)
if(s[i]==ch) return i+1;
return 0;

}
if(!n) n=length;
else n+=length+1;
if(n<1 || n>length) return 0;
for(i=n-1;i>-1;i--)
if(s[i]==ch) return i+1;
return 0;
}
//字符串赋值(将d第n个字符开始的m个字符赋给s,m=-1)
void MiddleStr(char *s,char *d,int n,int m)
{
int i,ld;
if(n<1) n=1;
if(m<0) m=30000;
ld=strlen(d);
if(n+m-1>ld) m=ld-n+1;
for(i=0;i<m;i++) s[i]=d[n+i-1];
s[i]=0;

}
//截掉字符串中空格
void CutSpace(char *s)
{
int i,k,length;
length=strlen(s);
k=0;
for(i=0;i<=length;i++)
if (s[i]!=' ') s[k++]=s[i];

}





void CMyDlg::OnButton3()
{
OnCancel();
}
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
www441864079 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sichuanpb 的回复:]

文件还有中文名 O(∩_∩)O哈哈~C/C++ code
int x=3
[/Quote]汉化过的,呵呵
sichuanwww 2011-10-18
  • 打赏
  • 举报
回复
文件还有中文名 O(∩_∩)O哈哈~
int x=3
笨笨仔 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wind4561906wind 的回复:]
奇怪,我想打出有颜色的代码,但是却不得,大侠教下,以便于大家以后能快速看出哪些代码是注释的
[/Quote]
用插入源代码方式
wind4561906wind 2011-10-18
  • 打赏
  • 举报
回复
奇怪,我想打出有颜色的代码,但是却不得,大侠教下,以便于大家以后能快速看出哪些代码是注释的

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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