Problem in WndProc function

Discussion in 'C Programming' started by Rawan2, May 12, 2010.

  1. Rawan2

    Rawan2

    Joined:
    May 12, 2010
    Messages:
    1
    I am Programming a project in c++ that display the result in a window create by CreateWindow() and I use the function WndProc for the implement some cases and in the case WM_COPYDATA I want to call another function " Sound() "
    But when I run the program, the computer stops responding completely and I having to restart it :(

    So how can I call a function within the WM_COPYDATA case correctly?

    this is the code, Can anyone know the problem?

    Code:
      
             
            
    #include "hooklib.h" // Includes WIndows.h, also.
     
    
    HWND textBox = NULL; // Read-only edit, child.
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Window procedure.
    LRESULT CALLBACK WndProce(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
            static TCHAR szAppName[] = TEXT("Screen reader");
        MSG msg;
    
            WNDCLASS wndclass = {CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH) GetStockObject(WHITE_BRUSH), NULL, szAppName};
            RegisterClass(&wndclass);
           
           
            HWND hwnd = CreateWindow(szAppName, TEXT("Screen Reader"), WS_OVERLAPPEDWINDOW, 320, 100, 550, 550, NULL, NULL, hInstance, NULL);
                                     
    
            // Set always-on-top, ignore the rest.
            SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
            if(! hooklibInitialize(hwnd))
            { // If setting up the hooks failed.
                    MessageBox(NULL, TEXT("Error installing a hook."), TEXT("ERROR"), 0);
                    return GetLastError();
            } // if
            ShowWindow(hwnd, iCmdShow);
        UpdateWindow(hwnd);
    
            // The message loop:
            while(GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        } // while
                            
    
        return msg.wParam;
    } // winmain
    
    void Sound ()
    {
    
            TextAloud_2::ITextAloudIntf_2Class TAObject;
             TAObject.PlayText("Hello");
    }
    
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
            static COPYDATASTRUCT* copyData = NULL; // For IPC with hooklib.dll.
    
            switch(message)
        {
                    case WM_CREATE: // Create the read-only text box.
    
                            textBox = CreateWindow(TEXT("edit"), NULL, WS_CHILD|WS_VISIBLE|WS_BORDER|
                            ES_LEFT|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL|ES_AUTOHSCROLL|
                            ES_AUTOVSCROLL, 0, 0, 0, 0, hwnd, NULL,
                            ((LPCREATESTRUCT)lParam)->hInstance, NULL);
                            return 0;
            case WM_SETFOCUS: // Set the focus to the edit control.
                            SetFocus(textBox);
                            return 0;
                    case WM_SIZE: // Resize to parent dimensions, don't reposition, do repaint.
                            MoveWindow(textBox, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
                            return 0;
                    case WM_COPYDATA: // A message from hooklib.dll - display it.
    
                            copyData = (COPYDATASTRUCT*) lParam;
    
                            SetWindowText(textBox, (PTCHAR) copyData->lpData);
                            Sound();
                            return TRUE;
                    case WM_DESTROY: // App quitted: kill windows, free hooks.
                            PostQuitMessage(0);
                            hooklibCleanup();
                            return 0;
            } // switch
        return DefWindowProc(hwnd, message, wParam, lParam);
    
    } // window procedure
     
     
    Last edited: May 12, 2010
    Rawan2, May 12, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beach Potato
    Replies:
    6
    Views:
    765
    Beach Potato
    Sep 22, 2003
  2. James Vanns
    Replies:
    7
    Views:
    7,033
    Evan Carew
    Jan 21, 2004
  3. komal
    Replies:
    6
    Views:
    1,418
    msalters
    Jan 25, 2005
  4. Turbo_King

    WndProc - Windows Classes Question

    Turbo_King, Mar 9, 2005, in forum: C++
    Replies:
    6
    Views:
    6,230
    Turbo_King
    Mar 10, 2005
  5. seberino@spawar.navy.mil
    Replies:
    2
    Views:
    916
    Bengt Richter
    Aug 1, 2005
Loading...

Share This Page