|
I think you will need to allocate the input text buffer before use.
<code>
char filename[256]; <font color=green>
object->m_ofn.lpstrFile = filename;
object->m_ofn.nMaxFile = 256;
..
</code>
I Dream of Absolute Zero
|
|
|
|
|
tasleem143 wrote:
CFileDialog *object=new CFileDialog(...);
It is not necessary to involve the memory manager for this. Just use a simple stack-based variable and you'll have one less potential problem to deal with.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
hi i m trying to select the multiple files through the file open dialog box for that purpose i used that code.
according to the MSDN to select multiple file the m_ofn.lpstrFile file ptr should pt to new buffer u had allocated. i had done that.
CFileDialog *object=new CFileDialog(TRUE,(LPCTSTR)"shp",NULL,OFN_ALLOWMULTISELECT,"Shape File |*.shp|",NULL);
char *filename;
object->m_ofn.lpstrFile= filename; // here it give the assertion.
object->m_ofn.nMaxFile=sizeof(filename);
if(object->DoModal()!= IDCANCEL)
MessageBox(object->m_ofn.lpstrFile,"ptr");
i want the file names that had been selected through file dialog. what to do.
ddd
|
|
|
|
|
Use the CFileDialog::GetStartPosition() / CFileDialog::GetNextPathName() functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cfiledialog.3a3a.getstartposition.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cfiledialog.3a3a.getnextpathname.asp
HTH
|
|
|
|
|
Hi All,
I have added Vertical Scroll bar to a Pop up dialog at design time.
However Scroll bar doesn't Scroll at run time.
I am adding controls to the dialog at run time.
As Control gets added and dialog size goes beyond screen size I am not able to scroll down and view the controls.
Kindly advise on this.
thanks
Sanjay
|
|
|
|
|
The builtin dialog handling does not support scrolling; you will need to scroll the dialog yourself. Look at the dialog section here on Code Project for ideas on how to do that.
Software Zen: delete this;
|
|
|
|
|
Is it possible to use Groups with a virtual list control?
The following line never results evaluates to true, which means I guess that the group id is not being requested?
if(pItem->mask & LVIF_GROUPID)
I am changing an exsiting list control that work in Non-Virtual mode and the groups work great, so I guess I am adding the group correctly.
How would I go about configuring the list control to request the Group ID / info.
Any ideas?
Cheers
AndyC
|
|
|
|
|
I want to use the assignement operator to get data from (CArray) that has items of type (CStringArray):
------------------------------------------------------------------------
CArray <cmstringarray,cmstringarray&> MyList;
CStringArray strArrMyStrArray1;
CStringArray strArrMyStrArray2;
strArrMyStrArray1.Add(TEXT("String11");
strArrMyStrArray1.Add(TEXT("String12");
strArrMyStrArray2.Add(TEXT("String21");
strArrMyStrArray2.Add(TEXT("String22");
MyList.Add(strArrMyStrArray1);
MyList.Add(strArrMyStrArray2);
/////////////////////////////////////////////////
CStringArray strArrMyOUTPUTStrArray;
strArrMyOUTPUTStrArray = MyList.GetAt(1); /// ERROR CStringArray doesn't support (operator = )
-----------------------------------------------------------------------
so; I inhereted the CStringArray (new class CMStringArray) and overladed the (=) operator:
-----------------------------------------------------------------------
CMStringArray& CMStringArray:perator= (const CMStringArray& InputArray)
{
int iCounter;
for( iCounter=0; iCounter
|
|
|
|
|
Dear All,
Can anybody let me know how to kill the running process (WINDOWS SDK)???
I am using the TerminateProcess() functionin which it requires the Handle of the process...How do I get the handle of process ??? Let me tell U,I am not getting the required Output by GetHandle() method...
Thanks in advance.
Supriya Tonape
|
|
|
|
|
Supriya Tonape wrote:
Can anybody let me know how to kill the running process
If you know the Name Of Window that Will Be Faily very Easy to kill that Window/Process.
First By Using FindWindow(...) find the handle of the Window then you can use WM_QUIT/WM_CLOSE message to close that window.
No need to use TerminateProcess in this case
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks Alok!
But I didnt get why do I need to find window when I already wanted to kill the process of specific name.
Anyways but I got the solution, I did it using 'CreateToolhelp32Snapshot()' as it will return handle for snap shot of all running processes in system n further using 'Process32First()' and 'Process32Next()'
Anyways but thanks again for trying to help me.
Regards,
Supriya Tonape
|
|
|
|
|
Supriya Tonape wrote:
Anyways but I got the solution, I did it using 'CreateToolhelp32Snapshot()' as it will return handle for snap shot of all running processes in system n further using 'Process32First()' and 'Process32Next()'
Yeah you solution is very Nice! . you can try my way tooo.. here is a small example to enumerate all the visible window present on desktop!:-
http://alok.bizhat.com/site/tipandtrick.php?tiptype=2&tipid=30#30[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Supriya Tonape wrote:
How do I get the handle of process ???
How about EnumProcesses() , or the Process32First() /Process32Next() pair?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks to U too David.bye
Supriya
|
|
|
|
|
if you know the executable location, you can use this function:
<br />
bool CMyclass::CloseApplication(CString sFilename)<br />
{<br />
HANDLE hProcessSnap = NULL;<br />
PROCESSENTRY32 pe32 = {NULL};<br />
CString sCompare, sTemp;<br />
CString sProcesm_sFilename =
#if (_MFC_VER < 0x0700)<br />
sProcesm_sFilename.MakeLower();<br />
#else<br />
CString sLowerTemp;<br />
sLowerTemp = sProcesm_sFilename;<br />
sProcesm_sFilename = sLowerTemp.MakeLower();<br />
#endif<br />
<br />
hProcessSnap = CreateToolhelp32Snapshot <br />
(TH32CS_SNAPPROCESS, 0);<br />
<br />
pe32.dwSize = sizeof(PROCESSENTRY32);<br />
if (Process32First(hProcessSnap, &pe32))<br />
{<br />
do<br />
{<br />
sCompare.Format("%s", pe32.szExeFile);<br />
<br />
#if (_MFC_VER < 0x0700)<br />
sCompare.MakeLower();<br />
#else<br />
CString sLowerTemp;<br />
sLowerTemp = sCompare;<br />
sCompare = sLowerTemp.MakeLower();<br />
#endif<br />
<br />
if (sCompare == sProcesm_sFilename)<br />
{<br />
HANDLE hProcess = OpenProcess<br />
(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);<br />
<br />
DWORD exCode;<br />
GetExitCodeProcess(hProcess, &exCode);<br />
TerminateProcess(hProcess, exCode);<br />
}<br />
} while (Process32Next(hProcessSnap, &pe32));<br />
}<br />
else<br />
{<br />
return false;<br />
}<br />
<br />
return true;<br />
}<br />
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
|
thank U Geert but I got late to read Ur soln but did in same manner after R&D.bye
Supriya
|
|
|
|
|
Does anyone know of a way of measuring/graphing how much Video RAM has been allocated? Is there a (freeware) utilitity to do that?
Joel Holdsworth
|
|
|
|
|
We have REALLY tried to find this out, and apparently there is no known API for determining such information.
|
|
|
|
|
i am writing a code for playing an mp3 file.i will first read 2mb from the file and it will put in to a buffer and then i will play it.then the next 2mb will read and so on.but there is an almost 1 second delay after each 2mb.what will be the problem. this is my code
void CMP3PLAYERDlg::OnPlay()
{
m_Video=NULL;
if(m_Video==NULL)
{
m_Video = MCIWndCreate(this->GetSafeHwnd(),
AfxGetInstanceHandle(),
WS_CHILD |MCIWNDF_NOMENU|MCIWNDF_SHOWNAME,m_Path);
m_Play.EnableWindow(FALSE);
//CMP3PLAYERDlg pNewObject = new CMP3PLAYERDlg;
AfxBeginThread(MyThreadProc, this);
}
Pause = FALSE;
}
UINT MyThreadProc( LPVOID pParam )
{
CMP3PLAYERDlg* pObject = (CMP3PLAYERDlg*)pParam;
CMediaType mt;
mt.majortype = MEDIATYPE_Stream;
mt.subtype = MEDIASUBTYPE_MPEG1Audio;
DWORD dwKBPerSec =INFINITE;
HANDLE hFile = CreateFile(pObject->m_Path,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox("Could not open "+ pObject->m_Path);
}
ULARGE_INTEGER uliSize;
uliSize.LowPart = GetFileSize(hFile, &uliSize.HighPart);
read=uliSize.LowPart;
uliSize.LowPart=2000000;
PBYTE pbMem = new BYTE[uliSize.LowPart];
if (pbMem == NULL)
{
AfxMessageBox("Could not allocate %d bytes", uliSize.LowPart);
}
do
{
if(read<ulisize.lowpart)
{
="" ulisize.lowpart="read;
" read+="2000000;
" pbyte="" pbmem="new" byte[ulisize.lowpart];
="" }
="" bool="" h="ReadFile(hFile,(LPVOID)pbMem,uliSize.LowPart,&dwBytesRead,NULL)" ;
="" if="" (!h)
="" afxmessagebox("could="" not="" read="" file");
="" closehandle(hfile);
="" break;
=""
="" hresult="" hr="S_OK;
" coinitialize(null);
=""
="" cmemstream="" stream(pbmem,="" (longlong)ulisize.quadpart,="" dwkbpersec);
="" cmemreader="" *rdr="new" cmemreader(&stream,="" &mt,="" &hr);
="" (failed(hr)="" ||="" rdr="=" null)
="" delete="" rdr;
="" create="" filter="" 0x%8.8x",="" hr);
="" couninitialize();
="" rdr-="">AddRef();
hr = CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC,
IID_IFilterGraph,
(void **)&pFG);
if(hr!=0)
{
AfxMessageBox("cannot create instance");
}
hr = pFG->AddFilter(rdr, NULL);
IGraphBuilder *pBuilder;
hr = (pFG)->QueryInterface(IID_IGraphBuilder, (void **)&pBuilder);
pin=rdr->GetPin(0);
int n=rdr->GetPinCount();
hr = pBuilder->Render(pin);
pBuilder->Release();
hr = pFG->QueryInterface(IID_IMediaControl, (void **)&pMC);
hr = pFG->QueryInterface(IID_IMediaEvent, (void **)&pME);
OAEVENT oEvent;
hr = pME->GetEventHandle(&oEvent);
hr = pMC->Run();
if (SUCCEEDED(hr))
{
LONG levCode;
hr = pME->WaitForCompletion(INFINITE, &levCode);
read-=2000000;
}
rdr->Release();
}while(dwBytesRead!=read);
pMC->Release();
pME->Release();
if (pFG)
{
ULONG ulRelease = pFG->Release();
if (ulRelease != 0)
{
AfxMessageBox("Filter graph count not 0! was %d", ulRelease);
}
}
CloseHandle(hFile);
CoUninitialize();
pObject->m_Play.EnableWindow(TRUE);
return TRUE;
}
please give me an elaborate answer.
sebin
|
|
|
|
|
I'm writing a simple flat file database MFC SDI application. However after i save n close the file, i cant open it again and shows 'unexpected file format'.
below is my serialize funcation for the new class, the sequence is correct. What other problem can it be?
void CPerson::Serialize(CArchive &ar)
{
CObject::Serialize(ar);
if (ar.IsStoring())
ar << m_sName << m_sRoom << m_iSex << m_iStatus;
else
ar >> m_sName >> m_sRoom >> m_iSex >> m_iStatus;
}
|
|
|
|
|
What are the data types for the member variables and if you open file were the contents saved as expected ?
Do a test with CString variables to make a test file if you are uncertain about what should happen when storing.
Elaine
The tigress is here
|
|
|
|
|
Problem solved, there's nothing wrong with the code. actually i have another similar application, it's because the save-filetype (fdb) for both applications are the same, so when i save using the second application, the window uses my first application to open and resulting in 'unexpected file format'.
|
|
|
|
|
|
Hello Friends
I have an application in which I need to start one exe from another one and at the end when the first one ends, it should automatically end the second one.
To start I use ShellExecute() or WinExec() function. And to terminate the another exe I put code into the destructor of the first one from where I have started it. But the problem is I don't know the Handle of the new exe that I have started using ShellExecute() or WinEec().....
Is there any functions which can give me the Handle of a perticular window or is there any other way to stop the application without knowing the handle or process id ?
Thankx in advance
My Code Looks Like :
-------------------
My first.exe file
================
MyClass()
{
// Do some work here........
WinExec("C:\\Temp\\second.exe",SW_SHOW);
// Do some work here...
};
~MyClass()
{
Here I want to kill(Terminate) the second.exe
}
Any help plz ?
Thankx
}
}
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
You could use CreateProcess() and TerminateProcess(), however TerminateProcess() ends a program so abruptly that some applications don't handle it well, it doesn't give them time to save their settings or other exit code. I'd recommend using FindWindowEx() and sending a WM_CLOSE to the main window.
|
|
|
|