Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem in WndProc function

Reply
Thread Tools

Problem in WndProc function

 
 
Rawan2 Rawan2 is offline
Junior Member
Join Date: May 2010
Posts: 1
 
      05-12-2010
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 by Rawan2; 05-12-2010 at 07:31 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
WndProc - Windows Classes Question Turbo_King C++ 6 03-10-2005 02:44 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM
Looking for a simple and interesting implementation of Windows' WndProc in C++ classes Beach Potato C++ 6 09-21-2003 11:03 PM



Advertisments