Click here to Skip to main content
16,004,833 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How do I add a menu to a dialog ? Pin
Michael Martin7-May-02 3:24
professionalMichael Martin7-May-02 3:24 
GeneralRe: How do I add a menu to a dialog ? Pin
yarp7-May-02 6:38
yarp7-May-02 6:38 
GeneralPostMessage Pin
Sameer Maggon6-May-02 22:39
Sameer Maggon6-May-02 22:39 
GeneralRe: PostMessage Pin
PJ Arends6-May-02 22:51
professionalPJ Arends6-May-02 22:51 
GeneralRe: PostMessage Pin
Hans Ruck6-May-02 22:50
Hans Ruck6-May-02 22:50 
GeneralRe: PostMessage Pin
Niklas L6-May-02 22:52
Niklas L6-May-02 22:52 
GeneralRe: PostMessage Pin
6-May-02 23:02
suss6-May-02 23:02 
GeneralRe: PostMessage Pin
Jonathan Craig7-May-02 5:06
Jonathan Craig7-May-02 5:06 
Yes, I do this in a lot of my applications. Especially in multi-threaded apps where you should only post messages between threads. Here is an example posting a CString.

Note you should allocate whatever you wish to post. It can be any kind of object.
//Somewhere in code.
...
    CString *pStr = new CString();
    *pStr = "Set String Here!";
 
    //NOTE: Receiver of this message must delete pointer!!!
    pMyView->PostMessage(WM_MY_MSG, 0, (LPARAM)pStr);
...
Note that the receiver of this message MUST free the allocated memory.
LRESULT CMyView::OnHandleMyMsg(WPARAM wParam, LPARAM lParam)
{
    CString *pStr = (CString *)lParam;
    if(pStr)
    {
        //Do something with the string...
 
        //We must delete it when done!!!
        delete pStr;
    }
    return 0;
}
This last step is important. Before the window is destroyed, check for any unhandled messages and delete their memory.
void CMyView::OnDestroy() 
{
    //Look for any WM_MY_MSG left in the queue. These have
    // pointers to allocated memory that must be freed or we will
    // have leaks!
    MSG msg;
    while(::PeekMessage(&msg, (HWND)NULL, WM_MY_MSG, WM_MY_MSG, PM_REMOVE))
    {
        CString *pStr = (CString *)msg.lParam;
        if(pStr)
            delete pStr;
    }
    CView::OnDestroy();
}
Hope this helps. Smile | :)

Jonathan Craig
www.mcw-tech.com
QuestionCombine CListBox & CEdit? Pin
6-May-02 21:43
suss6-May-02 21:43 
AnswerRe: Combine CListBox & CEdit? Pin
PJ Arends6-May-02 21:54
professionalPJ Arends6-May-02 21:54 
AnswerRe: Combine CListBox & CEdit? Pin
Niklas L6-May-02 22:34
Niklas L6-May-02 22:34 
GeneralRe: Combine CListBox & CEdit? Pin
6-May-02 22:53
suss6-May-02 22:53 
GeneralRe: Combine CListBox & CEdit? Pin
Niklas L6-May-02 22:57
Niklas L6-May-02 22:57 
GeneralRe: Combine CListBox & CEdit? Pin
6-May-02 23:05
suss6-May-02 23:05 
Generalstd::map's cost Pin
dannywidjaya6-May-02 21:43
dannywidjaya6-May-02 21:43 
GeneralRe: std::map's cost Pin
Paul M Watt6-May-02 21:49
mentorPaul M Watt6-May-02 21:49 
GeneralRe: std::map's cost Pin
Joaquín M López Muñoz6-May-02 22:18
Joaquín M López Muñoz6-May-02 22:18 
GeneralRe: std::map's cost Pin
dannywidjaya7-May-02 1:12
dannywidjaya7-May-02 1:12 
QuestionHow to create delay. Pin
Chanda.com6-May-02 21:32
Chanda.com6-May-02 21:32 
AnswerRe: How to create delay. Pin
Paul M Watt6-May-02 21:46
mentorPaul M Watt6-May-02 21:46 
GeneralRe: How to create delay. Pin
Chanda.com6-May-02 22:04
Chanda.com6-May-02 22:04 
GeneralRe: How to create delay. Pin
Sameer Maggon6-May-02 22:27
Sameer Maggon6-May-02 22:27 
GeneralTime Delay in rendering(DirectX) Pin
VCRamesh6-May-02 21:26
VCRamesh6-May-02 21:26 
GeneralRe: Time Delay in rendering(DirectX) Pin
Sameer Maggon7-May-02 0:06
Sameer Maggon7-May-02 0:06 
GeneralRe: Time Delay in rendering(DirectX) Pin
VCRamesh7-May-02 1:51
VCRamesh7-May-02 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.