-
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
-
set the ES_PASSWORD in your password edit win.
-
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
}