🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Scoping question using C and SDK

#1137
From: Alastair Dallas
Date: Thu, 24 Jan 1991 18:58
35 lines
2124 bytes
In article <1991Jan23.044611.21227@cs.uoregon.edu>, akm@cs.uoregon.edu (Anant Kartik Mithal) writes:
> I'm confused by what the scope of a variable is in a Windows program.
>
> ...
> 
> 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...

This isn't scope, it's storage class.  If the variables are automatics,
allocated on the stack, the values which WM_CREATE so carefully stores
there will be garbage by the time the WndProc gets called with a 
WM_PAINT.  You can put them in WndProc but you have to declare them
'static' so that they hang around between invocations.

> Any help would be much appreciated.

This bit me when I was trying to set a flag to indicate that the mouse
button was down in order to change the behavior of WM_MOUSEMOVE.  The
flag has to be static storage class, as a few seconds in CodeView
taught me--you should be glad you asked this question about painting,
which is a lot easier to debug than mousedown events!

/alastair/
> 
> 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: <1991Jan24.185856.19328@dbase.A-T.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!hacgate!ashtate!dbase!awd
References: <1991Jan23.044611.21227@cs.uoregon.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!hacgate!ashtate!dbase!awd
From: awd@dbase.A-T.COM (Alastair Dallas)
Newsgroups: comp.windows.ms.programmer
Subject: Re: Scoping question using C and SDK
Summary: Scoping isn't the problem
Keywords: scoping, C, SDK
Message-ID: <1991Jan24.185856.19328@dbase.A-T.COM>
Date: 24 Jan 91 18:58:56 GMT
References: <1991Jan23.044611.21227@cs.uoregon.edu>
Organization: Ashton-Tate, Inc.
Lines: 35