天天看點

vc動态生成按鈕并響應 .

void CBtnDlg::OnOK()

{

 // TODO: Add extra validation here

 // 動态建構按鈕代碼

 CButton* pNewButton = new CButton();// 也可以定義為類的成員變量。

 CRect rcButton( 10, 10, 50, 30); // 按鈕在對話框中的位置。

 pNewButton->Create("按鈕", 0, rcButton, this, 10098);

 pNewButton->ShowWindow(SW_SHOW);

 //CDialog::OnOK();

}

LRESULT CBtnDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)

 // TODO: Add your specialized code here and/or call the base class

 if ( WM_COMMAND== message )

 {

  WORD wID = LOWORD(wParam);

  if ( 10098 == wID)

  {

   CDC* pDC = GetDC();

   pDC->TextOut( 100, 100, "文字");

   ReleaseDC(pDC);

  }

    }

 return CDialog::DefWindowProc(message, wParam, lParam);