|
Are you sure the second thread is the GUI one? Maybe post some code.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I would have done so right away, but the code is at work. I admit to being a thread virgin - are you saying only one thread can be responsible for my GUI ? The main thread is doing all my GUI at the moment, except initially my dialog was happening in my second thread ( well, supposedly, nothing happened and the program froze ). The way our thread class works, I am certain that when it froze I was trying to run the dialog in the second thread. Now I am not, but either way when the second thread tries to access a HWND in any way, it freezes until the main thread kills the HWND.
I guess that's not much help, I should post some code tomorrow.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
are you saying only one thread can be responsible for my GUI ?
Absolutely not. But there are two flavours of threads - the worker threads without message queues, windows and such, and GUI threads with message queue. Probably you invoke your thread with AfxBeginThread, do you pass address of some function or RUNTIME_CLASS as 1st param?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
It's created with _beginthreadex, the app does not use MFC. I did not write the thread class, someone else stole my Richter book and wrote it.
He seemed to think when I asked that there was no difference between GUI and worker threads, which I thought was wrong but accepted as he has at least written this thing. I'll go to bed now and readu p on it, I think.
Thanks - I'll post some code tomorrow if I'm still stuck.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
So probably you'll have to add a message queue to the second thread.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi,
Okay, this is what I think you need to do. I don't have access to MSDN or anything as I'm not at home at the minute so if you need any more help just let me know.
I would suggest using an event (CEvent). You'd create an instance of a class which controls the progress dialog before the process begins. Then, the constructor would create a new thread. The first part of the thread function would create an event which has a timeout value as required. THen, it would wait on the event. When the even times out the dialog is created. You could have a flag which would cancel the process so that the dialog won't appear unless necessary.
Hope that helps!
--
Andrew.
|
|
|
|
|
Thanks for the advice, but unfortunately we are not using MFC.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
You don't need to be using MFC - Windows provides a series of functions which are wrapped by the CEvent class in MFC. Look up the following in MSDN for more info;
1. CreateEvent(...)
2. SetEvent(...)
3. ResetEvent(...)
4. WaitForSingleObject(...)
5. CloseHandle(...)
6. DuplicateHandle(...)
Hope this is useful - I think the idea should work anyway.
--
Andrew.
|
|
|
|
|
Cool - this looks VERY promising. I'll have a play at work this morning.
Thank you
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Thanks so much - I got this working like a treat and learned a bit of stuff in the process. Can't ask for more than that...
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Glad to be of help - cheers !
--
Andrew
|
|
|
|
|
I don't want to pass the CFtpConnection* pointer to a thread proc because that may be dangerous. Although I can get the handle of the FTP connection from the (HINTERNET) operation, I cannot construct a CFtpConnection object from the handle I've got because there's no such function. What should I do? Please help me out.
Thanks in advance.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
I don't know anything about these classes, but I've decided to look into your problem as it appears to be more of a C++ issue than anything else.
The MFC header file for CFtpConnection shows that the class has a couple of constructors. The one you would probably use looks like this:
CFtpConnection(CInternetSession* pSession, HINTERNET hConnected, LPCTSTR pstrServer, DWORD dwContext);
Again, I don't know anything about these parameters but the second one looks like the one you'd be passing from the other thread. If this doesn't work I'd suggest you to derive a class from CFtpConnection. Since m_hConnection is protected in CInternetConnection, you'd have access to it in your derived class.
Good luck!
Alvaro
|
|
|
|
|
Thank you very much!
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Hi,
I'm trying to get my MDI app to use splitter windows:
My ChildFrame class is called CDesignFrame:
I removed the CView derived member and added a CSplitterWnd member instead.
I overrode the CDesignFrame::OnCreateClient and added this:
m_splitWnd.CreateStatic(this,
2,
1,
WS_CHILD | WS_VISIBLE,
AFX_IDW_PANE_FIRST);
SIZE sInitSize;
sInitSize.cx = lpcs->cx;
sInitSize.cy = lpcs->cy / 2;
m_splitWnd.CreateView(0,
0,
RUNTIME_CLASS(CDesignView),
sInitSize,
pContext);
m_splitWnd.CreateView(1,
0,
RUNTIME_CLASS(CDesignView),
sInitSize,
pContext);
CDesignView is simply the default AppWizard created view class. it doesn't do anything yet. All i did to it was declare and implement dyncreate on it.
Anyway. All compiles nicely, but when i run it, clicking file|new causes app to crash with an unhandled exception: Traceing through the app step by step shows the error comes from the CMDIFrameWnd::CreateNewChild function, when it calls pFrame->InitialUpdateFrame(NULL, TRUE);
The docs for InititalUpdateFrame say it'll update all views in the frame window. but there are none. but if i remove this function call, my frame isn't displayed.
I'm a bit lost. How should I do this?
Jon
|
|
|
|
|
|
I finally figured it out... Because I disabled the Doc/View architecture support in appwizard, My CView derived class was in fact CWnd derived.
Part of the InitialUpdateFrame function casts this CWnd Pointer to a CView, and then calls a member function which plainly doesnt exist. This causes the exception.
Nice to have it sorted.
Thanks again
|
|
|
|
|
There are normally three buttons on the right most upper corner of a window
1) Minimize
2) Small / Large
3) Close (cross)
I want to add another button adjacent to these three buttons (supposedly .) that will minimize the application to task bar (adjacent to clock)
How can I possibly add this button?
Maliha
|
|
|
|
|
You'll have to handle WM_NCPAINT. Have a look at Jan'97 issue of MSJ, C++ Q&A column - it has a code that draws custom caption bar. The article should be in the 'Periodicals' section of VC++ help.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
how to list efficiently TIDs (or handles) of all threads
running within a specified process ?
Thanx in advance
Michal Januszczyk
|
|
|
|
|
There's no method that will work on all 32-bit Windows versions. On 9x and 2000 you can use ToolHelp32's Thread32First/Thread32Next. On NT4 you'll have to get perf data with PdhEnumObjects.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I had written a dialog based application.
It contained a button named "Try"
When I clicked the "Try" button,opened an other
dialog named "Test" which contained a button named "Open".
When I first clicked "Open" button and clicked the "OK"
button in Open File Dialog,everything is ok,and then
close the "Test" Dialog.
But When I click "Try" button again,it showed me wrong.
Who can please tell me what's wrong with my code??
******************************************************************
void CFirstDlg::OnButtonTry()
{
// TODO: Add your control notification handler code here
CTestDialog* dlg;
dlg=new CTestDialog;
dlg->DoModal();
}
******************************************************************
BOOL CTestDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString sCon;
_ConnectionPtr m_pCon;
_RecordsetPtr m_pRs;
sCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=main.mdb";
CoInitialize (NULL);
HRESULT hr=S_OK;
try
{
hr=m_pCon.CreateInstance(__uuidof(Connection));
if(FAILED(m_pCon->Open(_bstr_t(sCon),"","",adModeUnknown)))
AfxMessageBox("Can not open the database!");
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Failed!\r\nError Message:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
m_pRs.CreateInstance("ADODB.Recordset");
if(FAILED(m_pRs->Open("SELECT * FROM employeer",_variant_t((IDispatch*)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText)))
AfxMessageBox("Can not open the record set!");
if((m_pRs->State & adStateOpen) == adStateOpen)
m_pRs->Close();
if ( (m_pCon->State & adStateOpen) == adStateOpen)
m_pCon->Close();
CoUninitialize();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
***********************************************************************
void CTestDialog::OnButtonOpen()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[]="Bitmap Files (*.bmp)|*.bmp||";
CFileDialog *fd;
fd=new CFileDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,this);
if(IDOK!=fd->DoModal())
return;
else
AfxMessageBox(fd->GetFileName());
delete fd;
}
|
|
|
|
|
You didn't delete the dlg object in the CFirstDialog::OnButtonTry(). That should be the problem. Why do you want to use the heap object rather than stack object? If you do it like this:
void CFirstDialog::OnButtonTry()
{
CTestDialog dlg;
dlg.DoModal();
}
you won't be worried about the work of releasing object. I think this form is better.;)
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
The wrong still happened,what should I do?
|
|
|
|
|
So could you send your piece of codes to me? I think looking into the codes will be more clear.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|