|
Hi,
How can I display an Open/Save File dialog (using CFileDialog) with the initial directory is 'My Computer'? I tried using SHGetSpecialFolderPath with param CSIDL_DRIVES, but the return string is _T(""), and the CFileDialog object seems not to understand an empty string in m_ofn.lpstrInitialDir. It ususally starts with the current directory.
Please help me do this little thing.
Thanks in advance.
|
|
|
|
|
use SHGetFolderPath instead
From the docs: "This function is a superset of SHGetSpecialFolderPath, included with earlier versions of the Shell. On systems preceeding those including Shell32.dll version 5.0 (Windows Millennium Edition (Windows Me) and Windows 2000), SHGetFolderPath was obtained through SHFolder.dll, distributed with Microsoft Internet Explorer 4.0 and later versions. SHFolder.dll always calls the current platform's version of this function. If that fails, it will try to simulate the appropriate behavior. SHFolder.dll continues to be included for backward compatibility, though the function is now implemented in Shell32.dll."
|
|
|
|
|
Thanks, but it appears that SHGetFolderPath doesn't work with param CSIDL_DRIVES. The return string is empty.
Sincerely,
|
|
|
|
|
what is the return value of SHGetFolderPath?
pszPath
[out] Pointer to a null-terminated string of length MAX_PATH which will receive the path. If an error occurs or S_FALSE is returned, this string will be empty.
Return Value
Returns standard HRESULT codes, including the following:
S_FALSE SHGetFolderPathA only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function.
E_FAIL SHGetFolderPathW only. The CSIDL in nFolder is valid, but the folder does not exist. Note that the failure code is different for the ANSI and Unicode versions of this function.
E_INVALIDARG The CSIDL in nFolder is not valid.
|
|
|
|
|
It returns none of them. It's 0x80070057. This is exactly how I use the function:
TCHAR szMyCompPath[MAX_PATH];<br />
int rc;<br />
rc = SHGetFolderPath(NULL, CSIDL_DRIVES, NULL, 0, szMyCompPath);
Do you have any ideas to set the initial directory of CFileDialog to "My Computer"? This is my ultimate goal.
Thanks in advance.
|
|
|
|
|
That error code means "The Parameter Is Incorrect"
In looking at your code, the second to last parameter is incorrect.
It should be:
dwFlags
[in] Flags to specify which path is to be returned. It is used for cases where the folder associated with a CSIDL may be moved or renamed by the user.
SHGFP_TYPE_CURRENT Return the folder's current path.
SHGFP_TYPE_DEFAULT Return the folder's default path. so change your code to read:
TCHAR szMyCompPath[MAX_PATH];<br />
HRESULT hr;<br />
hr = SHGetFolderPath(NULL, CSIDL_DRIVES, NULL, SHGFP_TYPE_CURRENT, szMyCompPath);
|
|
|
|
|
It doesn't help. Actually SHGFP_TYPE_CURRENT is defined 0.
Did you succeed in retrieving the "My Computer" path? What did the function return?
Sincerely,
|
|
|
|
|
hmm, I get the same results. I think the reason is that CSIDL_DRIVES does not have a real directory path. There must be a way of doing it, but I'm not sure what it is. The closest that I can suggest right now is to use CSIDL_DESKTOPDIRECTORY which does have a real path and it shows "My Computer" as an item in that "directory"
the only other suggestion I have is to hook the open file dialog and find the id of the "My computer" button and click it programmatically.
good luck.
|
|
|
|
|
here's some code that'll do what you want. paste it into a .cpp file and compile and run.
#define _WIN32_WINNT 0x0501
#define STRICT
#include <windows.h>
#include <shlobj.h>
#include <shfolder.h>
#include <tchar.h>
UINT_PTR __stdcall OpenFileHook(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if (msg == WM_NOTIFY)
{
HWND parent = ::GetParent(hwnd);
HWND tbctl = ::GetDlgItem(parent, ctl1);
LRESULT count = ::SendMessage(tbctl, TB_BUTTONCOUNT, 0, 0);
LRESULT result;
for (int button = 0; button < count; ++button)
{
TCHAR buttonText[1024];
TBBUTTON buttonData;
::ZeroMemory(buttonText, sizeof(buttonText));
::ZeroMemory(&buttonData, sizeof(buttonData));
result = ::SendMessage(tbctl, TB_GETBUTTON, (WPARAM)button, (LPARAM)&buttonData);
result = ::SendMessage(tbctl, TB_GETBUTTONTEXT, (WPARAM)buttonData.idCommand, (LPARAM)buttonText);
if (result != -1 && _tcscmp(_T("My Computer"), buttonText) == 0)
{
if (0 == ::SendMessage(tbctl, TB_ISBUTTONCHECKED, (WPARAM)buttonData.idCommand, 0))
{
RECT rect;
::ZeroMemory(&rect, 0);
::GetClientRect(tbctl, &rect);
::PostMessage(tbctl, WM_LBUTTONDOWN, (WPARAM)MK_LBUTTON, MAKELPARAM(10, (rect.bottom - rect.top)/count * button));
::PostMessage(tbctl, WM_LBUTTONUP, (WPARAM)MK_LBUTTON, MAKELPARAM(10, (rect.bottom - rect.top)/count * button));
}
}
}
}
return (UINT_PTR)FALSE;
}
void main()
{
TCHAR fileBuffer[MAX_PATH * 10];
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof ofn);
ZeroMemory(fileBuffer, sizeof fileBuffer);
ofn.lStructSize = sizeof ofn;
ofn.lpstrFile = fileBuffer;
ofn.nMaxFile = sizeof(fileBuffer)/sizeof(fileBuffer[0]);
ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK;
ofn.lpfnHook = OpenFileHook;
BOOL result = ::GetOpenFileName(&ofn);
}
hope this helps
-- modified at 12:40 Wednesday 14th December, 2005
had to fix the < and >
|
|
|
|
|
Thank you so much. Do we have another way instead of simulating mouse clicks?
Sincerely,
|
|
|
|
|
sorry, i tried, you'll have to take it from here.
|
|
|
|
|
I want to access the Read data from Screen Buffer and copy block data of the Buffer. Is it possible to achieve ? ... I want to read pixels but dont want to use the GDI functions ... Any help on it ?
Best Regards
|
|
|
|
|
Well you could use DirectX for this - I think DirectDraw has functions for something like this.
What are you trying to accomplish?
Do you want to render an image? Manipulate pixels?
If you want to manipulate pixels, you can do so in the WM_PAINT handler, get the HDC, create a new in memory DIB, manipulate the pixels of the DIB, and them bit blit this to your HDC, which will then be displayed on the screen.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
I dont want ti manipulate pixels. I mentioned I dont want to use GDI Functions. Are you sure DirectDraw has functions to read directly from Screen Buffer but is it fast enough ?
|
|
|
|
|
|
unescape ? you mean transforming things such as < into < ?
i believe that it is known in the CGI specifications, but not sure anymore...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
|
I didn't see your reply, saw that my question was incorrect and I found an answer.
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
Using the class "A set of ADO classes - version 2.20
By Carlos Antollini"
Trying to delete the current record set with the following code
if (pRs->IsOpen())
{
if (!pRs->IsEOF())
pRs->Delete();
}
the application craches with "unhandled exception in App.exe (kernel32.dll) 0xe06d7363:Microsodt C++ Exception.
What seems to be worng ?
sdancer
|
|
|
|
|
first put your code inside a try catch block:
<br />
try<br />
{<br />
}<br />
catch(_com_error &err)<br />
{<br />
AfxMessageBox(err.Description());<br />
}<br />
this will issue a message box with the error description returned by the ADO.Recordset object
no body can help you with this error with the information you supplied here!!
k_dehairy
|
|
|
|
|
thank you,
what more informations do you want to supply ?
Regards,
George
sdancer
|
|
|
|
|
The commands before Rs->IsOpen() is a Select query statement with outter Left join to other tables, and it works fine when i try to show them. It is just used in a ShowRecord Dialog with a Delete Button to delete the current record that is shown currently in the window objects. The MoveNext() & MovePrevious() buttons works just fine.
Regards,
George
sdancer
|
|
|
|
|
you still need to put your ADO code in a try .. catch blocks, just like what I pointed earlier.
then tell me what did the messagebox say.
generally speeking any code that deals with COM objects (like ADO) is better written inside try .. catch blocks.
k_dehairy
|
|
|
|
|
Trying the code you said, i receive the following error.
if (!pRs->IsEOF())
{
try
{
pRs->Delete();
}
catch(_com_error &err)
{
AfxMessageBox(err.Description());
return;
}
}
(I will make an english translation of the error code since i get it in Greeks)
"It was not possible to find the row for update.Its possible that some values have changed
since the last read."
What Seems to be the problem ? Below is the OnInitDialog() code and you can see the select query.
BOOL CBookProperties::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strSQL,strVal;
wchar_t buffer[20];
m_Sheet.AddPage (&m_SheetBasic);
m_Sheet.AddPage (&m_SheetDetails);
m_Sheet.AddPage (&m_SheetExtras);
m_Sheet.AddPage (&m_SheetPhoto);
m_Sheet.Create (this, WS_TABSTOP | WS_CHILD | WS_VISIBLE,WS_EX_CONTROLPARENT);
m_Sheet.SetWindowPos (NULL,0,100, 0,0,SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
//NEW Record
if (m_mode == NEW)
{
m_bNext.EnableWindow (FALSE);
m_bPrevious.EnableWindow (FALSE);
m_bPrint.EnableWindow (FALSE);
m_bDelete.EnableWindow (FALSE);
}
else
//EDIT VIEW Record
{
pAdoDb = new CADODatabase();
try
{
if (pAdoDb->Open(((CLibrarianApp*)AfxGetApp())->m_strConnection))
{
pRs = new CADORecordset(pAdoDb);
_ultow( m_lRecSQLCode, buffer, 10 );
//find the specific record
strSQL=_T("SELECT Books.*, Categories.CategoryDesc, Author1,PublishHouses.PublishHouseDesc ")
_T("FROM books LEFT OUTER JOIN Categories ")
_T("On Books.CategoryID=Categories.CategoryID LEFT OUTER JOIN PublishHouses ")
_T("On Books.CategoryID=PublishHouses.PublishHouseID ")
_T("WHERE BookID=") + CString(buffer) + " "
_T("ORDER BY title,author1,categoryDesc ASC");
if (pRs->Open(strSQL,CADORecordset::openQuery) )
{
SetRecordValues();
UpdateData(FALSE);
m_lAbsRecPosition=pRs->GetAbsolutePosition();
pRs->Close();
}
else
{
pRs->Close();
delete pRs;
}
//now set a global query to use with next & previous button
strSQL=_T("SELECT Books.*, Categories.CategoryDesc, Author1,PublishHouses.PublishHouseDesc ")
_T("FROM books LEFT OUTER JOIN Categories ")
_T("On Books.CategoryID=Categories.CategoryID LEFT OUTER JOIN PublishHouses ")
_T("On Books.CategoryID=PublishHouses.PublishHouseID ")
_T("ORDER BY title,author1,categoryDesc ASC");
if (pRs->Open(strSQL,CADORecordset::openQuery) )
{
pRs->SetAbsolutePosition (m_lAbsRecPosition);
}
else
{
pRs->Close();
delete pRs;
}
}
else
{
pAdoDb->Close();
delete pAdoDb;
}
}
catch (CADOException &e)
{
pRs->Close();
pAdoDb->Close();
delete pRs;
delete pAdoDb;
AfxMessageBox(_T("Data base error.");
m_bError=true;
m_bNext.EnableWindow (FALSE);
m_bPrevious.EnableWindow (FALSE);
m_bPrint.EnableWindow (FALSE);
m_bDelete.EnableWindow (FALSE);
m_bOk.EnableWindow (FALSE);
m_bUpdate.EnableWindow (FALSE);
m_bCreateNew.EnableWindow (FALSE);
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
sdancer
|
|
|
|
|
I found the error, It was the Outter Join from the query !
Regards,
sdancer75
|
|
|
|
|