C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[669] [Dialog] InputQuery에 PasswordChar 적용 - 펌
장성호 [nasilso] 7146 읽음    2007-07-10 11:28
[제목 ] InputQuery에 PasswordChar 적용

[출처 ]
http://www.delphikorea.com/board2007/bbs/view.php?id=lecture&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=1044


[개요]
간단한 text입력이 필요할때 InputQuery를 이용해서 받을수 있습니다.
하지만 password를 입력받을땐 VCL에서 InputQuery처럼 지원하는 함수가 없는걸로 알고있습니다.
그래서 InputQuery에 PasswordChar를 적용하여 사용하면 편리할것 같습니다.

아래코드는 위사이트에 Delphi로 된 코드를 C++Builder로 변환한것입니다.


[코드]
// Input Query도 Form이기 때문에 Form에서 특정컨트롤을 찾아서 PasswordChar를 먹인다
void __fastcall TForm1::WMInputQuery(TMessage &message )
{

  for( int i = 0 ; iFormCount ;i++ )
  {
    if( Screen->Forms[i]->Caption == "암호" )
      {
        for(int  j =0 ;j< Screen->Forms[i]->ControlCount;j++ )
        {
            String sClsName=Screen->Forms[i]->Controls[j]->ClassName();
          if ( sClsName == "TEdit" )
            {
              ((TEdit*)Screen->Forms[i]->Controls[j])->PasswordChar = '*';
              ((TEdit*)Screen->Forms[i]->Controls[j])->SelectAll();
              return;
            }
        }
      }
  }
}



void __fastcall TForm1::Button1Click(TObject *Sender)
{
    String PassWord;
    PostMessageA(Handle, CM_PASSWORD, 0, 0);  // 메시지 날리기
    if(InputQuery("암호", "암호를 입력 하세요.    ", PassWord))
    {
        ShowMessage(PassWord);
    }
}
//---------------------------------------------------------------------------


//======================================================
//---------------------------------------------------------------------------
#define  CM_PASSWORD     WM_USER + 10

class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TButton *Button1;
    void __fastcall Button1Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
    __fastcall TForm1(TComponent* Owner);

    void __fastcall TForm1::WMInputQuery(TMessage &message );

BEGIN_MESSAGE_MAP
    MESSAGE_HANDLER(CM_PASSWORD,TMessage,WMInputQuery)
END_MESSAGE_MAP(TForm)

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

박지훈.임프 [cbuilder]   2007-07-10 13:22 X
괜찮은 아이디어이긴 한데...
죄송합니다만, 이 정도의 공이면 새로 다이얼로그를 만드는 게 훨 더 쉽고 원하는 기능도 맘껏 붙일 수 있을 거 같은데요. ^^;;
김태선 [cppbuilder]   2007-07-10 13:29 X
나름 괜잖은 아이디어네요.


장성호 [nasilso]   2007-07-11 08:56 X
그럼 좀 수정합니다.
---------------------------
void __fastcall TForm1::WMInputQuery(TMessage &message )
{
    HWND hWnd=FindWindowEx(Screen->ActiveForm->Handle,0,"TEdit", NULL);
    SendMessage(hWnd, EM_SETPASSWORDCHAR, '*', 0);
}
위에 함수를 이렇게 바꾸면 조금  간단하게 보이나요?
장성호 [nasilso]   2008-02-26 11:22 X
void __fastcall TForm1::InputBoxSetPasswordChar(TMessage &Msg)
{
    HWND hInputForm, hEdit, hButton;

  hInputForm = Screen->Forms[0]->Handle;
  if(hInputForm )
  {
    hEdit = FindWindowEx(hInputForm, 0, "TEdit",NULL);
    {
      // Change button text:
      hButton = FindWindowEx(hInputForm, 0, "TButton", NULL);
      SendMessage(hButton, WM_SETTEXT, 0,LPARAM("Cancel"));
    }
    SendMessage(hEdit, EM_SETPASSWORDCHAR, '*', 0);
  }
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  String InputString;
  PostMessage(Handle, InputBoxMessage, 0, 0);
  InputString = InputBox("Input Box", "Please Enter a Password","");

}

+ -

관련 글 리스트
669 [Dialog] InputQuery에 PasswordChar 적용 - 펌 장성호 7146 2007/07/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.