post CString as message parameter

What is the best way to pass CString as message parameters? For example

CString mystring;
CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?

Thanks,

John
0
homecurr (16)
6/9/2004 3:22:19 PM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
989 Views

Similar Articles

[PageSpeed] 21

homecurr@yahoo.com wrote:

> What is the best way to pass CString as message parameters? For example
> 
> CString mystring;
> CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
> 
> Thanks,
> 
> John

	If your application has the need to do this, I *strongly* recommend you 
evaluate your design. It poses all kinds of problems, like where and how 
do you allocate memory? Where and how do you free it? In the case of 
objects, how do you perform lifetime management?

	Why not have a "queue" where you deposit messages? Then the 
"MY_MESSAGE" can simply serve as an indication: "There's something in 
the queue for you!"

	If you still want to pass string data, you could pass a pointer (to 
either a CString to an  ASCII/UNICODE null-terminated string) via LPARAM.

	-n
0
nikb (49)
6/9/2004 3:26:57 PM
CString * s = new CString;

s->Format(_T("The result is %d"), result);

Note that the syntax 
CMyWindow::PostMessage
makes no sense. If you are in CMyWindow, it is useless; if you are in a subclass of
CMyWindow, you should not be calling the superclass method, and if you are in some other
class, it won't even compile.

I will assume this is in a method of CMyWindow:

PostMessage(MY_MESSAGE, (WPARAM)s);

Note that you must, in the handler for MY_MESSAGE, do a delete on the string (unless, for
some reason, you have stored that pointer in a place that will be deleted later)

LRESULT CMyWindow::OnMyMessage(WPARAM wParam, LPARAM)
   {
     CString * s = (CString *)wParam;
     ... do something with the CString here
     delete s;
     return 0;
   }

In the case where I'm adding to a ComboBox in which I do not have LBS_HASSTRINGS, I would
do

    CString * s = (CString *)wParam;
    c_Log.AddString(s);
    return 0;

where I would define

int CMyLog::AddString(CString * s)
    {
     return CComboBox::AddString((LPCTSTR)s);
    }

The owner-draw combobox then stores the CString * in its ItemData field, and I would have
a DeleteItem handler that took the itemdata, cast it back to a CString *, and did a
delete.

As already pointed out, if you are crossing DLL boundaries, you can get into trouble if
you've done something really bad, like using static linking. But in an ordinary MFC app,
in the absence of any static linking, memory allocation is a non-issue.
					joe

On 9 Jun 2004 08:22:19 -0700, homecurr@yahoo.com wrote:

>What is the best way to pass CString as message parameters? For example
>
>CString mystring;
>CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
>
>Thanks,
>
>John

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)
6/9/2004 4:29:42 PM
One other thing to note from what the others have posted.

If this application is going to run on a Win9x system, using WPARAM to pass
32 bits will not work.  You'll lose the upper 16bits when you get to your
handler (regardless of what you are trying to pass).   Only WinNt, 2000, XP
support 32bits on the WPARAM.   Use LPARAM instead.

Relv

<homecurr@yahoo.com> wrote in message
news:2d5d0ce4.0406090722.7cb5706d@posting.google.com...
> What is the best way to pass CString as message parameters? For example
>
> CString mystring;
> CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
>
> Thanks,
>
> John


0
m7217 (49)
6/9/2004 5:39:00 PM
WRONG!!!!!!

All Windows systems use 32-bit WPARAM, and they DO NOT lose the high-order bits! You are
confusing Win9x with Win16.

I have code running regulary on Win9x that relies on 32-bit WPARAM, and it works just
fine.

				joe

On Wed, 9 Jun 2004 11:39:00 -0600, "Relvinian" <m@msn.com> wrote:

>One other thing to note from what the others have posted.
>
>If this application is going to run on a Win9x system, using WPARAM to pass
>32 bits will not work.  You'll lose the upper 16bits when you get to your
>handler (regardless of what you are trying to pass).   Only WinNt, 2000, XP
>support 32bits on the WPARAM.   Use LPARAM instead.
>
>Relv
>
><homecurr@yahoo.com> wrote in message
>news:2d5d0ce4.0406090722.7cb5706d@posting.google.com...
>> What is the best way to pass CString as message parameters? For example
>>
>> CString mystring;
>> CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
>>
>> Thanks,
>>
>> John
>

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)
6/9/2004 6:42:07 PM
I am not Joseph.   Try it sometime and see what happens.  Pass a 32bit
WPARAM in Win98 in a message and look at the result.  You will lose the
upper 16bits.

Relv

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:k4mec0ds88b59ujprq5ndfa9cdgsf9q6tg@4ax.com...
> WRONG!!!!!!
>
> All Windows systems use 32-bit WPARAM, and they DO NOT lose the high-order
bits! You are
> confusing Win9x with Win16.
>
> I have code running regulary on Win9x that relies on 32-bit WPARAM, and it
works just
> fine.
>
> joe
>
> On Wed, 9 Jun 2004 11:39:00 -0600, "Relvinian" <m@msn.com> wrote:
>
> >One other thing to note from what the others have posted.
> >
> >If this application is going to run on a Win9x system, using WPARAM to
pass
> >32 bits will not work.  You'll lose the upper 16bits when you get to your
> >handler (regardless of what you are trying to pass).   Only WinNt, 2000,
XP
> >support 32bits on the WPARAM.   Use LPARAM instead.
> >
> >Relv
> >
> ><homecurr@yahoo.com> wrote in message
> >news:2d5d0ce4.0406090722.7cb5706d@posting.google.com...
> >> What is the best way to pass CString as message parameters? For example
> >>
> >> CString mystring;
> >> CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
> >>
> >> Thanks,
> >>
> >> John
> >
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm


0
m7217 (49)
6/9/2004 10:03:04 PM
"Nikolaos D. Bougalis" <nikb@webmaster.com> wrote in message news:<6%Fxc.675$tI2.486@fed1read07>...
> homecurr@yahoo.com wrote:
> 
> > What is the best way to pass CString as message parameters? For example
> > 
> > CString mystring;
> > CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
> > 
> > Thanks,
> > 
> > John
> 
> 	If your application has the need to do this, I *strongly* recommend you 
> evaluate your design. It poses all kinds of problems, like where and how 
> do you allocate memory? Where and how do you free it? In the case of 
> objects, how do you perform lifetime management?
> 
> 	Why not have a "queue" where you deposit messages? Then the 
> "MY_MESSAGE" can simply serve as an indication: "There's something in 
> the queue for you!"
> 
> 	If you still want to pass string data, you could pass a pointer (to 
> either a CString to an  ASCII/UNICODE null-terminated string) via LPARAM.
> 
> 	-n

Is that a kind of "Reinvent the wheel", since MFC should already has that.
0
homecurr (16)
6/9/2004 10:30:18 PM
homecurr@yahoo.com wrote:

> "Nikolaos D. Bougalis" <nikb@webmaster.com> wrote in message news:<6%Fxc.675$tI2.486@fed1read07>...
> 
>>homecurr@yahoo.com wrote:
>>
>>
>>>What is the best way to pass CString as message parameters? For example
>>>
>>>CString mystring;
>>>CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
>>>
>>>Thanks,
>>>
>>>John
>>
>>	If your application has the need to do this, I *strongly* recommend you 
>>evaluate your design. It poses all kinds of problems, like where and how 
>>do you allocate memory? Where and how do you free it? In the case of 
>>objects, how do you perform lifetime management?
>>
>>	Why not have a "queue" where you deposit messages? Then the 
>>"MY_MESSAGE" can simply serve as an indication: "There's something in 
>>the queue for you!"
>>
>>	If you still want to pass string data, you could pass a pointer (to 
>>either a CString to an  ASCII/UNICODE null-terminated string) via LPARAM.
>>
>>	-n
> 
> 
> Is that a kind of "Reinvent the wheel", since MFC should already has that.

	That depends, really. MFC may internally route messages, and even mask 
the default Windows messages that pass around strings, but that does not 
mean that it's good programming practice.

	Passing around strings in messages can be problematic. I gave a few 
examples as to why:

	- If you want to send a message to a different process, you need to do 
tricks to get the buffer to be valid in the remote process.

	- You and the receiver must agree about who allocates and who 
deallocates memory, as well as how to do that.

	- Continual allocations and deallocations for what are typically small 
strings tend to fragment the heap. Granted, the heap manager is pretty 
smart about this, and might remain largely unaffected.
	
	Sometimes, reinventing the wheel makes sense.

	-n
0
nikb (49)
6/10/2004 12:28:06 AM
Scott McPhillips [MVP] wrote:

> Nikolaos D. Bougalis wrote:
> 
>>     That depends, really. MFC may internally route messages, and even 
>> mask the default Windows messages that pass around strings, but that 
>> does not mean that it's good programming practice.
>>
>>     Passing around strings in messages can be problematic. I gave a 
>> few examples as to why:
>>
>>     - If you want to send a message to a different process, you need 
>> to do tricks to get the buffer to be valid in the remote process.
>>
>>     - You and the receiver must agree about who allocates and who 
>> deallocates memory, as well as how to do that.
>>
>>     - Continual allocations and deallocations for what are typically 
>> small strings tend to fragment the heap. Granted, the heap manager is 
>> pretty smart about this, and might remain largely unaffected.
>>         Sometimes, reinventing the wheel makes sense.
>>
>>     -n
> 
> 
> I don't see the problem and I think your points are invalid.  Your 
> interprocess point and heap fragmentation point also apply if you pass 
> strings in a queue that you design: No difference.

	About my interprocess point, how would you suggest something from 
outside process space access that queue?

	You're correct about the fragmentation. I was thinking about a specific 
implementation of this I encountered. A socket program had a statically 
sized buffer to read data into. When it got a complete "chunk" it would call

	SendMessage(hWnd, 0, strdup(chunk));

	The sender would then free(chunk). 	
	

> The appropriate plan for your second point is simple and obvious: sender 
> calls 'new' and receiver calls 'delete'.  This is an excellent way to 
> pass data between threads.  Windows gives us a nice built-in thread-safe 
> queue for each message-processing thread.
	
	I disagree that it's quite as simple as that. But you're welcome to 
your opinion.

	It's true that it's a nice built-in, thread-safe queue. It's not true 
that it's the queue for everything under the sun.

	-n
0
nikb (49)
6/10/2004 1:38:37 AM
Nikolaos D. Bougalis wrote:
>     That depends, really. MFC may internally route messages, and even 
> mask the default Windows messages that pass around strings, but that 
> does not mean that it's good programming practice.
> 
>     Passing around strings in messages can be problematic. I gave a few 
> examples as to why:
> 
>     - If you want to send a message to a different process, you need to 
> do tricks to get the buffer to be valid in the remote process.
> 
>     - You and the receiver must agree about who allocates and who 
> deallocates memory, as well as how to do that.
> 
>     - Continual allocations and deallocations for what are typically 
> small strings tend to fragment the heap. Granted, the heap manager is 
> pretty smart about this, and might remain largely unaffected.
>     
>     Sometimes, reinventing the wheel makes sense.
> 
>     -n

I don't see the problem and I think your points are invalid.  Your 
interprocess point and heap fragmentation point also apply if you pass 
strings in a queue that you design: No difference.

The appropriate plan for your second point is simple and obvious: sender 
calls 'new' and receiver calls 'delete'.  This is an excellent way to 
pass data between threads.  Windows gives us a nice built-in thread-safe 
queue for each message-processing thread.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
6/10/2004 1:49:18 AM
From Platform SDK:

Windows 95/98/Me Window Management

Messages

The wParam parameter for the SendMessageCallback, SendMessageTimeout, and
SendNotifyMessage functions is limited to a 16-bit value.

In Windows 95/98/Me, the wParam parameter in list box messages, such as
LB_INSERTSTRING or LB_SETITEMDATA, is limited to a 16-bit value. One effect
of this limit is that list boxes cannot contain more than 32,767 items.
Although the number of items is restricted, the total size, in bytes, of the
items in a list box is limited only by available memory. In contrast, a 64K
data limit is imposed by Windows version 3.1.

"Relvinian" <m@msn.com> wrote in message
news:h5OdnUNYUeqTFFrdRVn-uA@comcast.com...
> I am not Joseph.   Try it sometime and see what happens.  Pass a 32bit
> WPARAM in Win98 in a message and look at the result.  You will lose the
> upper 16bits.
>
> Relv
>
> "Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
> news:k4mec0ds88b59ujprq5ndfa9cdgsf9q6tg@4ax.com...
> > WRONG!!!!!!
> >
> > All Windows systems use 32-bit WPARAM, and they DO NOT lose the
high-order
> bits! You are
> > confusing Win9x with Win16.
> >
> > I have code running regulary on Win9x that relies on 32-bit WPARAM, and
it
> works just
> > fine.
> >
> > joe
> >
> > On Wed, 9 Jun 2004 11:39:00 -0600, "Relvinian" <m@msn.com> wrote:
> >
> > >One other thing to note from what the others have posted.
> > >
> > >If this application is going to run on a Win9x system, using WPARAM to
> pass
> > >32 bits will not work.  You'll lose the upper 16bits when you get to
your
> > >handler (regardless of what you are trying to pass).   Only WinNt,
2000,
> XP
> > >support 32bits on the WPARAM.   Use LPARAM instead.
> > >
> > >Relv
> > >
> > ><homecurr@yahoo.com> wrote in message
> > >news:2d5d0ce4.0406090722.7cb5706d@posting.google.com...
> > >> What is the best way to pass CString as message parameters? For
example
> > >>
> > >> CString mystring;
> > >> CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
> > >>
> > >> Thanks,
> > >>
> > >> John
> > >
> >
> > Joseph M. Newcomer [MVP]
> > email: newcomer@flounder.com
> > Web: http://www.flounder.com
> > MVP Tips: http://www.flounder.com/mvp_tips.htm
>
>


0
alegr (1131)
6/10/2004 2:48:21 AM
Here's t the code from a little dialog app I created called "wparam". You can create one
yourself and replace the wparamDlg files with the contents of this message, suitable
snipped out. Or send me email and I'll send the full project to anyone who wants to see it
and play with it.

I ran this on my only win98 machine, and it worked perfectly. Just to be sure, I dug out
my old Win95 laptop and ran it there perfectly as well. I see no evidence whatsoever of
any 16-bit WPARAM truncation on SendMessageCallback, SendMessageTimeout, or
SendNotifyMessage, and not on SendMessage or PostMessage on either Windows 95 or Windows
98. Like most sane people, I never looked at Me, but I very much suspect that they did not
suddenly put this feature into Me-only.

The 16-bit restriction on listboxes is a limitation on listboxes and does not apply to
other controls.

So there is not problem with WPARAM truncation. The documentation lies.

(Rather than post the entire .rc file, which has lots of boilerplate fluff in it, I've
extracted the main dialog. Paste this back into your project)

====================================================================================
IDD_WPARAM_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "wparam"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,260,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,260,23,50,14
    PUSHBUTTON      "SendMessage",IDC_SENDMESSAGE,62,8,106,14
    PUSHBUTTON      "SendMessageTImeout",IDC_SENDMESSAGETIMEOUT,62,26,106,14
    PUSHBUTTON      "SendMessageCallback",IDC_SENDMESSAGECALLBACK,62,44,106,
                    14
    PUSHBUTTON      "SendNotifyMessage",IDC_SENDNOTIFYMESSAGE,61,60,106,14
    LISTBOX         IDC_LOG,0,95,320,105,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | 
                    WS_TABSTOP

END
====================================================================================
// wparamDlg.cpp : implementation file
//

#include "stdafx.h"
#include "wparam.h"
#include "wparamDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
        CAboutDlg();

// Dialog Data
        //{{AFX_DATA(CAboutDlg)
        enum { IDD = IDD_ABOUTBOX };
        //}}AFX_DATA

        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CAboutDlg)
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
        //}}AFX_VIRTUAL

// Implementation
protected:
        //{{AFX_MSG(CAboutDlg)
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
        //{{AFX_DATA_INIT(CAboutDlg)
        //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CAboutDlg)
        //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
        //{{AFX_MSG_MAP(CAboutDlg)
                // No message handlers
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWparamDlg dialog

CWparamDlg::CWparamDlg(CWnd* pParent /*=NULL*/)
        : CDialog(CWparamDlg::IDD, pParent)
{
        //{{AFX_DATA_INIT(CWparamDlg)
        //}}AFX_DATA_INIT
        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWparamDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CWparamDlg)
        DDX_Control(pDX, IDC_LOG, c_Log);
        //}}AFX_DATA_MAP
}

static UINT UWM_TESTSENDMESSAGE = ::RegisterWindowMessage(_T("UWM_TESTSENDMESSAGE"));
static UINT UWM_TESTCALLBACK = ::RegisterWindowMessage(_T("UWM_TESTCALLBACK"));
static UINT UWM_TESTSENDMESSAGETIMEOUT =
::RegisterWindowMessage(_T("UWM_TESTSENDMESSAGETIMEOUT"));
static UINT UWM_TESTSENDNOTIFYMESSAGE =
::RegisterWindowMessage(_T("UWM_TESTSENDNOTIFYMESSAGE"));
static UINT UWM_LOG = ::RegisterWindowMessage(_T("UWM_LOG"));

BEGIN_MESSAGE_MAP(CWparamDlg, CDialog)
        //{{AFX_MSG_MAP(CWparamDlg)
        ON_WM_SYSCOMMAND()
        ON_WM_PAINT()
        ON_WM_QUERYDRAGICON()
        ON_BN_CLICKED(IDC_SENDMESSAGE, OnSendmessage)
        ON_BN_CLICKED(IDC_SENDMESSAGETIMEOUT, OnSendmessagetimeout)
        ON_BN_CLICKED(IDC_SENDMESSAGECALLBACK, OnSendmessagecallback)
        ON_BN_CLICKED(IDC_SENDNOTIFYMESSAGE, OnSendnotifymessage)
        //}}AFX_MSG_MAP
        ON_REGISTERED_MESSAGE(UWM_TESTSENDMESSAGE, OnTestSendMessage)
        ON_REGISTERED_MESSAGE(UWM_TESTSENDMESSAGETIMEOUT, OnTestSendMessageTimeout)
        ON_REGISTERED_MESSAGE(UWM_TESTCALLBACK, OnTestCallback)
        ON_REGISTERED_MESSAGE(UWM_LOG, OnLog)
        ON_REGISTERED_MESSAGE(UWM_TESTSENDNOTIFYMESSAGE, OnTestSendNotifyMessage)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWparamDlg message handlers

BOOL CWparamDlg::OnInitDialog()
{
        CDialog::OnInitDialog();

        // Add "About..." menu item to system menu.

        // IDM_ABOUTBOX must be in the system command range.
        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
        ASSERT(IDM_ABOUTBOX < 0xF000);

        CMenu* pSysMenu = GetSystemMenu(FALSE);
        if (pSysMenu != NULL)
        {
                CString strAboutMenu;
                strAboutMenu.LoadString(IDS_ABOUTBOX);
                if (!strAboutMenu.IsEmpty())
                {
                        pSysMenu->AppendMenu(MF_SEPARATOR);
                        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
                }
        }

        // Set the icon for this dialog.  The framework does this automatically
        //  when the application's main window is not a dialog
        SetIcon(m_hIcon, TRUE);                 // Set big icon
        SetIcon(m_hIcon, FALSE);                // Set small icon
        
        // TODO: Add extra initialization here
        
        return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWparamDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
        if ((nID & 0xFFF0) == IDM_ABOUTBOX)
        {
                CAboutDlg dlgAbout;
                dlgAbout.DoModal();
        }
        else
        {
                CDialog::OnSysCommand(nID, lParam);
        }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWparamDlg::OnPaint() 
{
        if (IsIconic())
        {
                CPaintDC dc(this); // device context for painting

                SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

                // Center icon in client rectangle
                int cxIcon = GetSystemMetrics(SM_CXICON);
                int cyIcon = GetSystemMetrics(SM_CYICON);
                CRect rect;
                GetClientRect(&rect);
                int x = (rect.Width() - cxIcon + 1) / 2;
                int y = (rect.Height() - cyIcon + 1) / 2;

                // Draw the icon
                dc.DrawIcon(x, y, m_hIcon);
        }
        else
        {
                CDialog::OnPaint();
        }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWparamDlg::OnQueryDragIcon()
{
        return (HCURSOR) m_hIcon;
}

/****************************************************************************
*                          CWparamDlg::OnSendmessage
* Result: void
*       
* Effect: 
*       Sends a UWM_TESTSENDMESSAGE message with a 32-bit WPARAM and LPARAM to the window
****************************************************************************/

void CWparamDlg::OnSendmessage() 
{
SendMessage(UWM_TESTSENDMESSAGE, 0x12345678, 0x87654321 );      
}

/****************************************************************************
*                        CWparamDlg::OnTestSendMessage
* Inputs:
*       WPARAM: a 32-bit value
*       LPARAM: a 32-bit value
* Result: LRESULT
*       1, always
* Effect: 
*       Formats the WPARAM and LPARAM and adds them to the Log
****************************************************************************/

LRESULT CWparamDlg::OnTestSendMessage(WPARAM wParam, LPARAM lParam)
{
     CString s;
     s.Format(_T("SendMessage: WPARAM %08x, LPARAM %08x"), wParam, lParam);
     c_Log.AddString(s);
     return 1;
}

/****************************************************************************
*                    CWparamDlg::OnTestSendMessageTimeout
* Inputs:
*       WPARAM wParam: a 32-bit value
*       LPARAM lParam: a 32-bit value
* Result: LRESULT
*       1, always
* Effect: 
*       Formats its WPARAM and LPARAM and adds the string to the listbox
****************************************************************************/

LRESULT CWparamDlg::OnTestSendMessageTimeout(WPARAM wParam, LPARAM lParam)
{
     CString s;
     s.Format(_T("SendMessageTimeout: WPARAM %08x, LPARAM %08x"), wParam, lParam);
     c_Log.AddString(s);
     return 1;
}

/****************************************************************************
*                      CWparamDlg::OnSendmessagetimeout
* Result: void
*       
* Effect: 
*       Sends a UWM_TESTSENDMESSAGETIMEOUT to this thread with a 32-bit
*       WPARAM and LPARAM
****************************************************************************/

void CWparamDlg::OnSendmessagetimeout() 
{
 DWORD result;
 SendMessageTimeout(m_hWnd, UWM_TESTSENDMESSAGETIMEOUT, 0x87654321, 0x12345678 , 0,
INFINITE, &result); 
}

/****************************************************************************
*                                  callback
* Inputs:
*       HWND hWnd: Window for which the callback is being done
*       UINT msg: message that was sent
*       DWORD data: Parameter that was sent via SendMessageCallback
*       LRESULT result: The result of the handler.
* Result: void
*       
* Effect: 
*       Formats the text and adds it to the listbox
*               The data is assumed to be a constant LPCTSTR
*               The result is assumed to be a CString * that must be deleted
****************************************************************************/

static void CALLBACK callback(HWND hWnd, UINT msg, DWORD data, LRESULT result)
{
   CString * s = new CString;
   CString * res = (CString *)result;
   s->Format(_T("SendMessageTimeout [callback] data = %s, result=%s"),
                     (LPCTSTR)data,
                     *res);
   delete res;

   ::PostMessage(hWnd, UWM_LOG, (WPARAM)s, 0);
}

/****************************************************************************
*                      CWparamDlg::OnSendmessagecallback
* Result: void
*       
* Effect: 
*       Does a SendMessageCallback, passing a 32-bit WPARAM, a 32-bit LPARAM,
*       and for the callback argument a literal string "Hello"
****************************************************************************/

void CWparamDlg::OnSendmessagecallback() 
{
 SendMessageCallback(m_hWnd, UWM_TESTCALLBACK, 0x18726354, 0x81726543, callback,
(DWORD)_T("Hello"));   
}

/****************************************************************************
*                         CWparamDlg::OnTestCallback
* Inputs:
*       WPARAM wParam: a 32-bit value
*       LPARAM lParam: a 32-bit value
* Result: LRESULT
*       (LRESULT)(CString *) the same string that was added to the log
* Effect: 
*       Formats the wparam and lparam and adds them to the log, then
*       returns a pointer to a freshly-allocated CString *
****************************************************************************/

LRESULT CWparamDlg::OnTestCallback(WPARAM wParam, LPARAM lParam)
{
     CString * s = new CString;
     s->Format(_T("SendMessageCallback: WPARAM %08x, LPARAM %08x"), wParam, lParam);
     c_Log.AddString(*s);
     return (LRESULT)s;

}

/****************************************************************************
*                              CWparamDlg::OnLog
* Inputs:
*       WPARAM wParam: (WPARAM)(CString *) data to add to log
* Result: LRESULT
*       0, always
* Effect: 
*       Adds the string to the log
****************************************************************************/

LRESULT CWparamDlg::OnLog(WPARAM wParam, LPARAM)
{
    CString * s = (CString *)wParam;
    c_Log.AddString(*s);
    delete s;
    return 0;
}

/****************************************************************************
*                                 threadproc
* Inputs:
*       LPVOID p: (LPVOID)(CWparamDlg*)
* Result: UINT
*       0, always
* Effect: 
*       Does a cross-thread SendNotifyMessage
****************************************************************************/

UINT threadproc(LPVOID p)
    {
     CWparamDlg * wnd = (CWparamDlg *)p;

     SendNotifyMessage(wnd->m_hWnd, UWM_TESTSENDNOTIFYMESSAGE, 0x87651234, 0x43215678);
     return 0;
    } // threadproc


/****************************************************************************
*                       CWparamDlg::OnSendnotifymessage
* Result: void
*       
* Effect: 
*       Launches a thread that fires off a SendNotifyMessage
****************************************************************************/

void CWparamDlg::OnSendnotifymessage() 
{
 AfxBeginThread(threadproc, this);
}

/****************************************************************************
*                     CWparamDlg::OnTestSendNotifyMessage
* Inputs:
*       WPARAM: a 32-bit value
*       LPARAM: a 32-bit value
* Result: LRESULT
*       0, always
* Effect: 
*       Logs the message
****************************************************************************/

LRESULT CWparamDlg::OnTestSendNotifyMessage(WPARAM wParam, LPARAM lParam)
    {
     CString s;
     s.Format(_T("SendNotifyMessage: WPARAM %08x, LPARAM %08x"), wParam, lParam);
     c_Log.AddString(s);
     return 0;
    } // CWparamDlg::OnTestSendNotifyMessage
=============================================================================================
// wparamDlg.h : header file
//

#if !defined(AFX_WPARAMDLG_H__498FFA73_7D6F_4E43_8AF4_547C83644EDB__INCLUDED_)
#define AFX_WPARAMDLG_H__498FFA73_7D6F_4E43_8AF4_547C83644EDB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CWparamDlg dialog

class CWparamDlg : public CDialog
{
// Construction
public:
        CWparamDlg(CWnd* pParent = NULL);       // standard constructor

// Dialog Data
        //{{AFX_DATA(CWparamDlg)
        enum { IDD = IDD_WPARAM_DIALOG };
        CListBox        c_Log;
        //}}AFX_DATA

        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CWparamDlg)
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);        // DDX/DDV support
        //}}AFX_VIRTUAL

// Implementation
protected:
        HICON m_hIcon;
        afx_msg LRESULT OnTestSendMessage(WPARAM, LPARAM);
        afx_msg LRESULT OnTestCallback(WPARAM, LPARAM);
        afx_msg LRESULT OnTestSendMessageTimeout(WPARAM, LPARAM);
        afx_msg LRESULT OnTestSendNotifyMessage(WPARAM, LPARAM);
        afx_msg LRESULT OnLog(WPARAM, LPARAM);
        // Generated message map functions
        //{{AFX_MSG(CWparamDlg)
        virtual BOOL OnInitDialog();
        afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
        afx_msg void OnPaint();
        afx_msg HCURSOR OnQueryDragIcon();
        afx_msg void OnSendmessage();
        afx_msg void OnSendmessagetimeout();
        afx_msg void OnSendmessagecallback();
        afx_msg void OnSendnotifymessage();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the
previous line.

#endif // !defined(AFX_WPARAMDLG_H__498FFA73_7D6F_4E43_8AF4_547C83644EDB__INCLUDED_)
=============================================================================================


On Wed, 9 Jun 2004 19:48:21 -0700, "Alexander Grigoriev" <alegr@earthlink.net> wrote:

>From Platform SDK:
>
>Windows 95/98/Me Window Management
>
>Messages
>
>The wParam parameter for the SendMessageCallback, SendMessageTimeout, and
>SendNotifyMessage functions is limited to a 16-bit value.
>
>In Windows 95/98/Me, the wParam parameter in list box messages, such as
>LB_INSERTSTRING or LB_SETITEMDATA, is limited to a 16-bit value. One effect
>of this limit is that list boxes cannot contain more than 32,767 items.
>Although the number of items is restricted, the total size, in bytes, of the
>items in a list box is limited only by available memory. In contrast, a 64K
>data limit is imposed by Windows version 3.1.
>
>"Relvinian" <m@msn.com> wrote in message
>news:h5OdnUNYUeqTFFrdRVn-uA@comcast.com...
>> I am not Joseph.   Try it sometime and see what happens.  Pass a 32bit
>> WPARAM in Win98 in a message and look at the result.  You will lose the
>> upper 16bits.
>>
>> Relv
>>
>> "Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>> news:k4mec0ds88b59ujprq5ndfa9cdgsf9q6tg@4ax.com...
>> > WRONG!!!!!!
>> >
>> > All Windows systems use 32-bit WPARAM, and they DO NOT lose the
>high-order
>> bits! You are
>> > confusing Win9x with Win16.
>> >
>> > I have code running regulary on Win9x that relies on 32-bit WPARAM, and
>it
>> works just
>> > fine.
>> >
>> > joe
>> >
>> > On Wed, 9 Jun 2004 11:39:00 -0600, "Relvinian" <m@msn.com> wrote:
>> >
>> > >One other thing to note from what the others have posted.
>> > >
>> > >If this application is going to run on a Win9x system, using WPARAM to
>> pass
>> > >32 bits will not work.  You'll lose the upper 16bits when you get to
>your
>> > >handler (regardless of what you are trying to pass).   Only WinNt,
>2000,
>> XP
>> > >support 32bits on the WPARAM.   Use LPARAM instead.
>> > >
>> > >Relv
>> > >
>> > ><homecurr@yahoo.com> wrote in message
>> > >news:2d5d0ce4.0406090722.7cb5706d@posting.google.com...
>> > >> What is the best way to pass CString as message parameters? For
>example
>> > >>
>> > >> CString mystring;
>> > >> CMyWindow::PostMessage(MY_MESSAGE, (WPARAM)mystring, (LPARAM)0)?
>> > >>
>> > >> Thanks,
>> > >>
>> > >> John
>> > >
>> >
>> > Joseph M. Newcomer [MVP]
>> > email: newcomer@flounder.com
>> > Web: http://www.flounder.com
>> > MVP Tips: http://www.flounder.com/mvp_tips.htm
>>
>>
>

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)
6/10/2004 5:35:30 AM
Reply:

Similar Artilces:

counting email messages being sent out
I am new to exchange 2003 administration. Is there a tool within MS Exchange 2003 that can bring up a count of how many emails were sent out for a particular time frame? Or is there a utility to download that can be used? Performance Monitor has lots of exchange counters. Try there. Vince -- Vince "Rob" wrote: > I am new to exchange 2003 administration. Is there a tool within MS Exchange > 2003 that can bring up a count of how many emails were sent out for a > particular time frame? Or is there a utility to download that can be used? Vince, Thanks for the heads up...

item stock inquiry error message
when I try to do an item stock inquiry, the following message pops up "An open operation on table 'tcsSYSTB00000_WindowsParams' failed accessing SQL data." when I clink to show more info, this is shown "[Microsoft][SQL Native Client][SQL Server]CREATE TABLE permission denied in database 'DAI'." Any idea how to fix this issue? Thanks - That sounds like a Trinity Computer Services table - have you asked them about this? -- Victoria Yudin Dynamics GP MVP Want to use Crystal Reports with GP? http://www.flex-solutions.com/gpreports.html blog: http://ww...

Posting old bills
I am setting up Money 2006 to tract income and expenses for a rental property, but I need to back date it to 1/1/2007. How do I enter bills and deposits made in the past? Thanks Go to the account register and enter the manually. Just click on the next blank transaction and go to town. You may want to make sure you are using Advanced Register. If there are subsequent transactions already in these accounts and you have balanced the accounts to statements--as though these transactions were already entered--then you will have to adjust account beginning balances and/or Account Adjustment...

* OWA... (Third Post)
Microsoft? If you're concerned about security then you should respond to this question. We cannot make this OWA server available on the Internet without applying the latest SP and critical updates. =========================== Our OWA Exchange 5.5 server (Windows NT Server) recently died and we replaced it with a Windows 2000 Server. We installed Exchange 5.5 OWA then applied Exchange SP4. Everything was working until we apply Windows 2000 SP4. Everytime we logon we get "OWA was unable to get to your inbox" error. As soon as we un-installed Windows 2000 SP4, OWA wo...

To the sender of the MI5 posts
I am not sure if you read responses or (like most other spammers) just see the web as a place where you are free to say whatever you want without fear of contradiction. Who knows? Either way - this section of this site is site is specifically here so that anyone with a comment, question, point to rise, etc regarding access databases can post with the knowledge that other likeminded people may read their post. It is not here as a general forum to discuss other matters. I have no doubt that if you are blocked from posting you will see this as yet another indication that MI5 is after yo...

OL07 keyboard "short"cuts in the Message Window?
In OL03, I was able to change the account to send a message with Alt+N followed by the number. Now, it seems, the shortcut is Alt+H,Y,1 followed by the number. Similarly, to send a message, I would use Alt+S. Now I have the choice of Alt+H,S or Alt+F,E. (Or Ctl-ENTER, I suppose.) Is there anything I can do to make OL07 use shorter shortcuts? Alt+S should still work... -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook ...

Outlook Message Inline Text
I have Outlook 2002 and need to know if I can change my received message format to inline text. Right now I have e-mails that have been forwarded multiple times as attachments instead of inline text but I can't synchronize it with my Pocket PC because of this. Any Suggestions? Thanks, Benny ...

What's the difference between Cross-posting and Multi-posting
And thanks for the discussion earlier... although the rudeness was unneeded. Sign me, A New User (and learning from you all) rochgal, you wrote on Thu, 22 Sep 2005 14:53:03 -0700: > What's the difference between Cross-posting and Multi-posting Cross-posting = You send one posting to several newsgroups. Multi-posting = You send several postings (with the same content) to several newsgroups. -- Best Regards Christian Goeller Some misspellings, grammatical or linguistical mistakes found? All corrections would be appreciated! ...

Post to GL
Hello I am having a problem with a setting within Great Plains 8.0 service pack 2. I have posting setup to only allow posting from the batch level for Inventory. But when you go into Inventory Batches the check box for post to gl is not marked. If I have it setup in posting to post to the gl shouldn't this check box be marked in inventory batches? -- Thanks, Brian Apples and oranges. The post to GL checkbox on the inventory batch window tells the system whether an IV transaction will post at all. The posting settings in tools --> setup --> posting tell the system w...

Intrastat posting issue
We are a UK company using intrastat. At the moment we cannot post invoices directly (thru) to the General ledger because we are getting an error saying that the 'intratsat information is missing'. When we click on an invoice that won't post in the Sales Transaction Entry screen, and click on the blue EC flag box, all the intrastat data is there and correct. Then when we post it goes through to the GL correctly. It seems that it will only post to the GL if every single line is checked (via the Blue EC flag) on the sales invoice regardless of the fact that all the date is alr...

Access 2002 bug: "dynamic" forms problem
There was no respond to my original post in microsoft.public.access.forms (May 5th 2007) about a fortnight so I try it here... ��������������������������������� A while ago we had a discussion about A2002 (sub)form which changes dynamically from code (hide/unhide controls, change subfom's width, etc.). There's a problem if I make some changes in code when the form is open: if I save changes, A2002 saves controls positions & subform's size as well. This is a BIG A2002 BUG and it's really annoying. Why Access forms don't behave as Visual Basic forms? I don't want Acc...

where is my post??
twice now I have typed up my post & sent it. So where is it? On Wed, 18 Jul 2007 08:41:36 -0700, Stapes <steve.staple@gmail.com> wrote: >twice now I have typed up my post & sent it. So where is it? On Google Groups: 1184773041.958329.270430@e16g2000pri.googlegroups.com Google's been having some problems lately, maybe it's temporarily unavailable. John W. Vinson [MVP] You mean the multiple posts with subject "Cancel = true"? I see 3 of them, and Allen Browne's already provided an answer. -- Doug Steele, Microsoft Access MVP http://I...

Is there a way I can only print the reply instead of the entire email message
I wonder if there is a way I can only print the reply to an email message, instead of printing the entire message? My choice for selection only seem to be gone with Outlook 2003 printing options. Any help is appreciated.............Peter ...

Duplicate messages when filtering
I have created a rule to MOVE messages from one address to a subfolder, but every time these messages arrive, Outlook puts a copy of the message on the Inbox AND ALSO on the subfolder I specified on the rule. I checked the rule and the action ONLY says to MOVE the e-mail to the specified subfolder, not to leave a copy on the mais Inbox folder. I'm very annoyed by this, because I always have to go to the Inbox and delete the message copy. Any ideas? ...

Sending message 1 of ....
In general, sending is fine but I get a "Sending message 1 of X" message in the status bar which does not correspond to anything. It started with "Sending Message 1 out of 2" a few months ago. It has recently grew up to 11. The only message I get is "503 bad sequence of command". All my fellow workers, connecting to the same server with the same Outlook 2003 version do not have this issue Any idea ? ...

My post not posted!
A couple of times when I've posted a reply to a recent post (same day), and later tried to view it, I found the header with a line drawn through it, and the following in the message body view pane: Message is no longer available on the server Windows Live Mail is unable to retrieve the requested message because the server no longer has the message available. -------------------------------------------------------------------------------- News servers regularly expire articles as they get older to make space available for newer articles. IMAP servers can be accessed by multip...

Can't view Messages
I cannot view any newsgroup messages in the preview pane. The only way i can view it is to "reply" then i see the message below my reply. I have Win XP Pro, and Outlook 2003. Any help is appreciated. (My outlook / email works fine). -Matt nutshell222@hotmail.com Hi Matt, please use Outlook Express as Newsreader -- Ich habe nichts gemacht, gestern gings noch! Bitte in den Newsgroup antworten damit jeder etwas davon hat. Bravestar@Datenschutzministerium.de "Matt" <nutshell222@hotmail.com> schrieb im Newsbeitrag news:ZqadneKI2qQ5RZvcRVn-uw@warpdrive.net... > ...

Cannot send newsgroup post with an attachment
I can send and receive posts using Outlook Express 6 newsgroups. I do not use html. When I send a post that has an attachment, e.g. a 160kB jpg that post never shows up as having been sent. How can I fix this? regards, "nobody" I can't speak for others, but msnews has a 100KB limit. If I have a need to post a graphic, I upload it to TinyPic and post the link to it. TinyPic: http://tinypic.com/ -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "news.microsoft.com" <nobody@nowhere.com> wrote in message ...

Fixed Assets Error Message
I've just installed GP10 SP 1 945412 on a test server. Originally I only installed SmartList builder. I've just finished adding Fixed Assets, Analytical Accounting (and Grant Management) and Project Accounting. When I launch GP Utilities I get the following error message: Fixed Assets Product 309 does not support upgrading from version 6.0.0 or prior Does anyone know what this means? Thanks! Maatthias, If you run the following query against your DYNAMICS database, what is the result? select db_name, db_verMajor, db_verMinor, db_verBuild from DB_Upgrade wher PRODID = 309 B...

Message Recall #2
Hello, I'm using Outlook 2002 with an Exchange 5.5 server. When I attempt to recall a message sent to a local mailbox or to an external recipient, it fails with the "Your message could not be recalled" error message whether or not the message has been read and the message has not been deleted. Any resolution would be appreciated. Thank you. It's not very reliable to begin with and it should always fail to the external recipient. Does everyone internally use the same version of outlook? Does it work if they open the recall message? -- Diane Poremsky [MVP - Outloo...

New rules error message
I suddenly started receiving a "Rules in error" message "cannot remove messages from the folder". Rules seem OK. Any ideas ...

can't print outlook 2000 message
I have outlook 2000 When I print a message I get the error: an error has occurred in your program. To keep working anyway click ignore an save your work in a new file... and then the outlook is closed. what can I do print a message from outlook? I've seen this problem when printing an HTML message and trying to print to a different printer than the default printer. As long as I print to the default it works. Plain Text and RTF emails, I can print to any printer. Other option, Uninstall printer and reinstall it. "amc2" <amc2@013.net.il> wrote in message news:8b4b01...

FYI
FYI to anyone who has Ex2003 SP1. I came across this problem on my server and the hotfix resolved it. Note: I didn't have the exact problem described because my messages were getting stuck in the "Local delivery" queue, not the "Messages pending submission" queue and I never got any error events, but nonetheless the hotfix corrected it. http://support.microsoft.com/?kbid=843545 Digitally signed messages remain in the Messages pending submission queue and are not delivered in Exchange Server 2003 SP1 -- Sincerely, Martin MCSA: M I ran into the same problem, t...

Editing Sales Rep in a Posted Transaction
Does anyone know if there is a way to recall a transacrion just to change the associated sales rep? Hello Scarpa, You cannot change a transaction that has happened via the system's interface. You could modify the database using SQL or Access or a number of other tools... however that may not be the right thing to do. One of my clients was having this happen quite often... for example John sold it but it was rung up under Peter... so we created a return reason code for wrong sales rep... the cashier basically recalls the transaction for return.... picks the reason code and then eit...

Why my posting are not posted!
I am not sure why sometimes my postings are not posted! do you know why? Perhaps because you are using Microsoft's unreliable web interface to the newsgroup? Better to access the newsgroup directly, using a newsreader. -- David Biddulph "LABKHAND" <LABKHAND@discussions.microsoft.com> wrote in message news:635CB4A1-C4C9-4A80-AB93-3C8601E3F0DD@microsoft.com... >I am not sure why sometimes my postings are not posted! do you know why? "LABKHAND" <LABKHAND@discussions.microsoft.com> wrote: > I am not sure why sometimes my postings are...