Win32 API :
ChooseFont() - Display Font Dialog
ChooseColor() - Display color dialog
GetOpenFileName() -Display File dialog
Learnt today...:
1.Added the file dialog to the Image Source Filter
1.Before creating an instance of the filter, we must prompt the user for selecting the file from File Dialog...
2.So i displayed the File Dialog before the filter's CreateInstance() fn...
3.Initialize the filter intsance in constructor initialization like
CMySourceStream::CMySourceStream(HRESULT* phr,CSourceFilter* pFilter,LPCWSTR pPinName):CSourceStream(NAME("SourceStream"),phr,pFilter,pPinName),
m_pFilter((CSourceFilter*)pFilter)
{
}
if we initialized the filter instance like this, I faced the problem that the filter instance is already locked ...
So use the above approach...
CMySourceStream::CMySourceStream(HRESULT* phr,CSourceFilter* pFilter,LPCWSTR pPinName):CSourceStream(NAME("SourceStream"),phr,pFilter,pPinName)
{
m_pFilter = (CSourceFilter*)pFilter;)
}
4.Display the file dialog...
OPENFILENAME ofn;
char szFileName[MAX_PATH]="";
char *szFile;
szFile = new char[260];
int i =0,j = 0;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
ofn.hwndOwner = ::GetActiveWindow();
ofn.lpstrFilter = "Bitmap(*.bmp)\0*.bmp\0jpg Files (*.jpg)\0*.jpg\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "bmp";
if(GetOpenFileName(&ofn)) //Displays file dialog...
{
// Do something useful with the filename stored in szFileName
//if(szFileName))
//OutputDebugString(szFileName);
while(szFileName[i] != NULL)
{
szFile[j] = szFileName[i];
if (szFileName[i] == '\\')
{
j= j+1;
szFile[j] = '\\';
}
i = i + 1;
j = j + 1;
}
szFile[i + 1] = NULL;
OutputDebugString(szFile);
return szFile;
}
else
{
return NULL;
}
}
if we are not assigned the data
char szFileName[MAX_PATH]="";
ofn.lpstrFile = szFileName;
the szFileName must be assigned some blank values otherwise the file dialog will not be shown
on the screen...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment