Thread: Password dialog question

  1. #1
    myNegReal
    Join Date
    Jun 2005
    Posts
    100

    Password dialog question

    Basically, I'm trying to create a password dialog in C++ for window. This may seem like a lot to ask, but I'm a total noob when it comes to windows programming other than a simple window with a rendering context and simple procedure (I mostly program games).
    So here's what I have so far:

    resource.rc
    Code:
    #include <windows.h>
    
    // just a blank small dialog box
    106 DIALOG DISCARDABLE  0, 0, 100, 20
    STYLE WS_POPUP | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
    EXSTYLE WS_EX_TOOLWINDOW
    FONT 8, "MS Sans Serif"
    {
    }
    main.cpp
    Code:
    #include <windows.h>
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CLOSE: EndDialog(hwnd, 0);
                            break;
    		default:
    			return false;
    	}
    	return true;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, int nCmdShow) {
    	return DialogBox(hInstance, MAKEINTRESOURCE(106), 0, DlgProc);
    }
    Basically it's just a blank dialog. I wanna know how to add a small text box(the size of the window, no scrollbars or anything), that focuses on creation of the dialog, and is encrytped (shows *'s instead of what you type. it's for a password), and how to get the text typed in the text box when the user presses enter. I hope it's not too much to ask, I've been looking around and anything helpful I can find has to do with windows, not dialogs and they're created differently (not through resource, at least ones with text boxes). Thanks in advance
    Using Dev-C++ on Windows

  2. #2
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    set the ES_PASSWORD in your password edit win.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You can add additional resource definition statements to your resource script. For controls and such you can use the individual statements for each type or the generic CONTROL statement. To get password characters for your edit control, give it the ES_PASSWORD window style([edit]as kryptkat has already mentioned[/edit]).

    Note that using bare numbers as identifiers is not good practice; while it may be readable for one or two identifiers it will become confusing very quickly. Typically, identifiers are #defined in a resource header that is #included by all files that use its contents. For example:
    Code:
    /*resource defines: resources.h*/
    #define IDD_MYDIALOG 106
    #define IDC_MYPASSWORDTXT 200
    Code:
    #include <afxres.h>
    #include "resources.h"
    
    IDD_MYDIALOG DIALOGEX  0, 0, 100, 200
    STYLE WS_POPUP | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
    EXSTYLE WS_EX_TOOLWINDOW
    FONT 8, "MS Sans Serif"
    {
    EDITTEXT IDC_MYPASSWORDTXT, 100, 14, WS_VISIBLE|WS_CHILD|ES_PASSWORD, WS_EX_CLIENTEDGE
    }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to set this dialog to this
    By stallion in forum Windows Programming
    Replies: 3
    Last Post: 01-31-2003, 05:19 PM
  2. edit control in dialog box problems
    By Bajanine in forum Windows Programming
    Replies: 11
    Last Post: 11-11-2002, 06:55 PM
  3. Simple Dialog Question
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 09-13-2002, 02:46 PM
  4. Simple Dialog Box (noob)
    By tegwin in forum Windows Programming
    Replies: 6
    Last Post: 06-30-2002, 06:04 PM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM