MFC displaying multiple-lines of text in Edit Control box - visual-c++

I am trying to implement a tool that displays file names.
I would like to do this by using SetWindowText() method.
However, When I was trying to use this method in a loop,
the text is displayed in one line and it is continuously refreshed.
here is code snippet
for (int i = 0; i<10; i++)
{
SetWindowText(filenames);
}
please help.! thanks.

SetWindowText replaces the current window text with the string you provide.
So, if you want to show multiple lines with it, you first have to create a multi-line string.
A quick example:
CStringArray names;
// Fill names
CString str;
for (INT_PTR i = 0; i < names.GetCount() ; ++i)
{
str += names[i] + _T("\r\n");
}
c_MyEdit.SetWindowText(str);

Another time-tested method of showing multiple names at once is the list box. MFC provides a nice wrapper with the CListBox Class (see http://msdn.microsoft.com/en-us/library/y04ez4c9%28v=vs.80%29.aspx). This has the added benefit of being scrollable and (optionally) sortable if the list is long.

Related

Using composed xpath to locate an element and click on it

I am trying to retrieve a list of elements using XPATH and from this list I want to retrieve a child element based on classname and click it.
var rowList = XPATH1 + className;
var titleList = className + innerHTMLofChildElement;
for(var i = 0; i < titleList.length; i++) {
if(titleList[i][0] === title) {
browser.click(titleList[i][0]); //I don't know what to do inside the click function
}
}
I had a similar implementation perhaps to what you are trying to do, however my implementation is perhaps more complex due to using CSS selectors rather than XPath. I'm certain this is not optimized, and can most likely be improved upon.
This uses the methods elementIdText() and elementIdClick() from WebdriverIO to work with the "Text Values" of the Web JSON Elements and then click the intended Element after matching what you're looking for.
http://webdriver.io/api/protocol/elementIdText.html
http://webdriver.io/api/protocol/elementIdClick.html
Step 1 - Find all your potential elements you want to work with:
// Elements Query to return Elements matching Selector (titles) as JSON Web Elements.
// Also `browser.elements('<selector>')`
titles = browser.$$('<XPath or CSS selector>')
Step 2 - Cycle through the Elements stripping out the InnerHTML or Text Values and pushing it into a separate Array:
// Create an Array of Titles
var titlesTextArray = [];
titles.forEach(function(elem) {
// Push all found element's Text values (titles) to the titlesTextArray
titlesTextArray.push(browser.elementIdText(elem.value.ELEMENT))
})
Step 3 - Cycle through the Array of Title Texts Values to find what you're looking for. Use elementIdClick() function to click your desired value:
//Loop through the titleTexts array looking for matching text to the desired title.
for (var i = 0; i < titleTextsArray.length; i++) {
if (titleTextsArray[i].value === title) {
// Found a match - Click the corresponding element that
// it belongs to that was found above in the Titles
browser.elementIdClick(titles[i].value.ELEMENT)
}
}
I wrapped all of this into a function in which i provided the intended Text (in your case a particular title) I wanted to search for. Hope this helps!
I don't know node.js, but in Java you should achieve your goal by:
titleList[i].findElementBy(By.className("classToFind"))
assuming titleList[i] is an element on list you want to get child elements from

How to override the textbox content in CSWPFAutoCompleteTextBox

I am using the autocomplete textbox from this MSDN link.
Question:
CSWPFAutoCompleteTextBox has property "AutoSuggestionList" which I bound this to observable string collection. Each string is made of id + description. When user selects an item from dropdown, how can I override the texbox content? I want to manipulate the text box content.
This is a textbox that extends a wpf combobox to make it searchable.
When the user types in a string in the textbox, it displays matching strings as a dropdown, user selects an item and the item is displayed in the textbox.
the question is how to override the textbox contents of this control.
Without actual format of your code it is hard to answer precisely, but for example, if your strings are
string[] suggestions = {"0: Yes", "1: No", "666: whatever"}
Then you could get the number by something like
sugestedString.Substring(0, sugestedString.IndexOf(':'));
EDIT: I misunderstood the question. So if I now understands correctly, you might do it with
for(int i = 0; i < suggestions.Length; i++) {
if(suggestions[i] == selectedString) {
return i;
}
}
If you seek only a number within your list of all possible suggestions.
If you seek a number within narrowed-down suggestions, it gets somewhat more difficult.
You firstly need to note down what user has typed so-far (e.g. "Aut"). Then you need what he actually selected (e.g. "Automotive"). With those things, you can then search all your possible suggestions, count how many of them satisfies the user-typed beginning and finaly which of them is the selected one. It might look like this:
int counter=0;
for(int i = 0; i < suggestions.Length; i++) {
if( suggestions[i].StartsWith(typedString)) {
counter++;
if(suggestions[i] == selectedString) {
counter;
}
}
}

document.createTextNode not working :/

So i am making this program where i need to create an ordered list with lots of list elements inside. This is the code:
for(i = 0; i < numbers.length; i++) {
document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(document.createElement("ls"));
}
It only creates the list elements, it doesn't put the text nodes anywhere in the html document. :/
Does anyone know why this happens and how to fix it? Would really help me out.
Instead of adding the "ls" element you've created on the first row to the "list" element, you're creating a new (empty) one and adding it.
Change it to:
var ls = document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(ls);

CMFCTabCtrl get handle of tabs and their childs

I have a properly initialized object of CMFCTabCtrl in my application.
I have added some tabs to it by
m_oMTC.AddTab(pTab, Name, -1, FALSE);
now I want to iterate over over all tabs in m_oMTC, get tabs handle and check some of it's child item. How can i do this?
I used this code for iterating
int nTabCnt = m_oMTC->GetTabsNum();
for (int i = 0; i < nTabCnt; i++)
{
m_oMTC->SetActiveTab(i);
}
CMCFTabCtrl is derived from CMFCBaseTabCtrl. You should be using CMFCBaseTabCtrl::GetTabWnd to iterate through the child tabs within your loop. Depending on how you've set up the tabs, you may need to enumerate the child CWnds on the returned CWnd from GetTabWnd.

Is there a way to change the text of checked/unchecked MCheckBox states?

How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?
Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.
Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171
Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.

Resources