CFileDialog truncates offered file name - c++

I have strange behaviour of CFileDialog once it is opened. The offered file name looks like it has been truncated, so that only last n characters are visible:
image http://ves.fijmovi.com/cpp/CFileDialog_1.jpg
As soon as I click on space for name, I get to see the whole file name:
image http://ves.fijmovi.com/cpp/CFileDialog_2.jpg
So it is not truly truncated, just the beginning position of shown string is not from the start.
The complete file name is in this case 36 characters long and part of the string which I get upon opening of dialog is from the 21st character to the last. I tested with some other files which are longer and they also appear truncated, but not from the 21st character, but some other one. I don't see any sense in this.
This piece of code has been several years old:
// Ask user for name and location of the ZIP
CString OfferName = DEFAULT_ZIPFILE_NAME;
CString File_Mask = GetString (IDS_ZIP_SELECT);
CFileDialog fileDlg (TRUE, _T("zip"), OfferName,
OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_ENABLESIZING,
File_Mask, pStateThread->GetThreadWindow());
CString strTitleName = GetString (IDS_ARCHIVE_CAPTION);
fileDlg.m_ofn.lpstrTitle = strTitleName;
CString Default_Dir = pConfig->GetTricUserKey (_T("TricSupportDir"));
fileDlg.m_ofn.lpstrInitialDir = Default_Dir;
if (fileDlg.DoModal () != IDOK) {
//..
}
Should I use some special flag for m_ofn? I've read article on MSN about OPENFILENAME structure but I see nothing worth adding to existing flags.
Any thoughts on what might be going on?

It happens in all software for me that uses the open file dialog. I think it's just a peculiarity of recent-ish incarnations of that dialog.

Related

Get a text from CHtmlEditView

I am using CHtmlEditView class for my edit control. I want to get text written in the edit control. GetWindowText() returns an empty string. Not sure its supported but not giving me any warning either. I tried IHTMLDocument2 interface to get a text. I am getting a text but in html format (text written in <body>). So I am not sure how to get text only from CHtmlEditView control. I have gone through list of APIs of CHtmlEditView and its base classes but I did not get anything there. Can any one know how to get a text from CHtmlEditView ?
IHTMLElement::innerText
Sets or retrieves the text between the start and end tags of the
object.
Example:
CHtmlEditView html_edit;
// or CHtmlEditCtrl html_edit;
...
CString getPlainText()
{
CComPtr<IHTMLDocument2> doc2;
html_edit.GetDHtmlDocument(&doc2);
CComPtr<IHTMLElement> element;
doc2->get_body(&element);
CComBSTR bstr;
element->get_innerText(&bstr);
CString text = bstr;
return text;
}

How to convert CEdit type of data in to CString type data and how to display that in a messagebox? [duplicate]

This question already has answers here:
Read text from edit control in MFC and VS2010
(3 answers)
Closed 7 years ago.
I would like to know how the data from CEdit(Entered by user) is displayed on Message box.
I would like to accept input from user and need to display it in a messagebox.Simple but i'm not able to convert CEdit type(input by user) to CString type(Which i have to display in Messagebox).
Here is my Code Snippet
In .h file
CEdit* pEdit = new CEdit;
CString text;
In .cpp file
pEdit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CRect(150, 10, 500, 50), this, 1);
pEdit.GetWindowText(text);
As you have created Textbox programatically.
EDIT:
Declare CEdit in header file
CEdit* pEdit;
Write this code in OnInitdialog() function
pEdit = new CEdit;
pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,CRect(150, 10, 500, 50), this, 1);
Now on click of any button you can show messagebox. For example
OnButtonOk()
{
CString strText;
pEdit->GetWindowText(strText);
AfxMessageBox(strText);
}
The documentation for CEdit clearly states:
To set and retrieve text from a CEdit object, use the CWnd member functions SetWindowText and GetWindowText, which set or get the entire contents of an edit control, even if it is a multiline control.
So given your creation of the CEdit object,
CString strOut;
pEdit->GetWindowText(strOut);
CWnd::GetWindowText
There are two methodes do that.
You can bind your edit control to a CString variable. when you want get text data, call UpdateData(TRUE) and the CString variable stored the text stirng data.
Also it can work as below:
CString textStr;
CEdit* pEdit = new CEdit;
//call when you want get text
pEdit ->GetWindowText(textStr);

How to display the file path in Entry widget in windows path format

I have written a Tkinter program in which the Browse button is used to select a file and the selected file's complete path gets displayed in the Entry widget. But my problem is, it's displaying the path with 'forward'(/) slashes instead of the conventional windows format of 'backward'(\) slashes. This is strange for me since I'm working on windows os.
Why this occurs ? Is there any before hand fix for this, instead of replace string option ?
my code:
def selectfile():
fileName = askopenfilename(parent=root, title='Choose a file', initialdir='C:\\')
custName.set(fileName) #Populate the text field with the selected file
#create the 'filepath' field
custName = StringVar(None)
filepath = Entry(root, width ='50', textvariable=custName).pack(anchor=W)
#Create the 'Browse' button
browseButton = Button(root, text="Browse", relief = 'raised', width=8, command=selectfile, cursor='hand2').place(x=325,y=16)
Expected Output in Entry widget:
c:\data\file.txt
Actual Output in Entry widget:
c:/data/file.txt
You can always use replace() to replace "/" with "\" for string. Here's link with docs about replace() method:
https://docs.python.org/2/library/string.html?highlight=replace#string.replace
This is workaround fix. Try looking more deeply inside Tkinter's docs for actual answer why this occurs.

Adding formatting to rich edit controls using win32 api

I am creating a rich edit text box like so:
const char *testText = "Hello \\bworld!";
LoadLibrary("riched20.dll");
hwndoutbox = CreateWindowEx(
ES_SUNKEN,
RICHEDIT_CLASS,
testText,
WS_BORDER | WS_VISIBLE | WS_CHILD,
0, 40, 300, 300,
hwnd, 0, hInstance, NULL);
The intended result is to display 'Hello World' with the 'World' in bold.
What am I doing wrong?
I have a hunch that \b might be an escape code for something, but i cant find much info to back that up
You need to go and have a look at the specification for RTF. For a start, RTF data has a header, and you aren't including that.
In fact, Wikipedia's page on RTF (here) might have been a good place for you to start. It includes this example text:
{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard
This is some {\b bold} text.\par
}
... which is a string with a bold word.
The "rich edit control" is a control designed to render RTF.

How to display Red Squiggly Lines in CRichEditCtrl in MFC

I am working on implementing spellchecker in an MFC application. What I want to do is display red lines under incorrectly spelled words.
I found one example where it is done but it works only for a simple edit box because it can simply use the edit controls default font for doing calculations to draw the squiggly lines. But it does not work for a rich edit control as in rich edit control it is possible that different words can have different fonts. In this case the example I found draws lines at incorrect places.
Please let me know if someone has already done this for CRichEditCtrl? (it must handle text of any font/size that is present in the rich edit control.)
Thanks,
Sachin
CHARFORMAT2 format;
SecureZeroMemory(&format, sizeof(CHARFORMAT2));
format.cbSize = sizeof(CHARFORMAT2);
format.dwMask = CFM_UNDERLINE|CFM_UNDERLINETYPE;
format.dwEffects = CFE_UNDERLINE;
format.bUnderlineType = CFU_UNDERLINEWAVE | 0x50;
SendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format);
I hope this will get the underline in your text
Use the EM_SETCHARFORMAT message:
CHARFORMAT2 format;
SecureZeroMemory(&format, sizeof(CHARFORMAT2));
format.cbSize = sizeof(CHARFORMAT2);
format.dwMask = CFM_UNDERLINE|CFM_UNDERLINETYPE;
format.dwEffects = CFE_UNDERLINE;
format.bUnderlineType = CFU_UNDERLINE
window->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
window->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);