Is there any way to programmatically scroll a single-line edit control in Windows?
For example, if the text in an edit control is too large to display at once, then the default behavior when the edit control gets the focus is to select all text and show the end of the text. I'd like to instead show the beginning of the text (while still leaving all text selected).
Although there's (apparently) no API for scrolling to the beginning and selecting all text, it seems to work to simulate the keystrokes that would do the same:
#ifndef CTRL
#define CTRL(x) (x&037)
#endif
SendMessage(edit_handle, WM_KEYDOWN, VK_HOME, 0);
SendMessage(edit_handle, WM_CHAR, CTRL('A'), 0);
You can either call SetScrollPos or send the WM_VSCROLL/WM_HSCROLL message directly to the window. You can find the full list of scroll functions here.
Related
So for the simple feat of wanting to put an icon on the right side of button text instead of the left resulted in having to use owner draw buttons (but someone here said Custom Draw is actually available if using visual themes). Okay, fine, but now I'm finding you can't really duplicate what Windows standard buttons do when it's not in owner draw mode.
For a normal enabled button I can get the look correct by checking if visual styles are available or not and then using either the DrawThemeBackground() / DrawThemeText() or DrawFrameControl() / DrawText(). However the hot key underline character is shown even when alt key is not pressed, the default buttons don't show it until alt pressed.
For a disabled button, I can't duplicate the disabled look of the icon placed on the button. I tried DrawState() over DrawIconEx() but that looks like the old Windows 3.1 type grey graphic not the visual style dimmed graphic. I see there is a DrawThemeIcon() for an image list, I guess I could try that (I'd have to test non visual style mode to see if DrawState() matches when not using visual styles).
Also, as you hover over the button, the state doesn't change, I understand that if using owner draw, that doesn't occur, maybe it would still work with Custom Draw?
So the two main questions are:
1 - Is there something built-in to the button / owner draw to handle the underlined hotkey only when alt was pressed?
Update to Question 1: I found DT_HIDEPREFIX in DrawText() and using Custom Draw there is the CDIS_SHOWKEYBOARDCUES flag. However with Owner Draw I'm not sure if there is a flag someplace?
2 - How do you draw an icon for a button that is disabled to match what default buttons do?
TIA!!
For shortcut underline you can use WM_QUERYUISTATE to ask if it should be hidden or visible
DWORD draw_text_flags = ...;
if ( SendMessage( control_hwnd, WM_QUERYUISTATE, 0, 0 ) & UISF_HIDEACCEL ) != 0 )
{
// hide prefix
draw_text_flags |= DT_HIDEPREFIX;
}
// some combination of PBS_DEFAULTED, PBS_DISABLED, PBS_HOT, PBS_NORMAL, PBS_PRESSED;
int state = ...;
DrawThemeText( theme, hdc, BP_PUSHBUTTON, state, text, text_len, draw_text_flags, 0, rect );
Answer to Q2: If you create an HIMAGELIST using ILC_COLOR32 | ILC_MASK, and use ILD_NORMAL|ILD_BLEND25 on ImageList_Draw() it gives the same look as windows default buttons for a disabled button.
Based on responses from #Remy-Lebeau and #Daniel-Sęk and reviewing various projects on CodeProject, I create an easy to use class to handle this. It can be found at CodeProject. Thanks Guys.
I what to display some text, probably using DrawText() on to the CTabView client area when no tabs exist to explain why they don't exist. However, CTabView::OnPaint() is not called except once at the app startup. Also when all tabs hidden the CTabView::OnDraw() is not called. I suppose the CMFCTabCtrl may be the one getting the OnPaint() callbacks? But nonetheless, how do you output something to that row/col of a CSplitterWnd occupied by a CTabView when all tabs are not shown (hidden via CMFCTabCtrl::ShowTab()). ??
TIA!!
The tab control works that way that all tab views are hidden - except the one which is open.
Where no tab view is open, none will receive a paint message (nor WM_ERASEBACKGROUND).
You could try implementing your paint stuff in the tab control's OnPaint handler.
On a Windows application, I want to check whether the foreground window (of any process) has the text cursor blinking or not.
There seems to be a standard way of doing it using the WinApi function GetGUIThreadInfo, as follows:
(it's C++ code, but the language is not important)
GUITHREADINFO threadInfo = {sizeof(GUITHREADINFO)} ;
GetGUIThreadInfo(NULL,&threadInfo) ;
bool caretState = threadInfo.flags & GUI_CARETBLINKING ; //true if the caret is blinking
This works perfectly for most programs but, unfortunately, not for Google Chrome, whose threadInfo.flags member never has the GUI_CARETBLINKING flag set.
Is there another way of detecting the text caret that works on Google Chrome?
For example, I know that screen readers can traverse Chrome's accessibility tree which exposes the contents of the window to external applications.
Is there, anywhere in this accessibility tree, information relative to the blinking caret?
Edit:
One of the comments made me realize that saying "blinking caret" could be interpreted as if I wanted to literally detect the graphical element known as blinking caret.
That's not my intention. What I'm trying to do is to detect what the blinking caret implies, which is that a text input field is focused.
I am developing a Qt 4.8 application using QGraphicsScene on Windows XP.
When the user double clicks on a QGraphicsTextItem, i call
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
At the next selection change i call
textItem->setTextInteractionFlags(Qt::NoTextInteraction);
This works correctly, but i find no way to remove the inversion of the background color that remains from editing. In the screen shot below, i first double clicked on the first text item and selected the characters "2927". Then i clicked on the second test item and selected "est". I find no way to get rid of the still inverted "2927" in the first text item (although its not in edit mode anymore).
I also tried to call:
textItem->textCursor().clearSelection();
textItem->update();
textItem->setTextInteractionFlags(Qt::NoTextInteraction);
textItem->clearFocus();
But his does not at all change the behavior.
So now i found a workaround:
QString s = textItem->toPlainText();
textItem->setPlainText("");
textItem->setPlainText(s);
textItem->setTextInteractionFlags(Qt::NoTextInteraction);
I dont like that, but it works.
Any hint for a cleaner solution?
Since QGraphicsTextItem::textCursor() returns a copy of the cursor, you have to set it back to the text item for it to have any effect.
QTextCursor cursor(textItem->textCursor());
cursor.clearSelection();
textItem->setTextCursor(cursor);
I'm writing a Silverlight+XNA game and when the user has something in their clipboard they can see less of the screen. I'd really like to be able to not show this clipbaord but I can't see any way (though it does seem to go away after some amount of time)
I've tried an empty string and Clipboard.SetText(null) but that throws an exception.
Unfortunately, there is no way to either clear the clipboard from code or influence the display of the SIP beyond setting an InputScope.
The best you can do for now is to update your design to allow for the amount of space which the SIP may use. :(
While more complicated, you could create your own text input keys as buttons, and instead of using a textbox, use buttons templated to look like textblocks, with background as you show above, and all... When the user taps the "button" that is a "textblock", you set a flag that says which textblock the keypad buttons send their numbers to.
Or, if the only spot you are sending inputs to (as it appears now that I look at your UI again), there is no need for the button template as the input space, or the flag. Just create buttons for user to tap for input, and send that input to the textblock that appears to be where your answer is. You could make the buttons whatever size you want, that way, as well, so you control how much of the screen is visible. Another thing you could do is make the buttons semi-transparent, so you could have even more background image showing.
Another thought - send the buttons all to the same event handler (except the backspace button), and have the code for that event handler look like this:
{
Button btn = sender as Button;
textblock.Text += btn.Content;
}