Problem in WndProc function

Joined
May 12, 2010
Messages
1
Reaction score
0
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:

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,440
Members
47,101
Latest member
DoloresHol

Latest Threads

Top