Thread: ShowWindow causing Access Violations - please help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    22

    Angry ShowWindow causing Access Violations - please help

    I'm trying to write a WIN32 API C++ wrapper (and I'm new to WIN32 programming but I think I understand the concepts fairly well), and I'm hitting a problem with the ShowWindow(HWND hWnd, int nShowCmd) function. I've read several articles and tutorials on the API and making wrapper classes for it, but I've seen no mention of this. The window structure is being properly filled out, the window is being registered and it is being created. But when I call ShowWindow, it craps out - the window appears (slowly) but is busy and not responding. According to the MSVC++ 6.0 debugger, an access violation is being cause when ShowWindow is called. Any help would be greatly appreciated, as this problem is a major show stopper.

    Below is the code for my show window method (at the very bottom) and the window creation method. The window handle, hWnd, is a protected member of the class. AddErrorMessage is an inherited method for posting error messages to a queue so they can be written to a file later. The class is modeled off of several examples I have.



    bool WindowClass::WindowCreate(HINSTANCE hInstance, char *title, int x, int y, int width, int height, unsigned long classStyle, unsigned long windowStyle)
    {
    WNDCLASS window;

    /* Configure Window Structure */
    window.style = classStyle;
    window.lpfnWndProc = WindowProc;
    window.cbClsExtra = 0;
    window.cbWndExtra = 0;
    window.hInstance = hInstance;
    window.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
    window.hCursor = LoadCursor (NULL, IDC_ARROW);
    window.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    window.lpszMenuName = NULL;
    window.lpszClassName = title;

    /* Register Window*/
    if(!RegisterClass(&window))
    {
    int error = GetLastError();
    AddErrorMessage("Unable to register window", "WindowCreate", "WindowClass", __FILE__, __LINE__);
    return false;
    }

    /* Create Window and Assign Handle */
    hWnd = CreateWindow(title, title, windowStyle, x, y, width, height, NULL, NULL, hInstance, (void*)this);
    if(hWnd != NULL)
    {
    windowStatus = WINDOW_ALIVE;
    return true;
    }
    else
    {
    windowStatus = WINDOW_NOT_CREATED;
    AddErrorMessage("Unable to create window", "WindowCreate", "WindowClass", __FILE__, __LINE__);
    return false;
    }

    }


    void WindowClass::WindowShow(int nShowCmd)
    {
    if(hWnd != NULL)
    {
    ShowWindow(hWnd, nShowCmd); // THIS IS THE PROBLEM!
    UpdateWindow(hWnd);
    }
    }

    Thanks!
    Last edited by Arrow Mk 84; 08-03-2002 at 08:11 PM.
    Never give an Ewok a thermial detonator

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do the Access Violations every end?
    By durban in forum C++ Programming
    Replies: 4
    Last Post: 10-12-2005, 10:13 PM
  2. Access Violations
    By nickname_changed in forum C++ Programming
    Replies: 0
    Last Post: 09-22-2003, 03:49 AM
  3. Finding access violations in the source
    By Carlos in forum Windows Programming
    Replies: 4
    Last Post: 11-20-2002, 04:07 AM
  4. Replies: 2
    Last Post: 06-13-2002, 11:05 PM
  5. access violations
    By curtner in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2001, 01:32 AM