|
LOL, thanks for pointing that out! I just copied the save stuff over from the open function, so I didn't notice...;P
And now I have a new problem...how do you associate a file extension with a particular program?!
|
|
|
|
|
I hope ur using an sdi/mdi application. You can find the option in the appwizard itself. How ever you can set the file associate later by following the below steps.
Suppose in the case of SDI application if you take the string table, you can find one entry with ID IDR_MAINFRAME.If my application name is MyApp, the string may look like
MyApp\n\nMyApp\n\n\nMyApp.Document\nMyApp Document. If you want to associate the file type say ".xyz", modify the string as follows
MyApp\n\nMyApp\nMyApp Files (*.xyz)\n.MyApp\nMyApp.Document\nMyApp Document. Also call the function RegisterShellFileTypes(TRUE); in the Initinstance just after the creation of the template.
|
|
|
|
|
hxhl95 wrote: ...but if the user just enters foo and selects .txt extension from the dropdown, I cannot seem to get the extension
Because NULL was used as the second argument to the CFileDialog constructor.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am not using MFC; just pure win32 at the moment. Is there something like a font dialog box? If there is then how to I call it and set my font after disposing the dialog...?
|
|
|
|
|
Use the ChooseFont() API to show the common font chooser dialog.
|
|
|
|
|
Font Dialog Box[^]
CreateFontIndirect() can be used to create a font from the LOGFONT obtained with the dialog.
For setting a control's font there's WM_SETFONT.
SelectObject() can select a font into a device context.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi, i wrote a mfc dialog that's running a worker thread i want to terminate it from outside.
in CMyTestDlg: public CDialog{
static bool STOP;//a shared variable to signal the thread function
static UINT __cdecl Start();
CWinThread* pThread
....
in the cpp file, i have a OnBnClickedButtonStart() and OnBnClickedButtonStop()function to start and stop the thread
bool CMyTestDlg::Stop=false;
void CMyTestDlg::OnBnClickedButtonStart(){
pThread=AfxBeginThread(Start,this,-1,0,CREATE_SUSPENDED);
pThread->m_bAutoDelete=FALSE;
pThread->ResumeThread();
}
void CMyTestDlg::OnBnClickedButtonStop()
{
STOP=true;
if(::WaitForSingleObject(pThread->m_hThread,2000)==WAIT_OBJECT_0){
delete pThread;
m_ListBox_MSG.AddString(_T("Thread terminated succesfully"));
//message showed in a list box
}
else{
::TerminateThread(pThread->m_hThread,0);
m_ListBox_MSG.AddString(_T("Thread is not normally terminated!"));
//message showed in a list box
}
}
UINT __cdecl CMyTestDlg::Start(LPVOID pParam){
CMyTestDlg* me=(CMyTestDlg*)pParam;
while(STOP==false){
//looping here...
}
return 0;
}
when i stop the thread, from the message showed in the listbox, i found that the thread is always terminated "dangeroursly" which means the ::TerminateThread()function ran.
What could be the possible cause?
|
|
|
|
|
What happens if you wait longer?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i tried for 10s, still doesn't terminate properly.
the looping is fairly simple, should take that long
|
|
|
|
|
another thing,in the thread function, i add the msg to listbox before return
UINT __cdecl CMyTestDlg::Start(LPVOID pParam){
CMyTestDlg* me=(CMyTestDlg*)pParam;
while(STOP==false){
//looping here...
}
me->m_ListBox_MSG.AddString(_T("ERROR!"));
return 0;
}
if the thread is terminated properly, this msg should show, how ever it didn't, this possibly means that the loop didn't exit...what's wrong?
|
|
|
|
|
How about setting the wait time to INFINITE and putting a breakpoint at the end of the thread proc
(maybe on the "return 0;").
Does the breakpoint ever get hit? If not, why?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
just tried your suggestion, the "return 0" never get hit, and dialog is stuck ,something weird is going on here
|
|
|
|
|
Mark Salsbery wrote: What happens if you wait longer?
They call your number and you pick up your Filet-O-Fish
|
|
|
|
|
lol,seriously, i think my thread loop didn't exit even i made STOp=true; what's going here?
|
|
|
|
|
alberthyc wrote: what's going here?
Sadly the same thing that goes on here everyday
|
|
|
|
|
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am guessing that you might have to make your STOP boolean a volatile.
I am guessing that the compiler has optimised it out of the while condition because it is not changed by the thread.
|
|
|
|
|
|
try...
//in header
volatile long m_iLock;
//global on top of cpp file
static volatile long *piLock;
//in OnBnClickedButtonStart
m_iLock =1;
piLock = &m_iLock;
AfxBeginThread(...
in the thread..
while(InterlockedCompareExchange(piLock,1,1))
{
//work
}
AfxMessageBox("Ending"...
And change m_bAutoDelete to true.
Tell me the results.
-Randor
|
|
|
|
|
sorry, what does this do??
|
|
|
|
|
I don't really use CWinThread but using my own thread class this works
class TestThread : public base_w32thread
{
private:
bool _brun;
protected:
virtual void run()
{
while(_brun)
{
TRACE("Thread is running\r\n");
Sleep(2000);
}
}
public:
void stop()
{
_brun = false;
}
};
// from the CMainDlg.h class declaration
protected:
HICON m_hIcon;
TestThread _thread;
// from the CMainDlg.cpp implementation
void CMainDlg::OnBnClickedButtonstart()
{
_thread.start();
}
void CMainDlg::OnBnClickedButtonstop()
{
_thread.stop();
if( WAIT_OBJECT_0 == ::WaitForSingleObject( _thread, 3000))
AfxMessageBox(_T("Thread exited"));
else
AfxMessageBox(_T("This did not happen"));
}
|
|
|
|
|
|
Mark Salsbery wrote: I had a filet-o-fish for lunch!
The down side to my adaptation is I don't think I could eat one now
|
|
|
|
|
interesting.....
if i really can't get the thread working, i'll try this method
|
|
|
|
|
I tried your code in a simple dialog project and it works.
In your original post you state that it is looping with no explanation as to what it is doing.
I put an intensive processor loop in there and tried and got a termination using the TerminateThread which is what you describe.
Because your WaitSingleObject specifies that you should only wait 2 seconds for the object to be signalled, it may be because your thread function is not terminating within 2 seconds it is returning a WAIT_TIMEOUT and as you only check for a WAIT_OBJECT_0 you assume that something has failed which is incorrect.
All that has happened in effect is the you got tired of waiting for it to complete and decide to kill it prematurely by incorrectly assuming that something must be wrong.
If your thread is not being signalled within the 2 seconds you specify I would assume that the problem lies in your thread function in that it takes too long to complete each pass through the while loop.
However without knowing what goes on in the loop it would be difficult to provide further guidance.
|
|
|
|