Window 1 causing text on window 2

This is a discussion on Window 1 causing text on window 2 within the Windows Programming forums, part of the Platform Specific Boards category; What I would like to do is this: When a button is pushed on window 2 have text appear on ...

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Window 1 causing text on window 2

    What I would like to do is this:
    When a button is pushed on window 2 have text appear on window 1 (my main window). Both windows use a different WndProc.

    I'm thinking off the following:

    1) Process the button push under WM_COMMAND on window 2's WndProc. (done)

    2) Use SendMessage to send a message to window 1's WndProc.

    3) Process and return.

    What I'm not sure of is how to code the SendMessage. Can you define your own WM_BLAHBLAH message?

    Oh reason I want to use SendMessage over PostMessage is that I need to wait for the results of the other wndproc before I can continue.

    Anyone able to point me in the right direction?

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    That's sounds about right.
    1. Declare the window 1 handle as global
    2. Capture the button click in window 2
    3. Make your string
    4. Use GetDlgItem(hWindow1,ID_EDITCONTROL) or something to get an edit control handle
    5. Use SetWindowText to put the string there

    If you want to use TextOut() in window 1 to print the text, you'll have to SendMessage(hWindow1, WM_USER+1,blah) and pass a pointer to the string. Capture the message in the window 1 procedure and use TextOut().

    I hope that's clear enough.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    1) ID_EDITCONTROL gave me an error so couldn't use GetDlgItem
    2) SetWindowText changed the text on the title bar not inside the window.

    I've changed the program up a little and put a read only edit box in window 1 and I think it might make it easier.

    Well time for sleep. Will review in the morning and post code if I'm still not getting it.

    Thanks

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Weee got it working now. Here is snipets of my code if anyone is wondering:

    Window 2 (Process the button push who's ID # is 1:
    Code:
            case WM_COMMAND:
                    if ( LOWORD (wParam) == 1 )
                        SendMessage (hMainWin, WM_COMMAND, LOWORD (1), lParam);
                        
                    return 0;
    Window 1 (Display the text):
    Code:
            case WM_COMMAND:
                    if ( LOWORD (wParam) == 1)
                       {
                       ScrollWindow (hMainWin, 0, -cyChar, &rect, &rect);
                       
                       hdc = GetDC (hMainWin);
                       
                       TextOut (hdc, cxChar, cyChar * (rect.bottom / cyChar - 2 ),
                                szBuffer, wsprintf(szBuffer, TEXT("Here is the text") ));
                       ReleaseDC (hMainWin, hdc);
                       }
    
    
                    return 0;
    Now on to the next part

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>1) ID_EDITCONTROL gave me an error so couldn't use GetDlgItem

    You defined the ID of the control as 1

    #define ID_EDITCONTROL 1 // this is usually set in the resource.h by the resource editor

    >>2) SetWindowText changed the text on the title bar not inside the window.

    Try

    SetDlgItemText() if it is an edit or static ect.

    ie
    SetDlgItemText(hWindow1,1,"Some text to set.");
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 07:57 PM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 04:07 PM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 06:55 PM
  4. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 05:49 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21