|
my project is base on unicode.
i am having a RichEdit control & i want to add unicoded strings on to it
with diffrent font ( BOLD, ITALIC,Diffrnt Font Size etc).
if anyone knows Please help me for it.
Thanks,
Swapnil.
|
|
|
|
|
|
Check out the EM_SETCHARFORMAT message. You can add the text to the control and use
EM_SETCHARFORMAT to alter its format.
Mark
|
|
|
|
|
Hi
All
I want to create Log file in my application to trap error messages in my application. So any body have code to do this, then plz forward me .
Thanks
Atool
Atool
|
|
|
|
|
|
i have writen the following function for open file its gives the selection for multiple files with ctrl+ but when i press ok it will gives folder name directly rather display the list of files in the listview control.
string Utility::GetFile(HWND hWnd)
{
try
{
OPENFILENAME ofn;
WCHAR file[MAX_PATH];
memset(file, 0, MAX_PATH);
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = _T("Media Files (*.wmv)\0*.wmv\0All Files (*.*)\0*.*\0\0");
ofn.lpstrFile = file;
ofn.nMaxFile = MAX_PATH;
<code>ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;</code>
ofn.lpstrDefExt = _T("wmv");
GetOpenFileName(&ofn);
char* tempFile = new char[wcslen(file) + 1];
WideCharToMultiByte(CP_ACP,0,file,-1,tempFile,MAX_PATH,NULL,NULL);
string fileName = tempFile;
if(tempFile != NULL)
{
delete[] tempFile;
tempFile = NULL;
}
return fileName;
}
catch(exception ex)
{
throw ex;
}
}
should i have some extra code for that?
Amit
|
|
|
|
|
amitmistry_petlad wrote: i press ok it will gives folder name directly rather display the list of files in the listview control.
This is what MSDN says:
If the OFN_ALLOWMULTISELECT flag is set and the user selects multiple files, the buffer contains the current directory followed by the file names of the selected files. For Explorer-style dialog boxes, the directory and file name strings are NULL separated, with an extra NULL character after the last file name.
|
|
|
|
|
If I remember correctly, each selection is returned in a single string and then has two null characters at the end. So you will need to read the first string as you have done, then set the pointer to the end of the string to get the next. Do this in a loop until the string is NULL, then you know you got them all.
|
|
|
|
|
yes that's i want.my logic is clear for that ,but the problem is in the file dialog the listed double qotted files in the ,how can i get because in filename string variable i can get the path name of the folder as per the given answer by Mr.Nibu babu thomas.
so if however i can get the list of files then i can do that way which you mention.
amit
|
|
|
|
|
It seems to me as if you havent' understood what WalderMort and Nibu said.
When you allow selecting a multitude of files in the file dialog, i.e. setting the OFN_ALLOWMULTISELECT flag, you should use ::FindFirstFile() / ::FindNextFile() if you're using the OPENFILENAME structure, or parse the string searching for NULL characters. If you're using CFileDialog then you should use CFileDialog::GetStartPosition() / CFileDialog::GetNextPathName() .
If you're unsure what this means, post the code where you're trying to retrieve the file names of the selected files and we can pin-point what you're doing wrong.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
ya now i understand !
thanks,
Amit
|
|
|
|
|
SHFILEINFO FileInfo1;
uploadedFile = util.GetFile(NULL);
the function Getfile is below
string Utility::GetFile(HWND hWnd)
{
try
{
OPENFILENAME ofn;
WCHAR file[MAX_PATH];
memset(file, 0, MAX_PATH);
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = _T("Media Files (*.wmv)\0*.wmv\0All Files (*.*)\0*.*\0\0");
ofn.lpstrFile = file;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;
ofn.lpstrDefExt = _T("wmv");
WIN32_FIND_DATA data;
GetOpenFileName(&ofn);
char* tempFile = new char[wcslen(file) + 1];
WideCharToMultiByte(CP_ACP,0,file,-1,tempFile,MAX_PATH,NULL,NULL);
string fileName = tempFile;
<code> HANDLE hFind=NULL;
while(fileName.c_str()!=NULL)
{
::FindNextFile(hFind,&data);
}
</code>
if(tempFile != NULL)
{
delete[] tempFile;
tempFile = NULL;
}
return fileName;
}
catch(exception ex)
{
throw ex;
}
}
i am tring to do the red code but i dont how get the handle of the open file dialog and how toget the string which is in that handle.
Amit
|
|
|
|
|
First of all you should really check the return value of ::GetOpenFileName() to see whether the operation was successful or not.
I think the easiest way to get the filenames of the selected files would be to parse the ofn.lpstrFile string.
Something like this:
if( ::GetOpenFileName( &ofn ) )
{
char* pFilename = ofn.lpstrFile;
while( *pFilename++ );
if( !*pFilename )
{
TRACE( "A single file was selected: %s\n", ofn.lpstrFile );
}
else
{
TRACE( "Multilpe files were selected:\n" );
while( *pFilename )
{
TRACE( "%s\\%s\n", ofn.lpstrFile, pFilename );
while( *pFilename++ );
}
}
}
You should be able to just copy/paste the snippet above.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
I have finding the such a same code from the MSDN.
is below.
<code>
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH];
DWORD dwError;
printf ("Target directory is %s.\n", argv[1]);
strncpy (DirSpec, argv[1], strlen(argv[1])+1);
strncat (DirSpec, "\\*", 3);
hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{
printf ("First file name is %s\n", FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData) != 0)
{
printf ("Next file name is %s\n", FindFileData.cFileName);
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
return (0);
i will follow your guidline.
thanks
Amit
|
|
|
|
|
its only give the current folder path not given the number of files.
thats why i am confused for last 4 hours .
its only give the current folder name path no number of files.
like
e.g.
D:\test\testfolder1(this is according Mr.Nibu babu thomas) it gives the current path,last folder in which the files stored.
i ask you one question when we open the file dialog and selecting multiple files we can select files
with ctr+ and dipslay it in the file name with double quotes like
File Name :<code>"x.wmv""y.wmv""z.wmv"</code> open
type:*.wmv
then it should come in the WIN32_FIND_DATA variable why it is not come ?
i have add D:\test\testfolder1\* in my sample but its not work.
amit
|
|
|
|
|
Haven't you tried the code I posted in my previous reply?
I thought you would since you said you would "follow my guideline"...
Use the code I sent. It parses the OPENFILENAME::lpstrFile string and it works. Just do whatever you have to do with the filenames at the TRACE locations in my code.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
ya I had try it.but when select number of files from the dialog and select ok . at that time
in (char*) ofn.lpstrFile; contain value c:\test\test1 no any files or serries of file name.when i debug it in pFileName it start with c then : the \ etc.. given the series of chars.
mean when i select it is not gives selected files but given the current folder in which selected files.
I follow your code and the above is result.i am also try with other one let see what happen???
Amit
|
|
|
|
|
amitmistry_petlad wrote: I follow your code and the above is result
Of course since the debug window only displays the contents of a string until it reaches the "terminating" NULL char. The data that is returned by ::GetOpenFileName() doesn't end there. Bring it up in the memory window and have a look at it there.
If you select multiple files in the open file dialog box, the OPENFILENAME::lpstrFile string will be built up in a similar way as you've built your filter string, as WalderMort told you earlier.
Set a breakpoint at the TRACE statement that looks like
TRACE( "%s\\%s\n", ofn.lpstrFile, pFilename ); in my code and debug it. When the execution stops at the breakpoint, have a look at the strings pointed to by both ofn.lpstrFile and pFilename . At this point ofn.lpstrFile points to a string containing the folder path and pFilename points to a string that contains the first filename that the user has selected. The TRACE call puts the parts together and print the complete file path in the debug window. On the next iteration ofn.lpstrFile still contains the folder path, but pFilename points to the second filename.
Just step through it while watching the variable contents and you'll get the picture.
I hope you have read this[^] MSDN article about the OPENFILENAME structure. In case you haven't, it's highly recommended.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
should i have to include trace.h header for tracing because it gives error Error 62 error C3861: 'TRACE': identifier not found d:\projects\drmclient\utils.cpp 43
how can i enable trace for my application.
|
|
|
|
|
I didn't know you were building without MFC.
No big deal, use ::OutputDebugString() instead, like this:
if( ::GetOpenFileName( &ofn ) )
{
char* pFilename = ofn.lpstrFile;
while( *pFilename++ );
if( !*pFilename )
{
std::string output = ofn.lpstrFile;
output += "\n";
::OutputDebugString( output.c_str() );
}
else
{
::OutputDebugString( "Multiple files were selected:\n" );
while( *pFilename )
{
std::string output = ofn.lpstrFile;
output += "\\";
output += pFilename;
output += "\n";
::OutputDebugString( output.c_str() );
while( *pFilename++ );
}
}
}
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
The output saying different. its give me ??????? question mark string only in the output window.
and i also put messagebox but didnt getting proper output.It dispaly sqarebox(like unicode char).
|
|
|
|
|
amitmistry_petlad wrote: It dispaly sqarebox(like unicode char)
That sounds like a unicode mixup and it looks as the reason is that you're using the datatype string which is a typedef of std::basic_string<char> . Use std::basic_string<WCHAR> instead.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
no its not given the file name which i have selected from dialog .its given the single character
of that path in the messagebox. when the path completed its terminate.
so ultimately i haven't found any selected file in the string output.
Amit
|
|
|
|
|
Run the application and break at the same location as I mentioned earlier, i.e. where the last TRACE used to be.
Bring up the memory window[^] and have it displaying the memory that surrounds the data for ofn.lpstrFile . What does it look like (write exactly how it looks)? Can you sense a pattern in the data?
I think you should also post how your code looks like at this point.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
as per our logn communication can you explain me one thing,
the output string give the path. its not finding any file after at the end of the path as in your code. is it really in buffer(files)? and if it is then why our control has directly switch over to the first selected file after current folder rather than traversing in the path string.
Amit
|
|
|
|