MFC编译没有错误,但是执行窗口不出现,什么情况呢

解决方案 »

  1.   

    mfc么,init函数内部隐藏了主窗口或者 阻塞是可能的唯一原因
      

  2.   


    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
    }
      

  3.   


    // 斗地主记牌器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 Aboutclass 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 dialogCMyDlg::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)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyDlg message handlersBOOL 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];}