[comp.windows.ms.programmer] Need help with creating a child window

akm@cs.uoregon.edu (Anant Kartik Mithal) (02/07/91)

Hi,

I am trying to create a simple child window that sits at the bottom of
my main window, and will (eventually) provide status information to
the user. I am using the folloing code which seems fairly
straightforward, but everytime it executes to the part where the child
window is being created via CreateWindow, I get an "Unrecoverable
Application Error." I've checked this by stepping through with the
SDK, and the error occurs within the call to CreateWindow.

The code follows. Any help will be much appreciated.

kartik

MainWndProc first calls InitApplication, then InitInstance (ala SDK).

BOOL InitApplication(hInstance)
HANDLE hInstance;			       /* current instance	     */
{
   WNDCLASS  wc;
   /* Fill in window class structure with parameters that describe the       */
   /* main window.                                                           */
    wc.style = NULL;                    /* Class style(s).                   */
    wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for */
                                        /* windows of this class.            */
    wc.cbClsExtra = 0;                  /* No per-class extra data.          */
    wc.cbWndExtra = 0;                  /* No per-window extra data.         */
    wc.hInstance = hInstance;           /* Application that owns the class.  */
    wc.hIcon = LoadIcon(hInstance, "X1PointIcon");
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
    wc.lpszMenuName =  "X1pointMenu";   /* Name of menu resource in .RC file.*/
    wc.lpszClassName = "X1pointWClass"; /* Name used in call to CreateWindow.*/

    /* Register the window class and return success/failure code. */

    if (!RegisterClass(&wc))
	return(FALSE);

    /* reuse wc to set up the child window class */
    wc.lpfnWndProc= NULL;		/* currently no procedure */
    wc.hIcon	= NULL;			/* no icon */
    wc.hInstance = hInstance;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName= "X1PointStatusWndClass";
    wc.style = NULL;
    
    return(RegisterClass(&wc));

}

BOOL InitInstance(hInstance, nCmdShow)
    HANDLE          hInstance;          /* Current instance identifier.      */
    int             nCmdShow;           /* Param for first ShowWindow() call.*/
{
    HWND            hWnd;               /* Main window handle.               */

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    hInst = hInstance;

    /* Create a main window for this application instance.  */

    hWnd = CreateWindow(
        "X1pointWClass",                /* See RegisterClass() call.         */
        "Pointing Devices Selection Test",   /* Text for window title bar.   */
        WS_OVERLAPPEDWINDOW |
        WS_CLIPCHILDREN,            	/* Window style.                     */
	APP_WINDOW_X_POSITION,		/*horiz. position (x) */
	APP_WINDOW_Y_POSITION,		/*vert. position  (y) */
        APP_WINDOW_WIDTH,		/*width */
	APP_WINDOW_HEIGHT,		/*height*/
        NULL,                           /* Overlapped windows have no parent.*/
        NULL,                           /* Use the window class menu.        */
        hInstance,                      /* This instance owns this window.   */
        NULL                            /* Pointer not needed.               */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);
    
    /* create the status window */
    hStatusWnd = CreateWindow
    (
        "X1PointStatusWndClass",	/* matches RegisterClass call. */
        NULL,				/* no title */
        WS_CHILD | WS_BORDER,		/* style bits */
        0, 0, 0, 0,			/* size and location */
        hWnd,				/* handle to Parent window*/
        IDCW_STATUS,			/* identifier to child window*/
        hInstance,			/* handle to creator */
        NULL				/* parameters */
    );

/*************************************NOTENOTENOTE***********/
/*the application crashes right here*********************/


    ShowWindow(hWnd, nCmdShow);  /* Show the window                        */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message                 */
    return (TRUE);               /* Returns the value from PostQuitMessage */

}

What is really frustrating is that if I remove the code for the second
register class and for the second create window, everything becomes
just fine.


Sigh....

kartik
--
Anant Kartik Mithal                                     akm@cs.uoregon.edu
Research Assistant, 					(503)346-4408 (msgs)
Department of Computer Science,                         (503)346-3989 (direct)
University of Oregon, Eugene, OR 97403-1202