|
Hello,
I have this piece of code which i am using in my application developed on VS2003. i have migrated the code to VS2005 and have cleaned the code, but now i have to port it to Vista.
The code uses SHFILEOPSTRUCT and SHFileOperation which are nwo deprecated and a new interface IFileOperation has been introduced for Vista. I did a lot of head banging but still i could not figure out how to modify my code except the use of SetOperationFlag() function of IFileOperation. So please see if you could help.
Here are the snippets
<br />
SHFILEOPSTRUCT shfileop;<br />
<br />
shfileop.hwnd = NULL;<br />
<br />
shfileop.wFunc = FO_DELETE;<br />
<br />
shfileop.pFrom = pstrfrom;<br />
<br />
shfileop.pTo = NULL;<br />
<br />
shfileop.fFlags = FOF_NOCONFIRMATION;<br />
<br />
shfileop.fAnyOperationsAborted = 0;<br />
<br />
shfileop.hNameMappings = 0;<br />
<br />
shfileop.lpszProgressTitle = 0;<br />
<br />
SHFileOperation(&shfileop);
I get the pFrom and pTo from LPCTSTR type strings. I would also like to know about the double null termination of strings.
Thanks and regards,
Mustanseer
|
|
|
|
|
What does your code snippet have to do with using SetOperationFlag() or IFileOperation ?
Mustanseer M S wrote: The code uses SHFILEOPSTRUCT and SHFileOperation which are nwo deprecated...
But it should still work.
Mustanseer M S wrote: SHFileOperation(&shfileop);
What does this return?
Mustanseer M S wrote: I get the pFrom and pTo from LPCTSTR type strings.
Are they double-null terminated?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Davis,
The code presented above was the one being used by me till i had my application compatible with XP or earlier. For Vista and later releases of Windows it is recommended to use IFileOperation interface instead of SHFileOperation(). That is why i want to replace SHFileOperation with IFileInterface.
As for the strings i am not sure whether they are double null terminated or not as i get them from a third party renderer. but i could double null terminate them using string maipulations if possible.
Any other suggestion will be welcomed.
Thank you for the trouble.
Regards,
Mustanseer
|
|
|
|
|
Mustanseer M S wrote: That is why i want to replace SHFileOperation with IFileInterface.
Ok, so what have you tried so far, and what results are you seeing?
Mustanseer M S wrote: As for the strings i am not sure whether they are double null terminated or not...
SHFileOperation() will not work otherwise.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
I got this code from a MSDN newsgroup
<a href="http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.vc.mfc&mid=eccb8144-68e3-4cc8-8457-73725d857019">http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.vc.mfc&mid=eccb8144-68e3-4cc8-8457-73725d857019</a>[<a href="http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.vc.mfc&mid=eccb8144-68e3-4cc8-8457-73725d857019" target="_blank" title="New Window">^</a>]
<code>//=======================================================================
//
// Deletes a file given its name (with full path).
//
// Uses new Vista IFileOperation COM interface
// (works in both ANSI/MBCS and Unicode builds, thanks to internal
// string conversion).
//
// Check HRESULT return value to see if operation was successful
// (SUCCEEDED( DeleteFile(...) )).
//
//=======================================================================
HRESULT DeleteFileWithIFO( LPCTSTR szFilename )
{
//
// Check input parameter
//
ASSERT( szFilename != NULL );
if ( szFilename == NULL )
return E_POINTER;
//
// Convert from TCHAR to wchar_t
// because IFileOperation::DeleteItem works only
// with Unicode UTF-16 strings.
//
CT2W wszFileToDelete( szFilename );
//
// Initialize COM engine
//
HRESULT hr = CoInitializeEx(NULL,
COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
//
// Create COM instance of IFileOperation
//
IFileOperation *pfo = NULL;
hr = CoCreateInstance(CLSID_FileOperation, NULL,
CLSCTX_ALL, IID_PPV_ARGS(&pfo));
if (SUCCEEDED(hr))
{
//
// Set parameters for current operation
//
hr = pfo->SetOperationFlags(
FOF_SILENT | // do not display progress dialog-box
FOF_NOERRORUI // do not display error message to the user
);
if (SUCCEEDED(hr))
{
//
// Create IShellItem instance associated to file to delete
//
IShellItem *psiFileToDelete = NULL;
hr = SHCreateItemFromParsingName(
wszFileToDelete, NULL,
IID_PPV_ARGS(&psiFileToDelete));
if (SUCCEEDED(hr))
{
//
// Declare this shell item (file) to be deleted
//
hr = pfo->DeleteItem( psiFileToDelete, NULL );
}
// Cleanup file-to-delete shell item
psiFileToDelete->Release();
psiFileToDelete = NULL;
}
if (SUCCEEDED(hr))
{
//
// Perform the deleting operation
//
hr = pfo->PerformOperations();
}
}
// Cleanup file operation object
pfo->Release();
pfo = NULL;
}
//
// Cleanup COM
//
CoUninitialize();
//
// Return operation result
//
return hr;
}</code>
|
|
|
|
|
Hi, do you know how to delete multiple files at once? Thank you!
|
|
|
|
|
Hi,
what is the difference between MF_BYPOSITION and MF_BYCOMMAND in DeleteMenu() function of CMenu class.I have problem with MF_BYCOMMAND is not working properly.
|
|
|
|
|
From MSDN [^]:
MF_BYCOMMAND
Identifies menu item position by command.
[...]
MF_BYPOSITION
Identifies menu item position by zero-based relative position.
[...]
i.e. if you need to access the menu via its ID (like, for instance, IDM_EXIT ) then you have to specify MF_BYCOMMAND . Viceversa, if you want to specify the menu item via its position inside the menu then use MF_BYPOSITION )
Is it clear enough?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
I created a file in append mode using CreateFile();.But if I reopen the file add add string to it, it is appending from the starting of the file.
But it should be added from the end of the file.
What is wrong?
|
|
|
|
|
can u send ur code...so that i can get clearly.
Born to win...!
|
|
|
|
|
AFAIK CreateFile has no 'append' option: you have to go to the end of the file
(via SetFilePointer ) after opening it correctly for append (i.e. depending on your needs, with OPEN_ALWAYS or OPEN_EXISTING as dwCreationDisposition parameter) and start writing there.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Do you need to CFile::Seek?
|
|
|
|
|
Yes, he does
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I think yes,Hi Nelek how are you.
|
|
|
|
|
Fine thanks, a bit away of VC++ but trying not to forget :P I changed job and city.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I guess maybe you forgot me.
|
|
|
|
|
No, I just forgot to check messages contents from forums notices , just saved all and now that I had time... I have made clean up answering and keeping the ones I consider to be kept.
It was a long time without coming to forums :P
I will get more often so... see you in the posts
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I create a list box as a popup window with parent as NONE and display it below a combo box. (This is imitation of intellisearch IE or IAutoComplete in WTL)
The creation of the listbox looks like this
<br />
CMyComboBox::CreateListbox() {<br />
BOOL bRet = _list.CreateEx(0, <br />
_T("ComboLBox"), <br />
_T(""), <br />
WS_POPUP | WS_VISIBLE | WS_BORDER | WS_VSCROLL <br />
| LBS_NOTIFY,<br />
clientRect.left, clientRect.top, <br />
clientRect.Width(), clientRect.Height(), <br />
this->GetSafeHwnd(),
NULL, <br />
NULL);<br />
}<br />
I display this listbox when user starts typing some text in the combobox. I add the filtered strings as per the text to this listbox.
There are two problems
1. I am trapping all the messages send to Listbox in its windowproc.
I find that the first time I display this listbox, I am able to see LBN_SELCHANGE (or other listbox specific messages) being trapped in Windowproc. But they are sent only once. The next time when I try to change any selection, LBN_SELCHANGE is not sent/trapped (I don't know where this message goes).
Although the basic messages - LBUTTON_DOWN/UP, KEY_DOWN/UP are being sent to the Listbox.
I intend to write something like below, but LBN_SELCHANGE is caught only once.
<br />
LRESULT CAutoCompListBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
<br />
switch(message) {<br />
case LBN_SELCHANGE: {<br />
}break; <br />
Does the question make sense? or its too vague?
2. I need to find a decent way to send the listbox messages to the combobox. Since the combobox is not at all related to Listbox here, I may have to resort to registering a callback in the Listbox to handle the messages. Is there any other way to handle the messages?
Thanks first of all for reading the question.
Many many thanks if you got some answers
Evil triumphs when good people sit quiet...
|
|
|
|
|
misha_grewal wrote: LRESULT CAutoCompListBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case LBN_SELCHANGE: {
[LBN_SELCHANGE^] is a notification message sent through WM_COMMAND message. Correct it and check, later we discuss for the decent way.
misha_grewal wrote: But they are sent only once
Actually you caught the WM_CREATE ( == 1 == LBN_SELCHANGE) message which is send only once.
modified on Monday, April 28, 2008 10:35 AM
|
|
|
|
|
Thanks a ton..
Rajkumar R wrote: Actually you caught the WM_CREATE ( == 1 == LBN_SELCHANGE) message which is send only once.
Yes, I think thats what I was catching..
The windowproc of the list box is getting all the WM messages like WM_KEYDOWN or LBUTTONUP. But a message like LBN_SELCHANGE is never caught in windowproc. why is it so?
WM_COMMAND is sent to a parent of a window and the wparam has the message id. In this case, the list box doesn't have any parent as such, so you never receive WM_COMMAND messages
Evil triumphs when good people sit quiet...
|
|
|
|
|
misha_grewal wrote: the list box doesn't have any parent as such
ComboBox is the parent which you already set in CreateEx and get Notified since you set WM_NOTIFY, Any way since you are using MFC use ON_CONTROL_REFLECT to get the notification to the ListBox itself, Add handler to ListBox class to allow wizard to put ON_CONTROL_REFLECT macros.
modified on Tuesday, April 29, 2008 5:00 AM
|
|
|
|
|
can anybody tell me where a static variable get stored in memory
Thanks in advance
|
|
|
|
|
The static variables are stored in the .data section of the corresponding module.
|
|
|
|
|
Hi at all,
is there a possibility to look which code is behind the function ::SetFocus(m_hWndFocus) ?
Because even i set the m_hWndFocus to a given control, Focus will not set on this control,
it changes to another control on the view ...
Big thanks for help
Greetings
|
|
|
|
|
I don't think you can see code of WinAPI functions. In any case I can assure you that there is no bug in that function and looking at code of SetFocus is not going to help you fix your problem. Maybe if you share how exactly are you using SetFocus then someone can help you find the problem.
-Saurabh
|
|
|
|