[comp.windows.ms.programmer] Why no text in static control in 1024x768 mode?

goun@ddif.dec.com (Roger H. Goun) (05/31/91)

In trying out examples from Petzold's _Programming Windows_, Second Edition,
I've run into a problem that I can't explain.  For those of you who own the
book, I'm talking about the program ENVIRON.C, pp. 249-252.

ENVIRON.C creates a list box and a static child window control:

#define MAXENV 4096

[WinMain and start of WndProc elided...]

    case WM_CREATE :
	hdc = GetDC (hwnd) ;
	GetTextMetrics (hdc, &tm) ;
	ReleaseDC (hwnd, hdc) ;

	hwndList = CreateWindow ("listbox", NULL,
			WS_CHILD | WS_VISIBLE | LBS_STANDARD,
			tm.tmAveCharWidth, tm.tmHeight * 3,
			tm.tmAveCharWidth * 16 +
			    GetSystemMetrics (SM_CXVSCROLL),
			tm.tmHeight * 5,
			hwnd, 1,
			GetWindowWord (hwnd, GWW_HINSTANCE), NULL) ;

	hwndText = CreateWindow ("static", NULL,
			WS_CHILD | WS_VISIBLE | SS_LEFT,
			tm.tmAveCharWidth, tm.tmHeight,
			tm.tmAveCharWidth * MAXENV, tm.tmHeight,
			hwnd, 2,
			GetWindowWord (hwnd, GWW_HINSTANCE), NULL) ;

	/* Now load the list box. */

The program displays an environment variable and its value in the static
control when the user clicks on an environment variable in the list box:

    case WM_COMMAND :
	if (wParam == 1 && HIWORD (lParam) == LBN_SELCHANGE)
	    {
	    n = (WORD) SendMessage (hwndList, LB_GETCURSEL, 0, 0L) ;
	    n = (WORD) SendMessage (hwndList, LB_GETTEXT, n,
				    (LONG) (LPSTR) szBuffer) ;

	    strcpy (szBuffer + n + 1, getenv (szBuffer)) ;
	    *(szBuffer + n) = '=' ;
	    SetWindowText (hwndText, szBuffer) ;
	    }
	return 0 ;

On my 386 clone with a 1 Mb Orchid ProDesigner II and the SpeedSTAR drivers
from cica, this all works just fine in 640x480 and 800x600 256 color modes.  In
1024x768 256 color mode, however, no text at all is displayed in the static
control.  I've tried compiling it under Borland C++ as well as with a
colleague's Microsoft C with the same results.  Thinking there might be some
bizarre clipping problem going on, I increased the nHeight parameter to
tm.tmHeight * 2 with no effect.  I tried adding a lpWindowName parameter to
preload the text in the static control, again with no effect.  I tried adding
SS_BLACKFRAME to dwStyle; the frame appeared just fine in all modes, so the
static control IS being created.

Can anyone explain this?
--
Roger H. Goun, Digital Equipment Corporation, 110 Spit Brook Road, ZKO2-2/O23, 
Nashua, NH 03062 USA, +1 603 881 0022, goun@ddif.enet.dec.com or 
goun%ddif.enet@decwrl.dec.com, {uunet,sun,pyramid}!decwrl!ddif.enet!goun