How to get dragged text position MFC - c++

I'm trying to insert tag next to specific text.
I was get a knowhow to insert tag next to text..
It is to use Setsel() and ReplaceSel().
example,
char str = "< name >";
m_richedit.Setsel( position of start dragging of text, end position )
m_richedit.ReplaceSel( str, TRUE )
but, I don't know how to get position of start dragging of text in richEdit.
Is there anybody who has an idea?
Thank you.

You need to add the appropriate accelerator key like they explain here: Adding accelerators(shortcuts) in MFC - HOW? . Then in the handler of the accelerator key, use GetSelText, add your tags to the string you get and call ReplaceSel.

Related

Adding a string into CEdit Text box instead of CCombobox

I currently have a combobox which displays a list of numbers which are retrieved elsewhere and stored into the variable "test". Every time another number is set for "test", that number will be added into the combobox list.
Is there a way where I can use a CEdit text box instead of a CComboBox to display my numbers?
This is how I have coded the combobox.
CComboBox *pCombobox = (CComboBox *) (GetDlgItem(IDC_ComboBox));
strNumber.Format(_T("%d"),test);
pCombobox->AddString(strNumber);
Any help would be appreciated. Thank you.
Presuming you have an appropriate edit control placed on your dialog with ID IDC_Edit for example, then get the existing string, append the new value to it, replace with new string.
CString text;
GetDlgItemText(IDC_Text, text);
if (text.IsEmpty())
text.Format(_T("%d"), test);
else
text.AppendFormat(_T(",%d"), test);
SetDlgItemText(IDC_Text, text);

strings in a list not properly being added to an empty string

Im making a calculator program, and I'm currently trying to get the user's input into a string. I was able to create a list based on the buttons they pressed. So if they pressed 5, the string would be '5', and if they pressed 8 after, it would be '58', etc. So for each time the person presses the button, I have that number added to a list, so in the last example the list would be ['5','8']. Im trying to get those into a string together, '58', but am having issues.
from Tkinter import *
root=Tk()
root.geometry('300x500')
root.configure(bg="gray")
root.title("Calculator")
typed_num=[]
def button_command(number):
typed_num.append(str(number))
string_num=''
for val in typed_num:
string_num+=typed_num
print string_num
startx=20
starty=60
one_button=Button(root, text="1", command=lambda:button_command(1), highlightbackground='gray').place(x=startx, y=starty)
two_button=Button(root, text="2", command=lambda:button_command(2), highlightbackground='gray').place(x=startx+60, y=starty)
three_button=Button(root, text="3", command=lambda:button_command(3), highlightbackground='gray').place(x=startx+120, y=starty)
four_button=Button(root, text="4", command=lambda:button_command(4), highlightbackground='gray').place(x=startx, y=starty+60)
five_button=Button(root, text="5", command=lambda:button_command(5), highlightbackground='gray').place(x=startx+60, y=starty+60)
six_button=Button(root, text="6", command=lambda:button_command(6), highlightbackground='gray').place(x=startx+120, y=starty+60)
seven_button=Button(root, text="7", command=lambda:button_command(7), highlightbackground='gray').place(x=startx, y=starty+120)
eight_button=Button(root, text="8", command=lambda:button_command(8), highlightbackground='gray').place(x=startx+60, y=starty+120)
nine_button=Button(root, text="9", command=lambda:button_command(9), highlightbackground='gray').place(x=startx+120, y=starty+120)
zero_button=Button(root, text="0", command=lambda:button_command(0), highlightbackground='gray').place(x=startx+60, y=starty+180)
root.mainloop()
Any and all help is greatly appreciated! The error returned is:TypeError: cannot concatenate 'str' and 'list' objects
You are attempting this concatenation here: string_num+=typed_num. You can use append if you want to add an item to list such as typed_num.append(string_num). You tried to add a list to a string, you can add a string to a list however. "+" can be also used but the other way around
The problem is caused because you want to add a list with a string, that operation is not possible, I think you want to do is concatenate for them you must change:
string_num+=typed_num
to
string_num+=val
A simple way to concatenate a string list is to join, for this it changes:
string_num=''
for val in typed_num:
string_num+=typed_num
print string_num
to:
print "".join(typed_num)

EditBox Text Alignment using Cocos2d-x 3.2

I am using CCEditBox in the latest cocos2d-x 3.2 as textBox for user input.
now , i want to align text which i am typing in Textbox area , but it's always stays left align. i want to set it in the Center of my textBox.
I tried one Function named : setLabelAnchorPoint but it's not giving any effect to my label alignment. please help.
cocos2d::extension::Scale9Sprite *Playername_bgtemp = cocos2d::extension::Scale9Sprite::create("Name_bg.png");
auto _editName = EditBox::create(Size(1000,164), Playername_bgtemp);
Point absolutePosition = Point(ReferenceFrameSprite->getContentSize().width/2,4*ReferenceFrameSprite->getContentSize().height*0.20);
_editName->setPosition(absolutePosition);
_editName->setFontName("fonts/HelveticaLTStd-Cond_0.ttf");
_editName->setFontColor(Color3B::WHITE);
_editName->setLabelAnchorPoint(Vec2(0.0f,0.0f));
_editName->setPlaceHolder(" Name ");
_editName->setPlaceholderFontColor(Color3B::WHITE);
_editName->setPlaceholderFontName("fonts/HelveticaLTStd-Cond_0.ttf");
_editName->setMaxLength(10);
_editName->setReturnType(EditBox::KeyboardReturnType::DONE);
_editName->setFontSize(BgContentFontSize);
_editName->setDelegate(this);
bgFrameSprite->addChild(_editName,PopUpTag);
I did the trick with a text Label in the same position than the Editbox. I keep the Editbox with an empty string.
When start editing the edit box:
Hide the label.
Set the Editbox text with the label content.
When end editing the Editbox:
Set label text to Editbox content.
Show the label.
Set Editbox text to an empty string.

Why can't I add these two strings together?

on oneButtonClicked_(sender)
set faceNumber's setStringValue() to faceNumber's stringValue() & "1"
end oneButtonClicked_
I get this error: "Can’t make «class ocid» id «data optr000000000058B37BFF7F0000» into type list, record or text. (error -1700)"
faceNumber is a label and when the user clicks the button, I want to add string of "1" to it. So for example, if the user clicked the button 5 times
stringValue returns an NSString(wrong answer) CFString. You have to make a real AppleScript String to use it.
BTW your code set faceNumber's setStringValue() is not correct. The reasons are:
The Cocoa handlers are always using the underscore.
If you use the setter setStringValue() you don't need to use set x to
If you want to use setStringValue() you must give the parameter between the parentheses
Now put everything together:
on oneButtonClicked_(sender)
faceNumber's setStringValue_((faceNumber's stringValue) as string & "1")
end oneButtonClicked_
or (to have it clearer):
on oneButtonClicked_(sender)
tell faceNumber
set currentValue to (its stringValue) as string
setStringValue_(currentValue & "1")
end tell
end oneButtonClicked_
I hope you like the answer, after pressing the button twice you have an 11 at the end of the label.
Cheers, Michael / Hamburg

Qt Text Edit with a fixed number of input lines

I have a Qt "Text Edit" widget in my Gui and this widget is used to log something.
I add every line(s) this way:
QString str;
str = ...
widget.textEdit_console->append(str);
by this way the Text Edit height will increase more and more after each new line.
I want it act like a terminal in this case, I mean after some number (that I set) of lines entered, for each new line the first line of Text Edit being deleted to prevent it being too big!
should I use a counter with every new line entered and delete the first ones after counter reached it's top or there is better way that do this automatically after
widget.textEdit_console->append(str);
called ?
thank cmannett85 for your advise but for some reason I prefer 'Text Edit',
I solved my problem this way:
void mainWindow::appendLog(const QString &str)
{
LogLines++;
if (LogLines > maxLogLines)
{
QTextCursor tc = widget.textEdit_console->textCursor();
tc.movePosition(QTextCursor::Start);
tc.select(QTextCursor::LineUnderCursor);
tc.removeSelectedText(); // this remove whole first line but not that '\n'
tc.deleteChar(); // this way the first line will completely being removed
LogLines--;
}
widget.textEdit_console->append(str);
}
I still don't know is there any better more optimized way while using 'Text Edit'
One simple way is to turn the vertical scroll-bar off:
textEdit_console->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
This code move cursor to the first line and then select it until end of line, next it will delete the line:
widget.textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
widget.textEdit->moveCursor(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
widget.textEdit->textCursor().deleteChar();
widget.textEdit->textCursor().deleteChar();