|
Hi all,
I am making a multi threaded application in which i have made a UI thread and from that thread i m using SendMessage() function to send a message to be displayed like this.
int row_no = test_int;
m_pLogWnd->SendMessage(MSGDIS, (WPARAM)(CString*)&logmsg,(LPARAM)(&row_no));
and recieving that message in my main class function like this..
LRESULT CMonitorVw::OnDispMessage(WPARAM wparam, LPARAM lparam)
{
CString* pLogMessage = (CString*) wparam;
int *u = (int*)lparam;
m_obj->m_List.SetItemText(u,7,*pLogMessage);
return UpdateData(FALSE);
}
<\pre>
if i do this i am getting an error
SetItemText' : cannot convert parameter 1 from 'int *' to 'int'
either tell me the way to convert int to int* or in any other way i pass or recieve inter value.
Thanks in advance
|
|
|
|
|
neha.agarwal27 wrote: m_obj->m_List.SetItemText(u,7,*pLogMessage);
change it as
m_obj->m_List.SetItemText(*u,7,*pLogMessage);
|
|
|
|
|
Actually you don't to pass an integer pointer, you may pass directly the integer value:
m_pLogWnd->SendMessage(MSGDIS, (WPARAM)(CString*)&logmsg,(LPARAM)row_no);
and
LRESULT CMonitorVw::OnDispMessage(WPARAM wparam, LPARAM lparam)
{
CString* pLogMessage = (CString*) wparam;
int u = (int)lparam;
m_obj->m_List.SetItemText(u,7,*pLogMessage);
return UpdateData(FALSE);
}
BTW usually pointers are passed only as LPARAM (though maybe an issue only on very old Windows versions).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Others have answered the details of your questions, but I wanted to make an observation.
When passing pointers between threads, you need to make sure that the item being pointed to (logmsg and row_no) will remain in existence during the time the receiving thread is processing the message. In general, this means that you should not pass pointers to items allocated on the stack i.e. variables that are local to the function sending the message. Your code is ok in this respect because you use SendMessage instead of PostMessage. However, using SendMessage tends to defeat the purpose of multi-threading by forcing the two threads to act sequentially.
Judy
|
|
|
|
|
Im Create a static control inorder to use it as a label
CStatic *temp = new CStatic();
temp->Create("YYYYY" ,SS_SIMPLE ,CRect(0,0,25,25) ,this);
My requirement is if my text which should display inside static control
exceeds the rectangle limits it should take a new line automatically.
It Must be multiline static control.
so how can i do it.
bhw
|
|
|
|
|
Use MultiLine Edit Control and make it readonly.
|
|
|
|
|
|
In the read only edit box how to stop the blinking |.
bhw
|
|
|
|
|
Don't let it have the input focus.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi ereryone,
I need a multithreaded downloading module for my project in vc++.net now.
Would you like give me the code about it? Or give me some advice to do this.
Thanks a lot!
|
|
|
|
|
I subclassed a control (actually, a CStatic) and want to access from it's functions some data members of the parent.
Let's say the new class of the control is CMyOwnCtl, and the parent, the main dialog, is CMyOwnDlg.
I am defining a pointer to the parent in CMyOwnCtl.h:
CMyOwnDlg *Parent;
This works only with
#include "CMyOwnDlg.h"
#include "CMyOwnCtl.h"
in this sequence. However, CMyOwnDlg.h requires the definition of CMyOwnCtl, i.e. the includes have to be in the other sequence.
I solved this by placing the pointer to the parent in the global definitions. However, I wonder if it could be done more elegantly.
|
|
|
|
|
You can put the includes in the cpp files, and then forward declare the class - so put
class CMyOnwCtl;
in the top of CMyOwnDlg.h and vice versa. This tells the compiler that a class exists, and it will find the details out during the compile process.
I should add - this works because you have a *pointer* to CMyOwnDlg in CMyOwnCtl - this is fine, all the compiler needs to do when compiling the header, is allocate space for a pointer. If you put an instance of the object in the header, it would not work.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I tried this already before asking, but it causes an error, when assigning the address of the parent to the pointer. If ctl_MyControl is the member variable of the instance of the subclassed control, and Parent is defined in MyOwnCtl.h as
class Parent;
then
ctl_MyControl.Parent = this;
in the parent's OnInitDialog causes
error C2440: '=' : cannot convert from 'class CMyOwnDlg *const ' to 'class $S217 *'
However, if the pointer is defined (in the globals) as
CMyOwnDlg *Parent;
then
Parent = this;
works fine from OnInitDialog.
|
|
|
|
|
Vancouver wrote: ctl_MyControl.Parent = this;
This means that ctl_MyControl is not a pointer, which means it won't work, like I said. If ctl_MyControl is a member variable, a forward declaration will only work if it's a pointer to an instance of your control.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Sorry, I mistyped it in the post. Of course I declared it as a pointer and it created the mentioned error.
|
|
|
|
|
|
class *Parent;
is in CMyOwnCtl.h. If it was not there, I would not have any problem: in the function itself CMyOwnDlg can be used. because both headers are known there (and then John M. Drescher's suggestion works).
|
|
|
|
|
When you use forward declaration. The forward declared variable cannot be accessed in the declaration file, since compiler only knows the pointer and allocates the size of pointer when you access it, compiler won't have enough information to do this.
ctl_MyControl.Parent = this;
Is this statement is in declaration file, if so, use this in a function definition is cpp file.
Since the dialog is immediate parent, you know the level of the parent class, you can use john's method (dynamic cast the parent window).
Best Regards
Raj
|
|
|
|
|
One thing you could do is to make *Parent a class member of CMyOwnCtl and pass it in a constructor or a SetParent member.
Actually you do not need to store the pointer though as you can always do a GetParent() in the control and DYNAMIC_CAST or (dynamic_cast) the CWnd pointer to CMyOwnDlg. I do this 90% of the time and use dynamic_cast syntax over DYNAMIC_CAST as my programs are compiled with RTTI and I avoid the MFC macros as much as I can.
John
|
|
|
|
|
This appeared to be all right, at least syntactically.
However,
CMyOwnDlg *Parent = dynamic_cast <CMyOwnDlg *> (GetParent());
in the function of the control caused an error: RTDynamicCast threw an exception.
|
|
|
|
|
Did you set the compiler option to enable RTTI (Run time type info)? If not use DYNAMIC_CAST as this will work without the compiler option.
John
|
|
|
|
|
What is the implication of using virtaul constructors?how to acchieve the model of the same even thogh C++ does not have them?
|
|
|
|
|
tom groezer wrote: virtaul constructors
such a thing doesn't exist... so I don't know where you're taking your questions from, but they're erroneous
|
|
|
|
|
It depends on what you mean. It's true that C++ doesn't support virtual constructors per se, but there is a design pattern called the virtual constructor idiom[^] which may be what the OP is after. Many programmers and designers use the term "virtual constructor" to refer to this idiom and are not talking about literally making constructors virtual.
Steve
|
|
|
|
|
What is your requirement, If you want to hide the details of Object creation,
Refer Factory, builder, .. patterns(Design Patterns)
Contructors are required to identify the class whose object is created. Making it virtual is meaning less.
Best Regards
Raj
|
|
|
|