how to create password field and button in vc++ - visual-studio-2010

I am new in vc++ and i need a Password field in my application. I created edit textbox using below code but don't know how to create password field and button control.
CreateWindow(L"EDIT", L"hello", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
ES_AUTOHSCROLL | ES_WANTRETURN, 350, 500, 130, 20, hwnd, NULL, NULL, NULL);
Any help would be grateful. thanks

Try ES_PASSWORD :
Displays an asterisk (*) for each
character typed into the edit control.
This style is valid only for
single-line edit controls.
Windows XP: If the edit control is
from user32.dll, the default password
character is an asterisk. However, if
the edit control is from comctl32.dll
version 6, the default character is a
black circle.
To change the characters that is
displayed, or set or clear this style,
use the EM_SETPASSWORDCHAR message.
Note Comctl32.dll version 6 is not
redistributable but it is included in
Windows XP or later. To use
Comctl32.dll version 6, specify it in
a manifest. For more information on
manifests, see Enabling Visual Styles.
Source : Edit Control Styles
Edit
You mean creating a button ? Via Using Buttons :
HWND hwndButton = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed.
L"OK", // Button text.
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
0, // x position.
0, // y position.
50, // Button width.
50, // Button height.
hwnd_parentwindow,
NULL, // No menu.
(HINSTANCE)GetWindowLong(hwnd_parentwindow, GWL_HINSTANCE),
NULL);

You can select the edit box and right click and choose its properties. In that there is an option called password. Just check it.
Also this link will help you.
http://msdn.microsoft.com/en-us/library/d3223ht2.aspx
Or if you want you can directly add
ES_PASSWORD
also along with rest.

Related

Is it possible to set DateTimePicker to dropdown the monthCalendar by default?

To avoid a duplicate control to CreateWindowEx(0,MONTHCAL_CLASS,...), it is expected to have DateTimePick_Class control showing DropDown Calendar defaultly.
HWND hwndDP = CreateWindowEx(
0,
DATETIMEPICK_CLASS,
TEXT("DateTime"),
WS_BORDER | WS_CHILD | WS_VISIBLE | DTS_SHOWNONE,
50, 20,200,25,
hWnd,
(HMENU)ID_DATETIME_PICKer,
hInst,
NULL);
But it seems that one has to know the control of dropdown arrow button say "ARROW_BTN", like this
SendMessage(hwndDP,WM_NOTIFY,(int)ARROW_BTN,(NMHDR)DTN_DROPDOWN);
or
SendMessage(hwndDP,DTN_DROPDOWN,0,0);
what is the command to retrieve the control ID or some other tricks behind?

Resizing an edit window

I have a simple edit window:
hwndEdit = CreateWindow(
TEXT("EDIT"),
TEXT("EDIT"),
WS_BORDER | WS_CHILD | ES_LEFT,
100,
100,
100,
30,
gHwnd,
0,
hInst,
0);
I have noticed that when I paste there a text which is longer than an edit window width I get notification (EN_CHANGE) which contains only a portion of the text which fits a window width. I would like to resize an edit window (SetWindowPos) when a text is longer than the edit window width. I can create an edit window based on MSFTEDIT_CLASS and use EN_REQUESTRESIZE. Do you know any other solution or that is the only option ?
The text is truncated by your edit control on paste.
To allow more text in that control without changing the size (which is not practical for many reasons), simply add ES_AUTOHSCROLL style to your CreateWindow call.

Implementing a dialog background image

using c++ under visual studio 2010.
I have a dialog creation section
IDD_LOGON DIALOGEX 0, 0, 265, 70
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
CAPTION "Log On to Windows"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_NAME,61,9,127,14,ES_AUTOSCROLL
EDITTEXT IDC_PASSWORD,61,29,127,14,ES_PASSWORD | ES_AUTOSCROLL
EDITTEXT IDC_DOMAIN,61,49,127,14,ES_AUTOSCROLL
DEFPUSHBUTTON "OK",IDOK,204,8,50,14
PUSHBUTTON "Cancel",IDCANCEL,204,25,50,14
LTEXT "Domain:",IDC_STATIC,21,52,27,8
LTEXT "Password:",IDC_STATIC,21,32,34,8
LTEXT "User Name:",IDC_STATIC,17,12,38,8
PUSHBUTTON "Shutdown",IDC_SHUTDOWN,204,49,50,14
END
I would like to have an image in the background of this dialog.
How would i go about performing this action?
thank you
In your OnInitDialog() use:
this->SetBackgroundImage(IDB_BITMAP1, BACKGR_TOPLEFT, TRUE);
For more info refer : CDialogEx::SetBackgroundImage
There is no way to do this through the dialog template/designer. You will need to handle the WM_ERASEBKGND message in your dialog and paint the background yourself.
Here is some info:
http://www.codeproject.com/Articles/18967/Bitmap-Backgrounds-For-Dialog-Boxes
quick answer... i dropped the image control on the dialog, set the image... then... i went into the code and placed it at the TOP of the stack, and it was painted with no issues. the transparent portion of the other controls was failing, so i grouped them all into an area of the same background color on the image, and walla - all done. thank you

win32 api edit control can't be selected or edited

I created an edit control using win32 api like this:
CreateWindow("edit", "", WS_CHILD |
WS_VISIBLE, 0, m_position,
CONTROLS_WIDTH, EDITBOX_HEIGHT,
m_editorWindow,
(HMENU)GetNextComponentID(),
m_instance, NULL)
I can change the text from it using SetWindowText, but I can't select it or edit it's content - this is the purpose of an edit control, or not?:))
I read on MSDN http://msdn.microsoft.com/en-us/library/bb775458%28VS.85%29.aspx that I must use Edit_enable but I don't know where to find thin macro and I don't heave any idea how to enable editing. When I move the cursor over it the cursor changes to standard edit cursor.
Thank you for help!
Or you could try:
HWND myWindow = CreateWindow("edit", "", WS_CHILD | WS_VISIBLE, 0, m_position, CONTROLS_WIDTH, EDITBOX_HEIGHT, m_editorWindow, (HMENU)GetNextComponentID(), m_instance, NULL);
EnableWindow(myWindow, true);
It works with SetFocus(hwnd) function.
Have you tried:
GetDlgItem(EditControlID)->EnableWindow(TRUE);
lol Oops.

How to add a custom button to windows' minimize/maximize/close (x)

I was wondering if there is a way to add (programatically, of course) an icon/button/whatever besides plain text to a window (Microsoft Windows window...)'s title bar or next to where the minimize/maximize/close buttons are. I could draw it myself and create an illusion it is a part of the window, but I wonder if in the user32 api there is such a method.
So far, I found a way to disable the minimize/maximize/close buttons but not a way to add a custom one to them. It seems strange to me.
Here is what I am trying to achieve:
I have been wondering how it is done here, since drawing a button for every window using gdi/gdi+ and then detecting if it is overlapped by another window and then displaying only the non-overlapped part seems to me like an unlikely solution. Probably the button has been registered in the window class so that every window has this button. Any pointers what to do?
In addition, how do I create a button at all, assuming I DON'T have Unicode enabled. Then in the following piece of code:
HWND hwndCommandLink = CreateWindow(
L"BUTTON", // Class; Unicode assumed.
L"", // Text will be defined later.
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_COMMANDLINK, // Styles.
10, // x position.
10, // y position.
100, // Button width.
100, // Button height.
hDlg, // Parent window.
NULL, // No menu.
(HINSTANCE)GetWindowLong(hDlg, GWL_HINSTANCE),
NULL); // Pointer not needed.
SendMessage(clHwnd, WM_SETTEXT, 0, (LPARAM)L"Command link");
SendMessage(clHwnd, BCM_SETNOTE, 0, (LPARAM)L"with note");
I have to substitute all the nice Windows constants with their long equivalent....However, when I search for them, all i get is this:
http://msdn.microsoft.com/en-us/library/bb775951(v=VS.85).aspx
Any pointers?

Resources