🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.ms.programmer
Article #1114

Scoping question using C and SDK

#1114
From: Anant Kartik Mithal
Date: Wed, 23 Jan 1991 04:46
54 lines
2181 bytes
I'm confused by what the scope of a variable is in a Windows program.
I would assume that it uses standard C scoping (assuming that you are 
using C, which is what I'm using). In the Guide to Programming, in the
chapter "Output to a Window," they give an example which requires a
bunch of HPEN, HBRUSH etc. They ask you to construct a program (pages
3-8 thru 3-9) that is something like

HPEN hPen;		/* black pen to draw outlines of rectangles  */	
HBRUSH hOldBrush;			/* handle to old brush */
HBRUSH hRedBrush;			/* handle to red brush */
HBRUSH hGreyBrush;			/* handle to grey brush */


WinMain()
{
	.
	.
}

MainWndProc()
{
	HDC hDC;
	PAINTSTRUCT ps;
	HPEN hOldPen;

	switch ()

		case(WM_CREATE)
		{
		<statements initializing the Grey and Red brushes>
		}

		case(WM_PAINT)
		{
		<statements using the grey and red brushes>
		}
}

It seemed to me that I could define all the pens and brushes within
MainWndProc, so that they would  not be global variables (they were
being used only in the WM_CREATE and the WM_PAINT cases, both within
MainWndProc. However, when I did that, it didn't work. When I went to
the way things are defined in the book, it worked. Unfortunately, that
doesn't give me any way of figuring out what the scoping rules are...

Any help would be much appreciated.

kartik

--
Anant Kartik Mithal                                     akm@cs.uoregon.edu
Network Manager, 					(503)346-4408 (msgs)
Department of Computer Science,                         (503)346-4156 (direct)
University of Oregon, Eugene, OR 97403-1202
Technical Details
Message-ID: <1991Jan23.044611.21227@cs.uoregon.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sdd.hp.com!zaphod.mps.ohio-state.edu!swrinde!ucsd!ogicse!cs.uoregon.edu!akm

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sdd.hp.com!zaphod.mps.ohio-state.edu!swrinde!ucsd!ogicse!cs.uoregon.edu!akm
From: akm@cs.uoregon.edu (Anant Kartik Mithal)
Newsgroups: comp.windows.ms.programmer
Subject: Scoping question using C and SDK
Summary: need info about the scoping of variables in windows programs
Keywords: scoping, C, SDK
Message-ID: <1991Jan23.044611.21227@cs.uoregon.edu>
Date: 23 Jan 91 04:46:11 GMT
Sender: news@cs.uoregon.edu (Netnews Owner)
Organization: Department of Computer Science, University of Oregon
Lines: 54