NTK and The NTK Project
are properties of Jn Dechereux
Home | Documentation | FAQ.

Vanilla 1.1.8 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthorHansB
    • CommentTimeOct 26th 2022 edited
     
    Hi group,
    A couple years ago I've designed a full login manager system to access my program (got inspired from the seapwd.prg source that comes with Appdemo sample).
    Recently i've been asked to add some kind of 'cosmetic control' we commonly find nowadays on most Apps and that allows operators to show/hide password visbility while editing.

    My code looks like that:

    @ 150, 30 GET cPassWord ID IDGET_PWD ;
    SIZE 25,210 ;
    PICTURE "@PW" ;
    FONT NTK_GetStockObject(DEFAULT_GUI_FONT) ;
    TEXTCOLOR NTK_RGB(255,255,255) ;
    BACKCOLOR NTK_RGB(255,128,000) ;
    STYLE GS_BORDER ;
    VALID ChkPassWord(hDlg, IDGET_PWD, @cPassWord);
    MESSAGE "Enter your password" ;
    OF hDlg

    @ 150,242 BUTTON "" SIZE 25,25 ; // Buddy Btn
    ID IDBTN_PWD ;
    STATE NTK_BT_ENABLE ;
    SUPER ACCEL KEY K_F5 ;
    FONT hFontBtn ;
    TYPE NTK_BT_OWNERDRAWN ;
    TEXTCOLOR NTK_RGB(255,255,255) ;
    BITMAP UP "16_EyePwdUp" ;
    BITMAP DN "16_EyePwdDn" ;
    BITMAP OVR "16_EyePwdOvr" ;
    SHIFT TO 2,2 ;
    MESSAGE "Toggle password visibility" ;
    ACTION DoTogglePwd( ??? ) ;
    OF hDlg

    Unfortunately I must admit i'm a bit stuck with the DoTooglePwd() - How to code this in NTK ???
    Would anybody already have a piece of code/any function he/she may want to share?

    Thanks in advance.
    •  
      CommentAuthorxbasefan
    • CommentTimeOct 31st 2022 edited
     
    hmm, solution to your problem is not rocket science - just bear in mind that a ntkrad @..get..picture "@pw" is nothing more than a ntkcore editbox control that has the ES_PASSWORD style enabled.
    btw according to msdn documentation:
    'ES_PASSWORD displays an asterisk (*) for each character typed into the edit control. You can use the EM_SETPASSWORDCHAR message to change the character that is displayed.'
    so basic code below should do the job. up to you to adjust it to your own needs.
    Function TogglePwdStyle(nGetID)
        local hEdit := NTK_GiveGetHandle(aGetList, nGetID)
        if (NTK_SendMessage(hEdit,EM_GETPASSWORDCHAR,0,0) == '*')   // 0x2A
           NTK_SendMessage(hEdit,EM_SETPASSWORDCHAR,0,0)  // visible
        else
           NTK_SendMessage(hEdit,EM_SETPASSWORDCHAR, 0x2A ,0) // masked again. remember: 3rd param passed as byte
           NTK_SetFocus(hEdit)
        endif
    Return(Nil)
    

    hth
    wilson
    n.b. i personally use this approach since years without any problems.
    •  
      CommentAuthorHansB
    • CommentTimeNov 3rd 2022 edited
     
    Hi Wilson
    Brillant! Works perfectly. neat code & easy to understand but personally not enough brain to write it by myself, for sure! :wink:
    Thank you very much.