way to remove comma from format of windows edit control? (C++) - c++

using a windows EDIT control with ES_NUMBER style and with an accompanying UPDOWN control, the default number written to the EDIT control uses a comma in the thousands place. Is there any way to turn off this behavior?
I tried intercepting a notification from the UPDOWN control and immediately overwriting the text but it looks like either the notification isn't being detected or I'm overwriting the text just before it writes the new value.

Add the UDS_NOTHOUSANDS style to the spin button control.

Related

I have a CEdit box. When I disable the box and immediately after try to call SetReadOnly, it stays disabled. Why is this?

There's not a particular reason I'm wanting to do this, it's more for my knowledge of how this stuff works.
I have an edit box derived from CWnd. Let's call it m_edtBox.
When I call m_edtBox.EnableWindow(FALSE)
followed immediately by
m_edtBox.SetReadOnly(TRUE),
the box stays disabled. It does not take on the read-only property. I'm simply curious as to why this is?
A disabled window is a window that
receives no keyboard or mouse input from the user [...].
In other words, the WS_DISABLED window style controls, whether a control gets to handle user input at all.
Contrast that with the ES_READONLY edit control style. It controls which user input that has an effect on the control.
Prevents the user from typing or editing text in the edit control.
Both styles can be set independently, and although both relate to user input, they serve different purposes.

How to disable user selection in Windows console

I need to disable user mouse selection in the Windows console. Is it possible and how? I tried the function SetConsoleMode() to disable mouse input with it, but it did not work as I expected. Selecting was still possible.
The console's quick-edit mode allows the user to quickly select and copy text using the mouse, without having to first enter mark mode (i.e. Ctrl+M, or Edit -> Mark on the menu). It's usually convenient to enable quick-edit mode, but it does interfere with getting mouse input. You can disable it using a handle for the console input buffer as follows:
DWORD prev_mode;
GetConsoleMode(hInput, &prev_mode);
SetConsoleMode(hInput, ENABLE_EXTENDED_FLAGS |
(prev_mode & ~ENABLE_QUICK_EDIT_MODE));
Remember to restore the previous mode at exit.

How can I create a Spin Button Control dynamically in MFC using CSpinButtonCtrl class?

I realize that this is a trivial problem and I even looked at an MFC book(Programming Windows with MFC by Prosise). However, I couldn't really find a solution.
I am trying to create a Spin Button Control dynamically and here is a simplified code:
CEdit* m_editControl = new CEdit();
m_EditControl->Create(WS_VISIBLE | WS_CHILD , rectEdit, this, EditID);
CSpinButtonCtrl* m_spinControlCtrl = new CSpinButtonCtrl;
m_spinControlCtrl->Create(WS_VISIBLE | WS_CHILD, rectSpinButton, this, SpinID);
m_spinControlCtrl->SetBase(10);
m_spinControlCtrl->SetBuddy(m_editControl );
m_spinControlCtrl->SetRange(-55, 55);
My problem is that the spin button does not change the value of the CEdit. Am I missing something? How can I create a Spin Button Control dynamically?
Your spin control is missing the style UDS_SETBUDDYINT:
UDS_SETBUDDYINT Causes the up-down control to set the text of the
buddy window (using the WM_SETTEXT message) when the position changes.
The text consists of the position formatted as a decimal or
hexadecimal string.
I also suggest setting UDS_ARROWKEYS so the arrow keys can be used to increment or decrement the value when the focus is on the edit control.
For the edit control I would add WS_TABSTOP so the user can navigate using the TAB key and WS_EX_CLIENTEDGE so the edit control shows the regular themed border.
I also noticed that you use dynamic memory allocation for the controls, which is not necessary. Just create non-pointer member variables like CEdit m_EditControl; so you don't have to worry about deallocation.
Fixed code:
m_EditControl.CreateEx(WS_EX_CLIENTEDGE, L"Edit", L"0", WS_VISIBLE|WS_CHILD|WS_TABSTOP,
rectEdit, this, EditID);
m_spinControlCtrl.Create(WS_VISIBLE|WS_CHILD|UDS_SETBUDDYINT|UDS_ARROWKEYS,
rectSpinButton, this, SpinID);
m_spinControlCtrl.SetBase(10);
m_spinControlCtrl.SetBuddy(&m_EditControl);
m_spinControlCtrl.SetRange(-55, 55);
I also strongly suggest learning to use Spy++. This is how I actually arrived at this answer. Using the resource editor I just dropped an edit control and an up-down control onto a dialog and used Spy++ to observe the default window styles.

How to increase character limit in MFC static control

We are using MFC static control in a dialog box to display some content to user. Both static control and dialog box are defined in a resource file (.rc) as LTEXT and DIALOG. Problem is if content is more than 256 character, it gets truncated. Does anyone know how can this limit be increased. The control and dialog box are old style.
You can vote for this problem here. Don't expect miracles, the resource compiler is neolithic. You'll have to work around it by using more than one static control or setting the text at runtime in the WM_INITDIALOG message handler. Don't overestimate the user's patience.
Static controls display text but have no user interaction; They don't have scroll bars, and truncate text to fit the control's bounds. If your problem is that the text fills the control and is truncated, consider switching to a read-only edit control.
If however the control is only accepting 256 characters even though there is room for more, I'm not sure why that would be. MSDN doesn't mention a limit to the size of the control's text.
In my understanding the compiler seems to have limitation with the in-lined strings in the compilable modules. Why don't you mind creating a string table if you're using such large text for a caption? For static controls there are no such limitations with 256K characters.

Manipulating scrollbars in third-party application

I need to create an application which do the following:
At the beginning we have notepad window open with a lot of text in it.
Our application must scroll through this file and take notepad window screenshot after each scroll action.
I've tried to achieve this using SBM_GETRANGE, SBM_GETRANGE, SBM_SETPOS but it does not work for me.
Please note that emulating keyboard events (e.g. PageDown, PageUp) is not an option for me because this application should also work with other applications which may not support keyboard shortcuts for manipulating scrolls.
Thanks.
Don't try to manipulate the scrollbar directly - instead SetFocus() to the text window, then send Page Down messages. If there are applications where you must manipulate the scrollbar, you should get its window handle and send the messages there.