BOOL CWebgameTestDlg::CreateRoleBnt(CPoint pPoint , CString pName)
{
#define   IDC_MYBUTTON   200
CRect r_client;
this->GetWindowRect(r_client);
// ScreenToClient(r_client);
CRect new_r_client = CRect(pPoint.x,pPoint.y,pPoint.x + 30,pPoint.y + 100);
if (pPoint.x < r_client.left || pPoint.x > r_client.right || pPoint.y < r_client.top || pPoint.y > r_client.bottom)
{
return 1;
}
CButton *t_player;
t_player = new CButton();
t_player->Create(pName,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,new_r_client,this,IDC_MYBUTTON);
t_player->ShowWindow(SW_SHOW);
delete t_player;
return 0;
}創建Create返回值為1 ,顯示不出來,是什麽問題的呢???

解决方案 »

  1.   

    delete t_player;
    删除了吧。
      

  2.   

    CButton t_player;
    t_player.Create(pName,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,new_r_client,this,IDC_MYBUTTON);
    t_player.ShowWindow(SW_SHOW);这样试下。
      

  3.   

    CButton *t_player; 
    t_player = new CButton(); 
    t_player->Create(pName,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,new_r_client,this,IDC_MYBUTTON); 
    t_player->ShowWindow(SW_SHOW); 
    delete t_player;  //楼主, 动态创建,这个用法有点过分了,这样怎么可能显示,等不需要显示了才能delete。
      

  4.   

    动态创建的,用临时变量也不行的,资源的子类化或attach的才可以。
      

  5.   


    然后再加上 t_player.Detach(); 就对了,否则变量周期到了又被销毁了