|
Hi,
Sorry to have started a new thread for an old problem.But there was no reply for a long time so I thought I should restart.
If this a problem I won't do it again.
int *pValue = new int;GetParent->SendMessage(MY_MESSAGE, 0, (LPARAM) pValue);
delete pValue;
In the handler function for MY_MESSAGE:
LRESULT MyParent::OnMyMessage( WPARAM wParam, LPARAM lParam )
{
*(int *) lParam = 123; return 0;
}
The above code was given to sent a message to the parent window and allocate memory for a variable which belongs to the parent.
Thanks for the above code.It was really useful
But can I make Message map of the form MY_MESSAGE and have a handler function OnMyMessage ?
Since message maps are something that are provided by Windows API and they can be generated through Class Wizard where messages and their corresponding functions are already given. Ex WM_KEYDOWN with function OnKeyDown()
Prithaa
|
|
|
|
|
Hi,
Actualy i can't understand u r problem.
The steps for sending a message from one class to another is as follows,
1. define the message
ie #define MY_MSG WM_USER + 1
2. Add the handler in u r parent class
ie in messge map
ON_MESSAGE( MY_MSG, OnMyMessage ) and the message handler
void Parent::OnMyMessage( WPARAM wParam_i, LPARAM lParam_i )
{
}
3. Send the message ie
GetParent->PostMessage( MY_MSG, wParam, lParam ));
You can use either SendMessage() or PostMessage() to send message.
rgds
aneesh
|
|
|
|
|
Hi,
Thanks for your reply.I understood what you wrote
and tried but I get this error.
error C2440: 'type cast' : cannot convert from 'void (__thiscall CVer2scratchView::*)(unsigned int,long)' to 'long (__thiscall CWnd::*)(unsigned int,long)'
Pointers to members have different representations; cannot cast between them
This error is on line
ON_MESSAGE(MY_MESSAGE, ONMYMESSAGE)
Can you try what it must be?
Prithaa
|
|
|
|
|
prithaa wrote: error C2440: 'type cast' : cannot convert from 'void (__thiscall CVer2scratchView::*)(unsigned int,long)' to 'long (__thiscall CWnd::*)(unsigned int,long)'
Pointers to members have different representations; cannot cast between them
This error is meaningless without also showing the offending piece of code.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
|
prithaa wrote: Since message maps are something that are provided by Windows API and they can be generated through Class Wizard where messages and their corresponding functions are already given. Ex WM_KEYDOWN with function OnKeyDown()
just have a look at ON_MESSAGE macro in MSDN or if you know Win32 too try overlaoding DefWindowProc
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And You
|
|
|
|
|
Hi,
i get a compile error, and i know the error
I have this situation
#include "B.h"
class A
{
B aBObject;
}
******************
#include "A.h"
class B
{
A *pointerToA;
}
During definition of A, B will be defined and uses A ( which is not already defined )
I have already used a #ifndef ... #define ...
Anyone a solution?
Thanks
|
|
|
|
|
In one of the .h-files, use forward declaration of the other class, i.e
class A; //Forward declaration
class B
{
A *pointerToA;
}
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Haupt.h
=======
#pragma once
#include "Einstellungen.h"
class Haupt
{
public:
Haupt(void);
~Haupt(void);
Einstellungen *Config;
void Applic();
};
Haupt.cpp
=========
#include "StdAfx.h"
#include ".\haupt.h"
Haupt::Haupt(void)
{
Config = new Einstellungen(this);
Config->Set();
}
Haupt::~Haupt(void)
{
}
void Haupt::Applic()
{
printf("APPLIC");
}
Einstellungen.h
===============
#pragma once
//#include "Haupt.h"
class Haupt;
class Einstellungen
{
public:
Einstellungen(Haupt *verb);
~Einstellungen(void);
void Set();
Haupt *Verbindung;
};
Einstellungen.cpp
=================
#include "StdAfx.h"
#include ".\einstellungen.h"
Einstellungen::Einstellungen(Haupt *Ver)
{
Verbindung = Ver;
}
Einstellungen::~Einstellungen(void)
{
}
void Einstellungen::Set()
{
Verbindung->Applic();
}
Your solution works only in an alone File, where all Definitions are togheter
But thanks !
|
|
|
|
|
|
i will read some sites
Big thanks
|
|
|
|
|
I'm sorry for not helping you out with your specific problem.
But I'm at work and have some other things to attend to...
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
What error do you get?
Does adding #include "Haupt.h" to the top of Einstellungen.cpp fix it?
|
|
|
|
|
No
But i changed the principle ... now it works savely
But nevertheless thanks for your ansers kakan and benjymous
|
|
|
|
|
|
I already know how to get the buffer is full (by select function). but, how can set the buffer to empty?
|
|
|
|
|
my problem is that I insert a control activeX in my CFormView (the control is
an interface ocx) so it generate to files .cpp and .h which contain all methods and proprties.
I wanted to get those methods and members in a class called port.cpp for example
so i put in this class port.h this line
CMyinterfacectrl1 *pDTC;
and I use it like this in port.cpp
pDTC->setWorkIndex(...);
pDTC->ComPortOpen(....);
in my CFormView.cpp
I call my CDialog like this:
Cport p;
p.pDTC=&m_DTC;
p.DoModal();
But when I run the programm and press OK in the CDialog I have this
message :
Exception not generated 0x10008226 dans prog.exe:0xC0000005:
Violation of access when writing in 0x00000030.
and the machine code is: 10008226 rep stos dword ptr [edi]
But my variable is initialized I don't know where is the prob
sometimes it works and some times i have this message
thank's
zizzzzzzzzzzz
|
|
|
|
|
I don't really understand what you are trying to do...
Anyway, if you write this: CMyinterfacectrl1 *pDTC; and then use it like that:
pDTC->setWorkIndex(...);
pDTC->ComPortOpen(....);
Then you'll get a problem because your pointer is not initialized, thus it points to invalid memory. You first need to create an instance of your class using new (don't forget to delete it afterwards).
|
|
|
|
|
I thought that those lines initialize it:
Cport p;
p.pDTC=&m_DTC;
p.DoModal();
or not ?
|
|
|
|
|
Your explanation is very unclear. Post some relevant code with the explanations, it is very difficult to see what you did.
For me pDTC was a global variable (you said that you put the code in port.h, you didn't say that it was a member of a class).
And also, explain when exactly does the problem appear (use also your debugger to narrow the problem)
|
|
|
|
|
sorry ! and thank's for the advice
I'll try to explain more:
when I insert the control activeX in my CFormView I create for it a member
variable with the wizard of "VC++ .net" as a control in the category.
so it's like this :
CPrincipale::CPrincipale()
: CFormView(CPrincipale::IDD)
, m_DTC()
{
}
then I do what I said before
i put in the class port.h this line:
CMyinterfacectrl1 *pDTC; //pointer to the class which was created when I insert the control.
and I use it like this in port.cpp
pDTC->setWorkIndex(...);
pDTC->ComPortOpen(....);
in my CFormView CPrincipale.cpp
I call my CDialog like this:
void CPrincipale::onPort()
{
Cport p;
p.pDTC=&m_DTC;
p.DoModal();
}
I hope that is clear enough
please help me !
|
|
|
|
|
But, why are you doing that ? Why have a pointer to your activeX control in a class that has nothing to do with it ? (and your explanation is still not very clear...)
|
|
|
|
|
because if I want to add a control ActiveX I must select the FormView
right click > insert Control ActiveX
then select the control add variable > category control
so it generate two files here you are some code of itdcinterfaceCtrl.h
class CItdcinterfacectrl1 : public CWnd
{
protected:
DECLARE_DYNCREATE(CItdcinterfacectrl1)
public:
CLSID const& GetClsid()
{
static CLSID const clsid
= { 0xFB05973A, 0x3C1E, 0x46DC, { 0x95, 0x93, 0xDC, 0xEE, 0xC4, 0x29, 0xDC, 0x88 } };
return clsid;
}
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
}
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey);
}
// Attributs
public:
// Opérations
public:
// _DITDCInterface
// Functions
//
void DoorTimeSchedule(LPCTSTR DoorTimeSchedule1, LPCTSTR DoorTimeSchedule2, LPCTSTR DoorTimeSchedule3, LPCTSTR DoorTimeSchedule4)
{
static BYTE parms[] = VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR ;
InvokeHelper(0xb, DISPATCH_METHOD, VT_EMPTY, NULL, parms, DoorTimeSchedule1, DoorTimeSchedule2, DoorTimeSchedule3, DoorTimeSchedule4);
}
void AccessDoor(LPCTSTR DoorIndex1, LPCTSTR DoorIndex2, LPCTSTR DoorIndex3, LPCTSTR DoorIndex4)
{
static BYTE parms[] = VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR ;
InvokeHelper(0xc, DISPATCH_METHOD, VT_EMPTY, NULL, parms, DoorIndex1, DoorIndex2, DoorIndex3, DoorIndex4);
}
but if I create a class to this control and not a member variable I don't obtain attributs and function chown below!
|
|
|
|
|
zizzzz wrote: but if I create a class to this control and not a member variable
Sorry, but I still don't understand... What do you mean by creating a class to this control ?? Simply declaring an instance of your class outside your view class ? But, why do you want to do that, that's the real problem ! An activeX is a control (it inherits from CWnd), so it will be displayed on your view, dialog, ... So, it is logical that it is a member variable of your view or dialog. Why do you want it to be outside of your class ?
|
|
|
|
|