[comp.windows.ms] Child Windows

newsuser@LTH.Se (LTH network news server) (02/26/89)

When creating childwindows in Windows (!), using the
function CreateWindow (what else!?) it goes wrong
after approx 300 windows.  The amount of memory
available has decreased about 32 kB. 
Unfortunately, Windows still allows me to create
additional windows, and the memory is eaten up by
another 20 kB. 

The function CreateWindow does not return NULL
when something goes wrong, which it ought to.  It
doesn't return a NULL until after about 900
windows have been created... 

Isn't it possible to create that many windows?

Do you have any suggestion?

Thanks in advance,
Torsten
-- 
Torsten Olsson, Dept of Comp Sc, Lund University, Box 118, S221 00 Lund, Sweden
Phone: +46-46109640                 Bitnet: lthlib@seldc52
Internet: torsten@dna.lth.se   or   torsten%dna.lth.se@uunet.uu.net
UUCP: {uunet,mcvax}!enea!dna.lth.se!torsten 

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (09/22/89)

When I create some overlapped child windows in the client area of a
program, they all get an "inactive" border and caption bar. I did not
find a usable way to get the child window with the input focus having
an "active" frame and caption bar (like it is the case in Excel).

I SPYed on the window messages to the child windows. When one is
activated, it gets a WM_CHILDACTIVATE and a WM_NCPAINT message but when
it is deactivated, it only gets a WM_NCPAINT. What can I do on this
message (return a special flag or a brush like on a WM_CTLCOLOR) ?
In the SDK docs I did not find any help. 

In the Appl. style guide are many suggestions for multidocument programs
wich are really good but there isn't any hint how to implement these
features.

Can anybody help ?

Thanks in advance,

Kai Uwe Rommel, Munich

paul@cscnj.csc.COM (Paul Moody) (09/26/89)

In article <810@tuminfo1.lan.informatik.tu-muenchen.dbp.de>, rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) writes:
> When I create some overlapped child windows in the client area of a
> program, they all get an "inactive" border and caption bar. I did not
> find a usable way to get the child window with the input focus having
> an "active" frame and caption bar (like it is the case in Excel).
... deleted .... 
> Can anybody help ?
> 
> Thanks in advance,
> 
> Kai Uwe Rommel, Munich

What you must do is control the style of the child window yourself.
This is done using the SetWindowLong call.
eg:
   SetWindowLong(hChildWnd, GWL_STYLE,
		 WS_CHILD | WS_SYSMENU | WS_CAPTION | WS_VISIBLE);
is a minimal call to "activate" a child window.
Note that you must send WM_ACTIVATE and WM_NCACTIVATE messages 
yourself.  Also, you must keep track of which child is active. If the 
child is obscured, you must call BringWindowToTop to make it visible.

There was a good intro to mdi in Microsoft System Journal, but I 
dont remember the issue.

In Windows version 3, mdi is "builtin". I havent played with it yet,
but it looks better than the "roll your own" versions.

Paul Moody
-- 
Paul Moody @CSC
...usual disclaimer...

thorp@spudge.UUCP (Don Thorp) (09/08/90)

I'm having problems with the following code.  I was attempting to create a 
listbox as a child window to my main application window.  I originally tried
to create the listbox in the WM_CREATE section of the MainWindowProc.  This
always returns a NULL handle for the window.  The section of code that is
enabled by defining THIS_DOES_NOT_WORK was the original attempt.  I then
moved the same code into the InitApplication procedure and it worked just
fine.  I have been stumped for quite awhile on how this could be.  Any
suggestions would be greatly appreciated.

Don Thorp


==========================================================================

#include "windows.h"        /* required for all Windows applications */
#define NULL 0
#include "wmail.h"          /* specific to this program        */

HANDLE hInst;               /* current instance          */
HWND   hMainWindow;         /* Main window handle.                */
HWND   hMailList;

char szChildClass[] = "listbox";


int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance;			     /* current instance	     */
HANDLE hPrevInstance;			     /* previous instance	     */
LPSTR lpCmdLine;			     /* command line		     */
int nCmdShow;				     /* show-window type (open/icon) */
{
  MSG msg;             /* message          */

  if (!hPrevInstance) {

    if (!InitApplication(hInstance))  {

      return (FALSE);    /* Exits if unable to initialize     */
    }
  }

  if (!InitInstance(hInstance, nCmdShow)) {

    return (FALSE);
  }


  /* Acquire and dispatch messages until a WM_QUIT message is received. */

  while (GetMessage(&msg, NULL, NULL, NULL)) {

    TranslateMessage(&msg);  /* Translates virtual key codes       */
    DispatchMessage(&msg);   /* Dispatches message to window       */
  }

  return (msg.wParam);     /* Returns the value from PostQuitMessage */
}

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(NULL, IDI_APPLICATION);
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject(WHITE_BRUSH);

  wc.lpszMenuName =  "WMailMenu";   /* Name of menu resource in .RC file. */
  wc.lpszClassName = "WMailWClass"; /* Name used in call to CreateWindow. */

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

  if(!RegisterClass(&wc)) {

    MessageBeep(880);
    return(FALSE);
  }

  return(TRUE);
}


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(
    "WMailWClass",                  /* See RegisterClass() call.          */
    "WMail",                        /* Text for window title bar.         */
    WS_OVERLAPPEDWINDOW ,
    CW_USEDEFAULT,                  /* Default horizontal position.       */
    CW_USEDEFAULT,                  /* Default vertical position.         */
    CW_USEDEFAULT,                  /* Default width.                     */
    CW_USEDEFAULT,                  /* Default 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);
  }


  /* Make the window visible; update its client area; and return "success" */

  hMainWindow = hWnd;

  ShowWindow(hWnd, nCmdShow);  /* Show the window                        */
  UpdateWindow(hWnd);          /* Sends WM_PAINT message                 */

#if defined(THIS_WORKS)

  hMailList = CreateWindow(szChildClass,
                            NULL,
                            WS_CHILD | WS_VISIBLE | LBS_STANDARD,
                            10,10,
                            200,200,
                            hWnd,
                            IDC_LISTBOX,
                            hInst,
                            NULL);

  if(!hMailList) {

    return(FALSE);
  }

  {
    LONG rc;

    rc = SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");

    displayWordError("LB_ADDSTRING",(WORD) rc);

    SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");
    SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");
    SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");
  }


#endif

  return (TRUE);               /* Returns the value from PostQuitMessage */

}

LONG FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd;				  /* window handle		     */
unsigned message;			  /* type of message		     */
WORD wParam;				  /* additional information	     */
LONG lParam;				  /* additional information	     */
{
  FARPROC lpProcAbout;      /* pointer to the "About" function */
  LONG rc;

  switch (message) {

#if defined(THIS_DOES_NOT_WORK)
    case WM_CREATE:


      hMailList = CreateWindow(szChildClass,
                                NULL,
                                WS_CHILD | WS_VISIBLE | LBS_STANDARD,
                                10,10,
                                200,200,
                                hWnd,
                                IDC_LISTBOX,
                                hInst,
                                NULL);

      if(!hMailList) {

        MessageBeep(440);
        break;
      }
      else {

        LONG rc;

        rc = SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");

        displayWordError("LB_ADDSTRING",(WORD) rc);

        SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");
        SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");
        SendMessage(hMailList,LB_ADDSTRING, NULL, (LONG) (LPSTR) "Hello");
      }

      break;
#endif

    case WM_COMMAND:     /* message: command from application menu */

      if (wParam == IDM_ABOUT) {

        lpProcAbout = MakeProcInstance(About, hInst);

        DialogBox(hInst, "ABOUT", hWnd, lpProcAbout);

        FreeProcInstance(lpProcAbout);

      }
      else {         /* Lets Windows process it       */

        return (DefWindowProc(hWnd, message, wParam, lParam));
      }

      break;

    case WM_DESTROY:      /* message: window being destroyed */

        PostQuitMessage(0);
        break;

    default:        /* Passes it on if unproccessed    */

        return (DefWindowProc(hWnd, message, wParam, lParam));
  }

  return (NULL);
}


==========================================================================
Don Thorp 

UUCP:  ...!letni!rwsys!spudge!thorp
USENET: thorp@rwsys.lonestar.org
BIX: dthorp