|
I am calling a PostMessage function froma worker thread and passing it a user defined window message. Since i have to update the control's which cannot be done as part of thread. Therefore I want to send a sturcutre along with the PsotMessage().
Is it Possible to pass a structure in PostMessage() and if Possible please tell how.
Thanks In Advance
Dhiraj
|
|
|
|
|
Dhiraj kumar Saini wrote: Is it Possible to pass a structure in PostMessage()
yes
Dhiraj kumar Saini wrote: and if Possible please tell how.
Send:
Dynamically allocate memory your strucuture first
Fill structure
Pass structure
Read
When you receive the message, read type cast the parameter in the respective pointer
read the data
delete the pointer
struct DATA
{
int EventID;
CString ModuleName;
CString ThreatName;
} info;
info* ptr = new info;
ptr->EventID = Whatever;
ptr->ModuleName = Whatever;
ptr-> ThreatName = Whatever;
PostMessage(WM_MYMSG, reinterpret_cast<wparam> (ptr) , static_cast<lparam> 0);
info* ptr = reinterpret_cast<info*> wParam;
info obj;
obj.EvenID = ptr->EvenID;
obj.ModuleName = ptr->ModuleName;
obj.ThreatName = ptr->ThreatName;
delete ptr;
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I have used the following code but it is giving eroor
Please tell whats the problem
VisitorDetails stVisitorPrDetails
m_vSiteVisitor[n].GetDetails(stVisitorDetails);
PostMessage(WM_GET_DATA,reinterpret_cast<wparam> (stVisitorPrDetails) , static_cast<lparam> 0);
and
LRESULT CMainDlg::OnGetData(WPARAM wParam,LPARAM lParam)
{
VisitorDetails stVisitorDetails;
stVisitorDetails = reinterpret_cast<visitordetails> wParam;
return 0;
}
the errorr are:
Error 25 error C2061: syntax error : identifier 'wparam' c:\documents and settings\shy\desktop\sourcecodes 8-09-08\source code 06dec2007\maindlg.cpp 525
Error 27 error C2061: syntax error : identifier 'wParam' c:\documents and settings\shy\desktop\sourcecodes 8-09-08\source code 06dec2007\maindlg.cpp 1927
Error 28 error C2146: syntax error : missing '(' before identifier 'wParam' c:\documents and settings\shy\desktop\sourcecodes 8-09-08\source code 06dec2007\maindlg.cpp 1927
Please Help
|
|
|
|
|
Dhiraj kumar Saini wrote: Error 25 error C2061: syntax error : identifier 'wparam' c:\documents and settings\shy\desktop\sourcecodes 8-09-08\source code 06dec2007\maindlg.cpp 525
Error 27 error C2061: syntax error : identifier 'wParam' c:\documents and settings\shy\desktop\sourcecodes 8-09-08\source code 06dec2007\maindlg.cpp 1927
Error 28 error C2146: syntax error : missing '(' before identifier 'wParam' c:\documents and settings\shy\desktop\sourcecodes 8-09-08\source code 06dec2007\maindlg.cpp 1927
In the above I see wparam , then wParam , i.e. it seems you have to choose one between the two different names for your variable...
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Dhiraj kumar Saini wrote: Is it Possible to pass a structure in PostMessage()
Yes.
Dhiraj kumar Saini wrote: if Possible please tell how
Pass a pointer to the structure as LPARAM. for instance:
static MyStruct ms;
UINT MyWorkerThread( LPVOID pParam )
{
ms.iProgress = 10;
PostMessage(hWnd, WM_MY_MESSAGE, (WPARAM)0, (LPARAM)&ms);
}
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanx u r genius .
It solved my problem
|
|
|
|
|
Dhiraj kumar Saini wrote: Thanx u
You're welcome.
Dhiraj kumar Saini wrote: u r genius
Well, I know that
Dhiraj kumar Saini wrote: It solved my problem
I'm glad it helped.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
Is it possible to use RotateTransform() after Graphics::DrawImage()?
Ex.
Graphics g(hMemDC);
for(){
for(){
.....
g.DrawImage();
}
}
g.RotateTransform();
Based from MSDN example RotateTransform is before DrawImage() function but I have tried the above code (6 months ago) and it works.
But now this code doesn't work anymore.
Image doesn't rotating anymore.
My code is for stitching tiles of an image to make it whole. When I place RotateTransform() before DrawImage() it produces black dash lines in between tiles.
It's been a solution to place RotateTrasform after DrawImage but now I can't make it work.
What seems to be the problem?
Do I have to add some more code?
Hope somebody can help me. Thanks.
|
|
|
|
|
Well, I guess DrawImage should follow RotateTransform and not the opposite. If you got undesidered lines, probably there's something wrong in your parameters.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for the reply.
Placing DrawImage after RotateTransform somewhat rotate my image tiles before stitching them. What I wanted is to stitch all first then rotate.
Is there any other way to do this.
|
|
|
|
|
Why dont you create a stitched bitmap first and then draw this bitmap on device context.
i mean
Graphics gr(bmpTemp)
.... Stitching code.
Graphics gr(hDC)
RatateTransform()...
DrawImage(bmpTemp)..
Does it make sense??
Regards,
Sandip.
|
|
|
|
|
Thanks for the reply.
I look at MSDN and I haven't found a constructor for bitmap.
Is there any?
|
|
|
|
|
check this
http://msdn.microsoft.com/en-us/library/ms535632(VS.85).aspx
|
|
|
|
|
I am working on a phonetic converter program. There are converter classes like "aConverter ","bConverter " etc which contains rules for converting english letters to equivalant text in other language.
In some cases fonts may have different formats. So I need to create different converters for it and plug with the application. I plan to supply all the converter details in a file and load the converter on runtime. So if I have specified "aConverter " in a file, how can I initialize it's instance? Each converter implements "IConverter " interface.
In C# I can use Activator.CreateInstance and cast to IConverter type. I am looking for a method to do this in standard C++ not MFC/C++ CLI. Or is there anyother changes which I can make in the existing design so that new converters can be plugged in?
|
|
|
|
|
Please elaborate: What exactly do you need that you can't find in standard C++ (possibly persistence?)?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: What exactly do you need that you can't find in standard C++ (possibly persistence?)?
I didn't get you. I am looking for some reflection kind of stuff.
|
|
|
|
|
Well, probably I had to use serialization instead of persistence, I meant saving/loading an object to/from a file. Is that what you need? On the other hand, as you probably know, reflection is a .NET feature not supported by standard C++ .
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you very much for your help.
CPallini wrote: I meant saving/loading an object to/from a file. Is that what you need?
NO. I just need to plug new converters to the application. All the converters implement IConverter interface.
CPallini wrote: reflection is a .NET feature not supported by standard C++.
I know. I used the term "reflection" here for better understanding. I need to compile this code in multiple platforms, that's why I am sticking with standard C++.
|
|
|
|
|
Not sure I got you, anyway have a look at creational design patterns [^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Not sure I got you
I might have not explained clearly Let me try my luck once more
I need some thing simlar to Builder[^] pattern. In that link PizzaBuilder is an abstract class providing methods to override. Many builder classes are derived from it and overrides the functionality. If you look at the main function (C#) you will find
PizzaBuilder hawaiianPizzaBuilder = new HawaiianPizzaBuilder();
PizzaBuilder spicyPizzaBuilder = new SpicyPizzaBuilder(); In this case we knows HawaiianPizzaBuilder or SpicyPizzaBuilder is the one to instantiate.
But in my case, I know only the class is derived from PizzaBuilder and it's name, say CustomPizzaBuilder . In that case, how do I instantiate it?
This can be easily done using reflection in managed code. As reflection is not supported in standard C++, is there a workaround for this? Or how does the Builder pattern is implemented in C++ when we have only the subclass name available?
I hope I made it clear.
|
|
|
|
|
OK. I think you may exploit the Prototype pattern:
(1)
Every new converter, say kConverter , should provide a clone method like
class kConverter : public IConverter
{
public:
IConverter * clone()
{
return new kConverter();
}
};
(2) Every new converter should add himself to a global map<string, IConverter>
Does the above make sense?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Does the above make sense?
Perfect! It did. This is going to work. Many thanks.
I think the clone() method is not needed as I will add new converters to map<string, IConverter> .
Thanks for taking time to help me. A well deserved 5
|
|
|
|
|
N a v a n e e t h wrote: I think the clone() method is not needed as I will add new converters to map<string,>.
Yes, that makes perfect sense.
N a v a n e e t h wrote: Thanks for taking time to help me
You're welcome.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
I prefer not to include any header files in other header files as long as it is possible.
But I have problem when I want to use an Enumeration type in a header file, which is defined in another header file.
I mean we can introduce classes and structs at the start of a header file, but it is not the case about Enumeration Data Types:
struct st1; //correct
Class C1; //correct
Enum e1; //Incorrect
|
|
|
|
|
is this a design question ?
or just trying to inform somebody here ?
if so, I strongly unadvise to do so. that is just not suitable for most advanced designs, and it's just the way C/C++ is designed and intended to work...
so, to make it short, go with #includes withing headers, it's not bad to do so !
|
|
|
|