Problem with user defined messages (WM_APP+n)

Hi,

I have a dialog application that creates a modeless child dialog which remains open for the lifetime of the application.

This is due to fact child dialog has an activex control that is constantly processing data and cant be shut down. When the user is not using the child dialog i make it invisible and make it visible when they want access to it.

Now i found some code that allows the parent dialog to keep track of it's child dialog.This involves adding a modelessdialoghelper and modelessdialogtracker class to my project. (Code at bottom of page)

It involves changing the child dialog class so it has two base classes, CDialog and CModelessDialogHelper and changing the constructor so that a modelessdialoghelperclass object is passed from the parent to the child dialog. 

I have found out through trial and error that this is where my problems are occuring. I want to be able to change a variable in the child dialog from a thread created in the parent dialog and thought the best way to do this was to use PostMessage to post a message from the parent to child to change the variable state.

If i use the standard contructor i can add user define messages to my child.h and .cpp file as shown below

Child .h
Class ChildDialog : CDialog
{
                .
                .
//{{AFX_MSG(CSetupAdministratorDlg)
     virtual BOOL OnInitDialog();
      afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
      afx_msg void OnPaint();
	     .
                     .	
      DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
afx_msg void OnSwitchLogging(WPARAM, LPARAM);  <- User Defined Message
DECLARE_MESSAGE_MAP()

//child.cpp
BEGIN_MESSAGE_MAP(CSetupAdministratorDlg, CDialog)
/{{AFX_MSG_MAP(CSetupAdministratorDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_GETBKGND, OnGetbkgnd)
ON_BN_CLICKED(IDC_GO, OnGo)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_RESET, OnReset)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_EN_CHANGE(IDC_ROOT, OnChangeRoot)
//}}AFX_MSG_MAP
ON_MESSAGE(UWM_SWITCH_LOGGING_ON,OnSwitchLogging)  <- User Defined message
END_MESSAGE_MAP()



Now if change the child constructor so as to allow it to be tracked by parent dialog as shown below

//Child.h
class CChildDlg : public CDialog, CModelessDialogHelper
{
// Construction
public:
                      .
                      .
    	//CSetupAdministratorDlg(CWnd* pParent = NULL);	// standard constructor
	CSetupAdministratorDlg(CModelessDialogTracker& tracker);   <- update contructor
//Parent.cpp
// Create modeless dialog with and passes tracker object

if (trackChildDialog.IsAlreadyPopped())
{	
           // Make Dialog Visible as it has been created and is hidden at moment
          CChildDlg& dlg = (CChildDlg&)*trackChildDialog.GetDlg();
          dlg.ShowWindow(SW_SHOW);
          return;
}
// This will be called Child Dialog is accessed for the first time, create modelss dialog
          CChildDlg* m_pNewDlg = new CChildDlg(trackChildDialog);
           m_pNewDlg->Create(m_pNewDlg->IDD,NULL);	


I get the following error:-

C:\Projects\SomeProject\ChildDlg1.cpp(60) : error C2440: 'type cast' : cannot convert from 'void (__thiscall CChildDlg::*)(unsigned int,long)' to 'long (__thiscall CWnd::*)(unsigned int,long)'
        Pointers to members have different representations; cannot cast between them

When i double click to see what the problem is , it is the 

ON_MESSAGE(UWM_SWITCH_LOGGING_ON,OnSwitchLogging)  <- User Defined message in the child.cpp(as shown above )

that is the problem


I have no idea why changing the the standard contructor to the new constructor as shown above would cause this error. Can anyone tell me why this error is occuring and what i can do to solve it?

Below is all the relevant source code

Thanks Macca

//ModelessDialogTracker.h
#pragma once
	// this class combined with the following helper class provides a simple way to deal with
	// modeless dialogs.  See the example at the end of the file for implementation details.
class CModelessDialogHelper;

class CModelessDialogTracker  
{
public:
     CModelessDialogTracker();
     virtual ~CModelessDialogTracker();

     BOOL IsAlreadyPopped() const;	// call before creating.  If true, don't bother (it will be set to active)
     CDialog* GetDlg() const;		// allows direct (with casting) access to dialog.

      virtual void OnDialogClosed() {}	// override if you want to do something when closed.
      void CloseDialog();		// call to forcibly close dialog (automatic when destructed)
      BOOL IsPopped() const;		// just return the status of the dialog pointer.

     friend CModelessDialogHelper;	// so the helper can access the start and stop functions.

private:
     CDialog* pDlg;			// pointer to modeless dialog (or NULL)
     void StartTracking( CDialog& dlg );	// called by ModelessDialogHelper constructor
     void StopTracking();		// called by ModelessDialogHelper destructor
};

//////////////////////////////////////////////////
class CModelessDialogHelper
{
public:
     CModelessDialogHelper(CModelessDialogTracker& tracker, CDialog& dlg);  // sets the tracked pointer.

     virtual ~CModelessDialogHelper();  // clears the tracked pointer.
private:
     CModelessDialogTracker* pDlgTracker;
};

///////////////////////////////////////////////////
#pragma warning( disable : 4355 )  
                                 // the warning given when passing "this" to a member constructor.
		// in the case of the helper class, we WANT to do this.

0
anonymous (74719)
5/21/2004 11:16:05 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
463 Views

Similar Articles

[PageSpeed] 41

Macca wrote:
> afx_msg void OnSwitchLogging(WPARAM, LPARAM);  <- User Defined Message
> DECLARE_MESSAGE_MAP()
> 
> //child.cpp
> BEGIN_MESSAGE_MAP(CSetupAdministratorDlg, CDialog)
> /{{AFX_MSG_MAP(CSetupAdministratorDlg)
> ON_WM_SYSCOMMAND()
> ON_WM_PAINT()
> ON_WM_QUERYDRAGICON()
> ON_BN_CLICKED(IDC_GETBKGND, OnGetbkgnd)
> ON_BN_CLICKED(IDC_GO, OnGo)
> ON_BN_CLICKED(IDC_EXIT, OnExit)
> ON_BN_CLICKED(IDC_RESET, OnReset)
> ON_WM_TIMER()
> ON_WM_DESTROY()
> ON_EN_CHANGE(IDC_ROOT, OnChangeRoot)
> //}}AFX_MSG_MAP
> ON_MESSAGE(UWM_SWITCH_LOGGING_ON,OnSwitchLogging)  <- User Defined message
> END_MESSAGE_MAP()

The function signature you are using for the message handler is wrong. 
Message handlers for ON_MESSAGE are required to return LRESULT:

afx_msg LRESULT OnSwitchLogging(WPARAM, LPARAM);

Return 0 from the function to indicate the message has been handled.


-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
5/21/2004 12:53:19 PM
See below...
On Fri, 21 May 2004 06:11:08 -0700, "Macca" <anonymous@discussions.microsoft.com> wrote:

>Thanks Scott,
>
>That works. i have another problem that maybe you can help me with. In the same app as described before.
>
>The parent Dialog has created a thread, using AfxBeginThread, which will post messages to the modeless child dialog.
>
>The way i thought about doing this is shown below.
>
>Where I create the modeless child diagram i thought i would out the retuen value into a member variable so that this member variable would contain a pointer to the child window as shown below:-
>
>// Function to create Modeless child Dialog
>CChildDlg* m_pNewDlg = new CChildDlg(trackAdminSetupDialog);
>m_pNewDlg->Create(m_pNewDlg->IDD,NULL);   m_pNewDlg declare as CChildDlg *m_pNewDlg in Parent.h
>
>
>Now i thought that in the fuction that creates the thread i could use this membe variable to create a variable on the heap and pass this to the thread as shown below:_
>
>//Function that creates thread
>CParameters * pParameters;// = new CParameters;     Parameters class has 3 params including CWnd *pWnd
>pParameters->wnd = new CSetupAdministratorDlg();
****
You create a CSetupAdministratorDlg object in C++, but you don't create the modeless
dialog to do with it. Unless you have done
	pParameters->wnd->Create(CSetupAdministratorDlg::IDD, NULL);
then you have no window. The line below then overwrites this pointer (thus losing all
references to the object, causing a memory leak). So why did you do a 'new' and then
overwrite it? And in particular, why did you first overwrite it with a newly created
CSetupAdministratorDlg, and then overwrite it with a CChildDlg? Note that since the value
of IDD is a constant, there is no reason to use the pointer to reference it.
*****
>pParameters->wnd = m_pNewDlg;
>
>AfxBeginThread(ThreadProc,(LPVOID)pParameters,THREAD_PRIORITY_NORMAL);	
>
>However the problem i have is that there is nothing in m_pNewDlg even though earlier on when i created the modeless dialog i used  CChildDlg* m_pNewDlg = new CChildDlg(trackAdminSetupDialog).It has obviously gone out of scope but i don't know why.
*****
You declared a local variable that overrode the member variable name. And you declared a
local variable with a member variable notation (don't use misleading notations if they are
used incorrectly: one of the reasons I am deeply opposed to all these notations)

You probably had a name declared in your class

class CSetupAdminstratorDlg : public CDialog {
    protected:
        CChildDlg * m_pNewDlg;
....
};

and then you declared a LOCAL variable using a MEMBER variable naming convention:

CChildDlg * m_pNewDlg = new CChildDlg(...);

so this declared a local variable incorrectly named as a member variable, then allocated
an object, stored the pointer in the local variable, and went on with life. If you had
meant to store it in the member variable, you would not have written a declaration at this
point, but simply
	m_pNewDlg = new CChildDlg(...);

>
>How can i pass the window that i created  when i created the modeless dialog into the thread so that i can post a message to that window, the child dialog?
>
****
By using the correct variable.
****
>Thanks In Advance
>Macca
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
5/21/2004 4:53:01 PM
Thanks Joe

Stupid mistake!!

Macca
0
anonymous (74719)
5/24/2004 8:26:06 AM
Reply:

Similar Artilces:

Problem shortcuts in Word
Hello, I work with Word 2008. In the beginning there is no problem, but suddenly i have problem with shortcuts. When i want to do "cmd c" it make an other shortcuts same thing for "cmd s", "cmd v" and surly some other. But when i write there is no problem "c" is "c"... If somebody have an idea please help me. Thank you. Unless you indicate your specific update level of Office as well as OS X & describe what the keystrokes *are* doing contrary to what you expect there isn't much we can offer. -- Regards |:>)...

encoding problem in Outlook 2007 importing Outlook 2000 personal folders
I use Outlook 2007 to import the pst file of Outlook 2000. The Chinese characters in the subject became unreadable but it's ok to display in message body. In Outlook 2000, there's no problem to display the Chinese characters in the subject. What's wrong with Outlook 2007? What setttings should I change to fix the problem? Thanks. cyl <u8526505@gmail.com> wrote: > I use Outlook 2007 to import the pst file of Outlook 2000. The Chinese > characters in the subject became unreadable but it's ok to display in > message body. In Outlook 2000, there's no problem t...

Outlook 2003 PST problems
I just installed Office 2003 professional on a new computer & am having problems with outlook. I copied my Outlook.pst file into the appropriate directory & although it is recognized the calendar is not working properly. I cannot attach any of the colored labels to my appointments - so everything is pretty much in black & white. I totally uninstalled & reinstalled office... first removing my pst file... but there appears to be an ini file... or something that is retaining some information... does anyone know of a fix for the labels... or how to TOTALLY uninstall office (so I...

Outlook not sending messages from correct POP3 account
I am a tech support person, supporting several companies from my home. Therefore, I have several pop3 email accounts setup on my computer in Outlook. When I reply to an email, I need to make sure that the correct account shows up in the "From" field. This works for some messages, but for others, the email is sent from the wrong account (making me look real bad :-)). This happens even when it says it's going to be sent from the correct account, if I check the sent items afterward, I'll see that it was sent from the wrong account. This is driving me batty and I nee...

Problem with Authentication
The CRM application was running smooth. But now I can't logging. It ask my credentials and than return a 401.1 error. I had already reinstalled the CRM server but it won't work. I'm accessing it in the same local network. I'm running CRM 3.0 in SBS. Best regards, Erico Hi When you open a Internet explorer and type the name of the CRM server, it prompts for user and password ? Are you logged in with domain credentials ( AD user ) ? If you are, so add url of the crm server in Local intranet. Enable "Automatic logon only in intranet", this is under security,c...

Vista blue screen problem...please help!
I've seen some other threads, here are the dump files: 'RapidShare: 1-CLICK Web hosting - Easy Filehosting' (http://rapidshare.com/files/347103149/Minidump.rar.html) Please, help me out here. -- ceVil It might be better to know at what point the bsod occurs and what the actual err.msg given is "ceVil" <guest@unknown-email.com> wrote in message news:0b9a0c60b90bf6c0be88bda30f2820ab@nntp-gateway.com... > > I've seen some other threads, here are the dump files: > 'RapidShare: 1-CLICK Web hosting - Easy Filehosting' > (...

calendar problem
Dear all, I am using both mail and calendar function in outlook 2002. Everything is ok until recently, when I try to make a new appointment or checking any old appointments, an error message "out of memory or resource, try to close some windows..." pop up. The mail function is still ok. Can anyone tell me how can I solve this? I have already installed sp2. The version of office is the professional one with frontpage. Thanks. tp ...

problem #4
Hi, I am facing this new problem... i.e a user has installed Office 2003 on win2k prof platform.. whenever she is working on a outlook.. she gets a Microsoft error message... saying to send the report or don't send the report... Usually I have seen this problem in IE... But for outlook it is new to me... after clicking on send or don't send report.. the outlook closes. And there are no IE open..... and if atall it is open.. the IE does not close... Need your help regards, KAH What is logged to the Event Viewer regarding this? Try one of the following already; http://www.howt...

Automatic printing of sent messages.
Can Outlook 2000 be set-up to automatically print a message immediately after having hit the "send" button? or Can a "Send and Print" button be set up? I'm probable not the only grunt that has to print a hard copy of all outgoing e-mails to be maintained in a physical file folder. To make matters worse, bosses cc: me so that I can print out and file their messages too. Thanks >-----Original Message----- >Can Outlook 2000 be set-up to automatically print a >message immediately after having hit the "send" button? or >Can a "Send a...

Making End User Recovery Work
I've seen a lot of people commenting how EUR never works for them. It does work for me after a lot of fiddling, and here are some brief comments that might help: 1. Don't just turn it on within DPM itself; go to one of your domain controllers and run the EUR setup utility. For DPM2010 it can be found at: \\dpmserver\c$\Program Files\Microsoft DPM\DPM\End User Recovery\DPMADSchemaExtension.exe For DPM2007 I believe it's at: \\dpmserver\c$\Program Files\Microsoft Data Protection Manager\DPM\End User Recovery\DPMADSchemaExtension.exe Remember, run this on your...

95 and 97 problem
For some unknown reason there is Excel 95 and 97 on this pc.When i double click on an Excel file, the pc defaults to the 95 program (Which incidently doesn't work properly). So my question is how do i get the pc to default to 97. Cheers Craig Craig, Have a look at Windows Help. From Windows 2000 Help (Index under Programs Associating with File Types) To change which program starts when you open a file In My Computer or Windows Explorer, on the View menu, click Folder Options. Click the File Types tab. In the list of file types, click the one you want to change. Click Edit. In Act...

Importing Message Archival
Hello everyone, I have turned on the message archival under IMS logging to for the purpose of backup. I can open these file with notepad for administrative purposes, but what I really need to do is to import these into a mail box or a pst file so I can read them using outlook. Any input is welcome, Thanks. Calvin wrote: > Hello everyone, > > I have turned on the message archival under IMS logging to for the purpose > of backup. I can open these file with notepad for administrative purposes, > but what I really need to do is to import these into a mail box or a pst >...

Date problem
I can't believe there's no post on this, but I can't find it. I've tried the solutions I could find (see below) and still get the error: "The expression is typed incorrectly or it is too complex to be evaluated. For example....Try simplifying...." I have a date field, formatted as Date/Time, General Date, default Value = Now(). I like having the date and the time - in case we need it. I want to run a report on calls taken just for one day. I have CallDate: CallDateAndTime in my query, with "criteria" as Between ([Forms]![frmReports]![txtStartDate]) A...

sync problems
I have all of my info on an HP Ipac. I had to reformat the hard drive and I did not make a back-up file. I am trying to move everything back to the computer but it says there is an error with syncing it. How can I move everything from the PDA back to Outlook again? Please help- thanks ...

Office 2007 - HELP
I have used Word for many years and love it - not too thrilled with the changes in Office 2007, but my bigger issue is with Publisher 2007. I have an image that I have used in Word just fine - meaning, the on screen colors are correct and when printed the colors are correct. Someone sent me a Publisher file and asked me to add the image - I did this - now the image is messed up - the colors are correct on screen, but when printed FROM MY computer the image colors are all wrong - but if I transport the file to a different computer it prints fine I have reinstalled Office - no good Any id...

Installation Problem!!
I am having a problem installing MSCRM 1.2. My configuration consists of a Domain Controller running Win 2000 Server SP4 . I am trying to install MSCRM on a member of the domain running Windows 2000 Server SP4. There is a DNS Server on the DC which is integrated with AD, and a SQL Server 2000 running on the Win 2K machine. The install errors out when CRM creates the root business with the message: Setup was unable to install Microsoft CRM Server. Setup was unable to provision your organization. Setup was unable to create the root business. The configuration of ASP.NET seems to be ok, the pr...

Problems Creating a disclaimer in Exchange 2003
I am trying to create a server based disclaimer that will stamp all of my smtp emails going to the internet. I have been following KB article 317680 with no luck. I get an error like the one below. Binding Display Name Specified: smtpscriptinghost ** Registration Failed ** Err.Number (HRESULT) = 0x1AD Err.Description = ActiveX component can't create object ProgID = cdo.ss_smtponarrival COM Category = {FF3CAA23-00B9-11d2-9DFB-00C04FA322BA} Corresponding Event = onarrival ** Have you registered your sink COM class on this machine? I am puttin...

Resource editor problems
Hello all, Under VC++ 7.1... Please consider these two lines: IDC_ARROW_ADD_CANCEL DISCARDABLE "res\\cur00004.cur" IDC_ARROW_ADD_CANCEL CURSOR DISCARDABLE "res\\cur00004.cur" The second is a hand-edited change to the first. Both will compile just fine in the resource compiler. However, after I use a text editor to make this change, I cannot open the .rc file in the resource editor. The resource editor issues the following error open attempting to open the .rc file: error RC2135 : file not found: CURSOR Can anyone shed light on what's going on here? Thanks, Dave ...

Directory Replication Problem #2
Hi, recently my Exchange Server directory database receives changes from other servers but does not send out its own changes. Check from the knowledge base, to correct the USN discrepancy need to use Authrest.exe (need to amke changes for about 100+ users). Does anybody know where to get this file 'Authrest.exe' for exchange server 5.5? Exchange server 5.5 CD only provide this file for ver.4.0. Have anyone use it before? Regards, "Sharon Tan" <sharon_tansk@yahoo.com.sg> wrote: >Hi, recently my Exchange Server directory database >receives changes from ot...

Cell Format
I have a spreadsheet with cells that I'm trying to type the date into. I type in the date exactly like this: 09/26/03. When I hit "enter" MS Excel displays "37890" in the cell. No matter what I do I can't the cell to show: 09/26/03. I think that somehow I need to "strip" the cell of what it's original format is, but I can't figure out how. I try to use the Date option in the format cell screen but it doesn't work. Curtis I tried this and it didn't work. I also tried the "Text to columns" feature. No success. >...

User Defined Variables in MS query cause a problem to import data
If I use user defined variables in MS query to import data into excel sheet, the query executes but no data gets imported into the excel sheet. If I get rid of the variable the results can be imported into the Excel sheet. ...

Any way to view users passwords in server 2003 AD ?
Is there any way to view users passwords in Server 2003 AD ? We run a server 2003 SP2 domain, us Administrators have a list of all users password on a spreadsheet, locked up. We need their passwords in the event we must sign onto their computers as an admin while they are away, we log back into the computer with their user name/password when done. You would be surprised how many people "do not" look at the user name when they log on - we had panic --- I can not log in, we go to their desktop and the user name is that of one of the administrators - user did not look. ...

outlook web access redirect problem
hi, I have been trying to redirect outlook web access (OWA) from the IIS root folder to the /exchange folder. I have followed the instructions on going into the web site and redirecting to a folder but I just get the following URL when I browse to the root of my webserver : http://webmail/exchange/exchange - it's like it's doubling up somehow. I have it set to : A redirection to a URL redirect to: /exchange client will be sent to: A directory below URL entered I just can't work it out... any ideas... cheers Baronne Which instructions did you follow? I wrote the below articl...

Problem after sorting
In my Excel 2007 workbook I have two sheets The "Master Names" sheet has columns: (A) First|(B) Last (C) First (B) Last (concatenated) The "Selected Names" sheet contains (A) cells which link to selected (C) First Last (concatenated) cells in the Master Names sheet. Everything links and displays fine except when I add names to the bottom of the Master Names sheet and then sort using (B) Last name column. When I do this I get a 0 (zero) in the (A) First Second cells in the Selected names sheet and other cells in this sheet have the wrong name. Obviously I am doin...

Initializing a user-defined type
Is there any quick way to initialize such a type when all the elements in it are the same e.g. Public Type typDates Date1 As Date Date2 As Date Date3 As Date Date4 As Date Date5 As Date End Type I'm not sure what you have in mind when you say you want to quickly initialize the elements, but... When you declare a variable as your type, its elements will be initialised to zero (as each element is a date type), as demonstrated by the following example: Public Type typDates Date1 As Date Date2 As Date Date3 As Date Date4 As Date Date5 As Date End Type Publi...