|
I did something like this a few months ago. B was my main Dialog, so I just used AfxGetMainWnd in A to retrieve a Cwnd* which I casted on the B class, just as you do with the thread parameter. The result of the operation was that I had a pointer on the B class inside A, and I synchronized the whole with Critical_section, in order not to show in B data being changed simultaneously in A.
A naive question : is it not possible to put your A data in a struct, and post it through a user message to B (I have really no idea if this is possible or not )?
~RaGE();
|
|
|
|
|
Hi RaGE,
Thank you very much for your reply!
I want to try the first method, but would you please say that in more detail or give me an simple example project?
Best Regards,
chen
|
|
|
|
|
Declare
CRITICAL_SECTION m_cs;
int *m_myData;
as member variables in B.
In OnInitDialog of B :
InitializeCriticalSection(&m_cs);
So, in the thread A :
CWnd* pWnd=AfxGetMainWnd();
CMainDlg *pMainDlg=(CMainDlg*)pWnd;
... do some stuff ...
EnterCriticalSection(&pMainDlg->m_cs);
pMainDlg->m_myData[8]=22;
LeaveCriticalSection(&pMainDlg->m_cs);
And in the "show" section of B:
EnterCriticalSection(m_cs);
LeaveCriticalSection(m_cs);
So that's the start. You may have member variables in B which simply copies member variables of A just for display purposes. Of course, this is not a _good_ way to do multithreading, but i think that it is simple enough, and it works if the updating of data in the thread is not too time-critical.
If this doesn't work, you're going to use CEvent 's ...
~RaGE();
|
|
|
|
|
If all you need to do is transfer a numeric value, use InterlockedExchange() which allows you to set a LONG as an atomic operation. (See help for explanation of Interlocked calls--if you do multithreading you should understand these.)
|
|
|
|
|
dianazheng wrote:
// Get the current time
CTime curTime = CTime::GetCurrentTime();
//Get the current date
CTime curDate = CTime::GetCurrentTime();
What is the point of this ? Both these objects are the same.
dianazheng wrote:
//Display the current date
m_sDate = curDate.Format("%b / %d / %y");
// Display the current time
m_sTime = curDate.Format("%H:%M:%S");
MSDN does not document these methods, have you tried using GetMonth/GetYear/GetDay instead ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
// Display the current time
m_sTime = curDate.Format("%H:%M:%S");
MSDN does not document these methods, have you tried using GetMonth/GetYear/GetDay instead ?
Actually, I have this one in my MSDN, so I guess that's why dianzheng wrote that "it works for time". Anyway, Chris is right, GetMonth/Year/Day is the best way to do it.
~RaGE();
|
|
|
|
|
i have try the get month get day and get year but it still can't work that why i change it to tis way. Using this way i can get the time but i coulsn't get the date..
pls help....thanks
|
|
|
|
|
dianazheng wrote:
i have try the get month get day and get year
... ... What's wrong ? Could you post your code again ? I'll give it a try inbetween.
~RaGE();
|
|
|
|
|
Ok, this runs perfectly :
COleDateTime dTime;
dTime = COleDateTime::GetCurrentTime();
int d=dTime.GetDay();
int m=dTime.GetMonth();
int y=dTime.GetYear();
m_sDate.Format("%i / %i / %i",d,m,y);
~RaGE();
|
|
|
|
|
Really thanks for your help,i can display the date and time directly from the computer but now i have face with another problem hope you can help me also...Thanks
I have this two error
C:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\DLGDATA.CPP(170) : error C2065: '_countof' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\DLGDATA.CPP(181) : error C2065: 'AfxSetWindowText' : undeclared identifier
which i really don't know what are they but they come from the function below...Hope you can help...
AFX_STATIC void AFX_CDECL _Afx_DDX_TextWithFormat(CDataExchange* pDX, int nIDC,
LPCTSTR lpszFormat, UINT nIDPrompt, ...)
// only supports windows output formats - no floating point
{
va_list pData;
va_start(pData, nIDPrompt);
HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
TCHAR szT[32];
if (pDX->m_bSaveAndValidate)
{
// the following works for %d, %u, %ld, %lu
::GetWindowText(hWndCtrl, szT, _countof(szT));
if (!_AfxSimpleScanf(szT, lpszFormat, pData))
{
AfxMessageBox(nIDPrompt);
pDX->Fail(); // throws exception
}
}
else
{
wvsprintf(szT, lpszFormat, pData);
// does not support floating point numbers - see dlgfloat.cpp
AfxSetWindowText(hWndCtrl, szT);
}
va_end(pData);
}
|
|
|
|
|
I have a CStatic element on my dialog.
I use the following code to show different bitmaps:
<br />
myStatic.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)) );<br />
...<br />
myStatic.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP2)) );<br />
...<br />
myStatic.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3)) );<br />
One question: Must I call DeleteObject(...) when changing the bitmap or at the end of the dialog or does the CStatic this automaticly?
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I'd say the fact that SetBitmap returns the previous bitmap means you need to delete them
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Thanks Christian!
One question: When do you sleep?
When I take a look on the CP forums, there is no question you don't post an answer!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
What's sleep ? I have young children.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
You must free it...
<br />
HBITMAP hOld = myStatic.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)) );<br />
<br />
if (hOld)<br />
{<br />
DeleteObject(hOld);<br />
}<br />
Hope this helps...
|
|
|
|
|
Thanks!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Hello Folks,
I Have a problem of painting the border window that appears when a tool-bar is in floating state.
How can i achieve this ?. I tried by creating an object of CTOOLBAR derived class.,so there's no need of subclassing.
And in the MainFrame Class ,i processed the wm_paint message where i checked the myToolBarobj.isfloating() ..and performed the futher operation. .its working ... but what if i need to trap the paint message or I need to change the Wndproc ?
Pl help if any solution of any kind is availabe.
|
|
|
|
|
Hi,
Please tell me how to open browser in VC6.0..? I am displaying one url in my application I want that if I click that url it should open browser with the specified url...How to do that..Please help me.
Thanks in advance
|
|
|
|
|
ShellExecute a URL and the default browser will start.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
ShellExecute a URL and the default browser will start.
Exactly. If you need to handle your browser a little bit better, just use CreateProcess() . You may take a look at Mike's FAQ.
~RaGE();
|
|
|
|
|
ShellExecute worked...Thanks very much for the reply.
Prateeti
|
|
|
|
|
I want to draw on the ActiveX Control in Design Mode i.e
I placed a ActiveX control on the DialogBox, now i want to draw something on the control . How can i do this ?
Any help...
Thank you.
|
|
|
|
|
I think (not sure) it is not possible to draw on Antivex Control at design time. You can only draw on it after getting its Device Context through Coding.
|
|
|
|
|
Hi,
I'm unable to export a template class from an MFC based dll !
any ideas of how I can do it ?
Ciao
- Nilesh
|
|
|
|
|
Template classes are generated by their template arguments, they are in fact a little class factory. So I reckon you'll have trouble.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|