我在对话框程序中通过按钮新建了另一个输入对话框,要求用户输入信息。但我想调用之前改变输入对话框中的静态文本的内容,欲获得新建对话框的句柄,从而改变新建对话框中文本控件的文本内容。
如何做到获得新建对话框的句柄?
代码如下:
void CMemory_key_testDlg::OnUnlockUsrPin()
{
// TODO: Add your control notification handler code here
char newUsrPin[16];
char unlockPin[16]; CChangUserPin m_hChangUserPin;
int iRet = m_hChangUserPin.DoModal(); //(GetDlgItem( IDC_STATIC_oldPin ))->SetWindowText( "Test111" ); switch( iRet )
{
case -1:
MessageBox( "对话框不能被创建起来!", "错误信息", MB_OK | MB_ICONEXCLAMATION );
return;
case IDABORT:
return;
case IDOK:
//接受cstring值,并传入函数参数中
strncpy(newUsrPin,(LPCTSTR)m_hChangUserPin.m_OldPin,sizeof(newUsrPin));
strncpy(unlockPin,(LPCTSTR)m_hChangUserPin.m_NewPin,sizeof(unlockPin));
break;
case IDCANCEL:
return;
default:
return;
} rv = NHTKEY_UnlockUsrPin(hKey,newUsrPin,unlockPin);
if( NHTKEY_SUCCESS != rv)
{
m_list.ResetContent();
m_list.AddString("NHTKEY_UnlockUsrPin error...\n");
}
else
{
m_list.ResetContent();
m_list.AddString("NHTKEY_UnlockUsrPin OK...\n");
(GetDlgItem( IDC_display ))->SetWindowText( "UnlockUsrPin OK!" );
}
return;
}
如何做到获得新建对话框的句柄?
代码如下:
void CMemory_key_testDlg::OnUnlockUsrPin()
{
// TODO: Add your control notification handler code here
char newUsrPin[16];
char unlockPin[16]; CChangUserPin m_hChangUserPin;
int iRet = m_hChangUserPin.DoModal(); //(GetDlgItem( IDC_STATIC_oldPin ))->SetWindowText( "Test111" ); switch( iRet )
{
case -1:
MessageBox( "对话框不能被创建起来!", "错误信息", MB_OK | MB_ICONEXCLAMATION );
return;
case IDABORT:
return;
case IDOK:
//接受cstring值,并传入函数参数中
strncpy(newUsrPin,(LPCTSTR)m_hChangUserPin.m_OldPin,sizeof(newUsrPin));
strncpy(unlockPin,(LPCTSTR)m_hChangUserPin.m_NewPin,sizeof(unlockPin));
break;
case IDCANCEL:
return;
default:
return;
} rv = NHTKEY_UnlockUsrPin(hKey,newUsrPin,unlockPin);
if( NHTKEY_SUCCESS != rv)
{
m_list.ResetContent();
m_list.AddString("NHTKEY_UnlockUsrPin error...\n");
}
else
{
m_list.ResetContent();
m_list.AddString("NHTKEY_UnlockUsrPin OK...\n");
(GetDlgItem( IDC_display ))->SetWindowText( "UnlockUsrPin OK!" );
}
return;
}
GetSafeHwnd()是很有效的获得句柄的函数。
{
CDialog::OnShowWindow(bShow, nStatus); GetDlgItem(IDC_STATIC_oldPin)->SetWindowText("Test111");
GetDlgItem(IDC_XXX)->SetFocus();
}
{
CDialog::OnShowWindow(bShow, nStatus); GetDlgItem(IDC_STATIC_oldPin)->SetWindowText("Test111");
GetDlgItem(IDC_XXX)->SetFocus();
}