|
Are you sure that it is an MFC project and not a console application, or just a simple application? Did you use the application wizard to create the project?
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
I overrode the CBN_SELCHANGE event so I have a OnSelChangeControl event for my dialog. (In MFC, via ClassWizard)
When the user changes the selection, the code doesn't get called. If I do a close-up event on the same control it works, but I need it to run on selection change and not just close-up.
I'm using a break point in the debugger to see if it'd getting called.
What am I forgetting?
|
|
|
|
|
This is odd. I made a new project, and did what I did above. It works. But it refuses to work on this project.
Does anyone have any ideas?
|
|
|
|
|
Compare your message map calls between the two projects and see if they match. Your event may not have gotten hooked up for some reason. I've had issues with that before (though not usually on a combo box) that were fixed by hooking up the message map manually.
I did a test app to see if I could duplicate your problem and mine worked fine. Heres the code that classwizard generated.
void CSelChangeTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC_LABEL, m_label);
DDX_Control(pDX, IDC_COMBO1, m_combo1);
}
BEGIN_MESSAGE_MAP(CSelChangeTestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
END_MESSAGE_MAP()
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I did verify that I have:
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
So it is wired up right.
I also checked for duplicate nmumonics and control IDs. No such luck. It's like windows isn't sending (or is swallowing) the event.
I even went into PreTranslateMessage() and did:
if (m_cmbCombo1.m_hWnd==pMsg->hWnd) {
TRACE ("%d %d %d\n",pMsg->message,pMsg->wParam,pMsg->lParam);
}
and no CBN_SELCHANGE messages are comming in!
Arg!
|
|
|
|
|
Someone (not me) made it a CComboBox2
CComboBox2 publicly inherits CCombobox, be it looks like this isn't good enough.
How do I use a derived class like this, while still being able to use the CComboBox's events?
|
|
|
|
|
The message for Combo box you handled in the parent dialog
i.e. CBN_SELCHANGE is called notification. In your project this notification message from child i.e. ComboBox to parent dialog is handled by the parent (Dialog which has the message handler). But when you derive the a class publically from the CComboBox class then you define the message handler in this new derive class for the notification message from the ComboBox and this method is called Message Reflection.
Now you will have to map your combo box with your newly
derived class through wizard which will defined an instance
of derive class to the parent dialog like...
class CSelChangeTestDlg:public CDialog<br />
{<br />
...<br />
private:<br />
CDerivedCombo m_MyCombo;<br />
....<br />
}<br />
<br />
void CSelChangeTestDlg::DoDataExchange(CDataExchange* pDX)<br />
{ <br />
CDialog::DoDataExchange(pDX);<br />
DDX_Control(pDX, IDC_COMBO1, m_MyCombo); <br />
...... <br />
}
Now the newly derivered class is self contained and you can this class for the customized behaviour in any project. You dont have to define the message handler again in the parent class/Window of the ComboBox because this defined in the derived class. you only need to map it with the Combo Box. If you need further help plz .....
Regard,
Nasir Maan
|
|
|
|
|
I have a Class (XClass) which has a private variable (Dialog*). It references to main dialog. So, the main dialog has same variables which were initializated before.
In the dialog I do something like that: varibleX.setParnert(this)
The problem is when I call one method, from the XClass, the Dialog´s variables lost their values.
it is an example how i do: ((CMyDlg*)pWnd)->NuevaTarea(strRecvd);
Which is my error?
el hombre arriesga su vida cada vez que elige y eso es lo que lo hace libre
|
|
|
|
|
I don't know exactly what's your problem, but since you're accessing the variables through a pointer (Dialog* ) you can modify them in any way. What you can do is making the parameters of your member-functions in XClass "const" . That way you won't be able to change the dialog variables directly. You can change e.g. definition of NuevaTarea() to something like that:
NuevaTarea(const CString& strRecvd);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I´ll try to explain
I have a dialog(CSurSpoolerDialog) which has a public variable(server).
So, the Server has a private variable pWnd as CDialog* (which is a reference to parnert dialog (CSurSpoolerDialog))
I initilized the Server, Then I call server.setParnert(this)
So, The Server has a event (OnMessage)where I want to call a Dialog´s method ( ((CSpoolerSurDlg*)pWnd)->NuevaTarea(strmessage) )
All work fine, but when i debug the NuevaTarea all the dialod´s variables have lost them values. they have NULL (???)
it is more clearer?
|
|
|
|
|
I found the solution thanks you the any way
el hombre arriesga su vida cada vez que elige y eso es lo que lo hace libre
|
|
|
|
|
I try to make an active X calling an other active X, but I dont know how to do to make the active X I'm calling to be visible.
I don't know if I explain it as clearly as I should, but who can help me?
Thank you
|
|
|
|
|
Are you using MFC ? Well... anyway.. he activex will have and hWnd handle, just call the ShowWindow API and the control should display. If you're using MFC, you can use a method with the same name... that does the same thing.
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
Life is a mixture of painful separations from your loved ones and joyful reunions, without those two we'd just be animals I guess. The more painful the separation, that much more wonderful will be the reunion - Nish
"Th@ langwagje is screwed! It has if's but no end if's!! Stupid php cant even do butuns on forms! VISHAUL BASICS ARE THE FUTSHURE!" - Simon Walton
|
|
|
|
|
Do I Have to create a CDialog to insert my active X into?
|
|
|
|
|
No.. you don't need to. Whatever method you use, the activex will always have an hWnd handle. Can you post the method you're using to create it ?
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
Life is a mixture of painful separations from your loved ones and joyful reunions, without those two we'd just be animals I guess. The more painful the separation, that much more wonderful will be the reunion - Nish
"Th@ langwagje is screwed! It has if's but no end if's!! Stupid php cant even do butuns on forms! VISHAUL BASICS ARE THE FUTSHURE!" - Simon Walton
|
|
|
|
|
No, I haven't any hWnd...
My project is to create an Active X. So I've created this with Visual C++.
Then I want to insert in this project my other control Active X so I go to Project, Add to Project, Components and controls and I choose the component I want.
I've added methods to my project so I can call them from a tester...
On the call of one of this methods, i want to make the component I've inserted to be visible (it's a map)... How can I draw it?
I only have the about box and the property dialog in my project at the moment...
Thanks
dvlpt
|
|
|
|
|
I have created an MFC project through AppWizard which supports Active Documents. If I create a new document and insert an existing Word file, all looks fine. However, when I come to print preview, the preview window opens, but the document is actually printed to the printer.
I asked a while ago and no-one had any ideas of how to make it work, but I've come up with a few possibilities, and wondered if anyone might be able to help.
First possibility is to change the parameters to IPrint::Print() so that it uses the preview screen DC instead of the printer - anyone know how this can be done?
The second option is printing to a file, and then viewing the file. Any ideas on how I can view a "Print to File" file on screen?
Thanks in advance!
|
|
|
|
|
Can anyone suggest a good sample app that demonstrates multi-threaded graphics using VC++ and MFC? Trying to get a seperate thread working to handle dialog graphics animation. Thanks
|
|
|
|
|
find the "MTGDI" sample in the MSDN. it's the classic multi-threading sample: each thread controls a bouncing ball.
-c
|
|
|
|
|
Thanks, I forgot all about that one. I'll check it out.
|
|
|
|
|
How can I implement a class function, which can be run in separate thread
Example
class AudioIn
{
public:
AudioIn();
virtual ~AudioIn();
void StartProc();
HANDLE Thread;
DWORD m_ThreadID;
HANDLE hEvent;
};
AudioIn::AudioIn()
{
hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
Thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)AudioIn::StartProc,NULL,0,&m_ThreadID);
}
Is it possible?
I'm creating console application in VC++.
Sorry for stupid question.
Tomaz
|
|
|
|
|
Yes. One your example, declare StartProc as a static public member function.
Kuphryn
|
|
|
|
|
How can I get few parameters into static class function?
Should I declare a structure
Thread = CreateThread(NULL,0,AudioIn::StartProc,declared-structure,0,&m_ThreadID);
or is there a simple way?
Thank you
Tomaz
|
|
|
|
|
You have to declare a structure and pass a pointer to it. There are some common problems regarding who owns this structure. Consider the following:
void foo()
{
data d;
CreateThread(...,&d,...)
} This seems OK and will probably work some times until it suddenly stops to do it. The reason is that, when the thread starts executing and access d , it is perfectly normal that foo has already exited, and d is no longer valid. So, you have to dynamically allocate the data:
void foo()
{
data* d=new data;
CreateThread(...,d,...)
} Now the problem is who deletes d ? The most reasonable choice is to let the thread delete the data:
MyThread(LPVOID arg)
{
data * d=(data *)arg;
...
delete d;
...
} This is almost perfect: you should take into account the rare case when the thread does not launch (due to insufficient resources, for instance):
void foo()
{
data* d=new data;
if(!CreateThread(...,d,...)){
delete d;
}
} That's it, hope it helps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi Tomaz,
the problem is that CreateThread() is a c function...and c doesn't know anything about classes or virtual tables...
try this:
//---------------------------------------------------
void YourClass::AnyFunction()
{
// declarations
DWORD dwId;
// create the thread
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartAddress,(LPVOID)this,0,&dwId);
}
DWORD YourClass::StartAddress(LPVOID lpParam)
{
// call the thread function
((YourClass*)lpParam)->ThreadFunction();
}
void YourClass::ThreadFunction()
{
...
}
//---------------------------------------------------
in the header you should declare the thread start procedure as follows:
static DWORD StartAddress(LPVOID lpParam);
..this should do it
|
|
|
|