win32 api edit control can't be selected or edited - winapi

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.

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.

How to change text size in basic text window win32 c++

I am making a very basic tic tac toe game as my first ever attempt at anything windows. I have only a small amount of basic c++ experience as well. At the top of my program i want it to display in a large font "WELCOME TO TIC-TAC-TOE!", and then right underneath it in a much smaller font something like "DEVELOPED BY ....." or something. This is the code i wrote making the text window:
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("STATIC"),TEXT("WELCOME TO TIC-TAC-TOE!"), WS_CHILD|WS_VISIBLE|SS_CENTER, 20,20,210,20,hWnd,HMENU(NULL),GetModuleHandle(NULL),NULL);
Is there a way to make the text font for "WELCOME TO TIC-TAC-TOE!" bigger? Thanks!
The following code worked if any are interested, thanks to ScottMcP-MVP for pointing me to the right website:
hwnda = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("STATIC"),TEXT("WELCOME TO TIC-TAC-TOE!"), WS_CHILD|WS_VISIBLE|SS_CENTER, 20,20,210,20,hWnd,HMENU(NULL),GetModuleHandle(NULL),NULL);
hFont=CreateFont (20, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Arial");
SendMessage (hwnda, WM_SETFONT, WPARAM (hFont), TRUE);
I hope you save the HWND returned by CreateWindowEx: You will need it. After you create the STATIC window send it the WM_SETFONT message, as outlined here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632642(v=vs.85).aspx
Note especially the remarks on that page about font lifetime.

how to create password field and button in vc++

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.

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