I am trying to understand anothers person's program and at the moment
I am just curious as to how a WNDCLASS wndclass instance behaves if you give it values, RegisterClass it, then give it new values and register those. Doesn't
the one that was registered before have their values replaced by the ones
that follows. An illustration is below. wndclass has its items assign with
values, and after the call to RegisterClass these same items are assign
with different values, how is this suppose to work. I am somewhat new to
Windows.
Thanks Very Much,
Please EMAIL
S. Nguyen
/*========================================================================*/
/* */
/* NAME : InitApplication */
/* DESCRIPTION : This routine registers the different windows used */
/* by this program at startup. */
/* */
/* ARGUMENTS : HANDLE : hInstance */
/* */
/* RETURN VALUE : TRUE or FALSE (BOOL) */
/* */
/*========================================================================*/
BOOL _cdecl InitApplication (hInstance)
HANDLE hInstance;
{
/*------------------ declaration of local variables ----------------------*/
WNDCLASS wndclass;
/*----------------------- Start of routine code ----------------------*/
wndclass.style = CS_BYTEALIGNWINDOW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, "BUGICON");
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = CreateSolidBrush(RGB(0, 0, 255));
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.style = NULL;
wndclass.lpfnWndProc = MenuWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = COLOR_WINDOW+1;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "StatLine:Child";
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.lpfnWndProc = OLutProc;
wndclass.cbClsExtra = sizeof(HBRUSH);
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, "RGBICON");
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = CreateSolidBrush(0L);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Color:LUT";
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.lpfnWndProc = LogWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = CreateSolidBrush(RGB(255, 255, 124));
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Log:Child";
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.lpfnWndProc = LutWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = CreateSolidBrush(RGB(255, 255, 124));
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Lut:Child";
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.lpszClassName = "ILut";
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = ILGraphWndProc;
wndclass.hCursor = LoadCursor (hInstance, IDC_ARROW);
wndclass.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wndclass.lpszMenuName = NULL;
wndclass.hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.lpszClassName = "OLut";
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = OLGraphWndProc;
wndclass.hCursor = LoadCursor (hInstance, IDC_ARROW);
wndclass.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wndclass.lpszMenuName = NULL;
wndclass.hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
if(!RegisterClass(&wndclass))
return (FALSE);
wndclass.lpszClassName = "OvLut";
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = OvLGraphWndProc;
wndclass.hCursor = LoadCursor (hInstance, IDC_ARROW);
wndclass.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wndclass.lpszMenuName = NULL;
wndclass.hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
return (RegisterClass(&wndclass));
}
/*========================================================================*/
/* */
/* NAME : InitInstance */
/* DESCRIPTION : This routine creates the different windows used by this */
/* program during its execution. */
/* */
/* ARGUMENTS : HANDLE : hInstance */
/* int : nCmdShow */
/* */
/* RETURN VALUE : TRUE or FALSE (BOOL) */
/* */
/*========================================================================*/
BOOL _cdecl InitInstance (hInstance, nCmdShow)
HANDLE hInstance;
int nCmdShow;
{
/*------------------ declaration of local variables ----------------------*/
static char *szColorLabel[] = {"Index", "Red", "Green", "Blue"};
FARPROC lpfnScrollProc;
int x, y, cx, cy, cyh;
int iReopen;
short n;
/*----------------------- Start of routine code ----------------------*/
cy = GetSystemMetrics (SM_CYSCREEN) -
GetSystemMetrics (SM_CYICON) -
(GetSystemMetrics (SM_CYCAPTION) * 2);
cyh = GetSystemMetrics (SM_CYHSCROLL);
x = GetPrivateProfileInt (achPr, "x", 0, achFile);
y = GetPrivateProfileInt (achPr, "y", 0, achFile);
cx = GetSystemMetrics (SM_CXSCREEN);
cx = GetPrivateProfileInt (achPr, "cx", cx, achFile);
cy = GetPrivateProfileInt (achPr, "cy", cy, achFile);
iReopen = GetPrivateProfileInt (achPr, "Reopen", 0, achFile);
if(iReopen == REOPEN_ZOOM)
nCmdShow = SW_SHOWMAXIMIZED;
if(iReopen == REOPEN_DEFAULT)
{
x = CW_USEDEFAULT;
y = CW_USEDEFAULT;
}
hWndMain = CreateWindow(szAppName,
"DT3851/52 Example Program: A Sample User Interface",
WS_OVERLAPPEDWINDOW |
WS_SIZEBOX |
WS_CLIPCHILDREN,
x,
y,
cx,
cy,
NULL,
NULL,
hInstance,
NULL);
if(!hWndMain)
return (FALSE);
hWndMenu = CreateWindow("StatLine:Child",
NULL,
WS_CHILD |
WS_BORDER |
WS_CLIPSIBLINGS |
WS_VISIBLE,
0, 0, 0, 0,
hWndMain,
NULL,
hInstance,
NULL);
if(!hWndMenu)
return (FALSE);
hWndLog = CreateWindow("Log:Child",
"DT3851/52 Response Log",
WS_CHILD |
WS_SIZEBOX |
WS_THICKFRAME |
WS_CAPTION |
WS_CLIPSIBLINGS |
WS_VISIBLE |
WS_VSCROLL |
WS_HSCROLL,
0,
0,
(2*cx)/3,
cy-cyh,
hWndMain,
NULL,
hInstance,
NULL);
if(!hWndLog)
return (FALSE);
hWndLut = CreateWindow("Lut:Child",
"DT3851/52 Lookup Table Values",
WS_CHILD |
WS_SIZEBOX |
WS_THICKFRAME |
WS_CAPTION |
WS_CLIPSIBLINGS |
WS_VISIBLE |
WS_VSCROLL |
WS_HSCROLL,
(2*cx)/3,
0,
cx/3,
cy-cyh,
hWndMain,
NULL,
hInstance,
NULL);
if(!hWndLut)
return (FALSE);
hWndOL = CreateWindow("Color:LUT",
"OLUT Manual Entry",
WS_CHILD |
WS_CLIPSIBLINGS |
WS_CAPTION |
WS_MINIMIZEBOX |
WS_MAXIMIZEBOX |
WS_SIZEBOX |
WS_VISIBLE |
WS_THICKFRAME,
0,0,0,0,
hWndMain,
NULL,
hInstance,
NULL);
if(!hWndOL)
return (FALSE);
hwndRect = CreateWindow("static",
NULL,
WS_CHILD |
SS_WHITERECT |
WS_VISIBLE,
0,
0,
0,
0,
hWndOL,
14,
hInstance,
NULL);
if(!hwndRect)
return (FALSE);
hwndButton [0] = CreateWindow ("button",
"Set Color",
WS_CHILD |
WS_VISIBLE |
WS_TABSTOP |
BS_PUSHBUTTON,
0,
0,
0,
0,
hWndOL,
4,
hInstance,
NULL);
if(!hwndButton [0])
return (FALSE);
hwndButton [1] = CreateWindow ("button",
" Quit ",
WS_CHILD |
WS_VISIBLE |
WS_TABSTOP |
BS_PUSHBUTTON,
0,
0,
0,
0,
hWndOL,
5,
hInstance,
NULL);
if(!hwndButton [1])
return (FALSE);
lpfnScrollProc = MakeProcInstance ((FARPROC) ScrollProc, hInstance);
for(n=0; n<4; n++)
{
hwndScrol [n] = CreateWindow("scrollbar",
NULL,
WS_CHILD |
WS_VISIBLE |
WS_TABSTOP |
SBS_VERT,
0,
0,
0,
0,
hWndOL,
n,
hInstance,
NULL);
if(!hwndScrol [n])
return (FALSE);
hwndLabel [n] = CreateWindow("static",
szColorLabel[n],
WS_CHILD |
WS_VISIBLE |
SS_CENTER,
0,
0,
0,
0,
hWndOL,
n+6,
hInstance,
NULL);
if(!hwndLabel [n])
return (FALSE);
hwndValue [n] = CreateWindow("static",
"0",
WS_CHILD |
WS_VISIBLE |
SS_CENTER,
0,
0,
0,
0,
hWndOL,
n+10,
hInstance,
NULL);
if(!hwndValue [n])
return (FALSE);
lpfnOldScr[n] = (FARPROC)GetWindowLong (hwndScrol [n], GWL_WNDPROC);
SetWindowLong (hwndScrol[n], GWL_WNDPROC, (LONG)lpfnScrollProc);
SetScrollRange (hwndScrol[n], SB_CTL, 0, 255, FALSE);
SetScrollPos (hwndScrol[n], SB_CTL, 0, FALSE);
}
lpfnOldScr [4] = (FARPROC)GetWindowLong (hwndButton [0], GWL_WNDPROC);
SetWindowLong (hwndButton [0], GWL_WNDPROC, (LONG)lpfnScrollProc);
lpfnOldScr [5] = (FARPROC)GetWindowLong (hwndButton [1], GWL_WNDPROC);
SetWindowLong (hwndButton [1], GWL_WNDPROC, (LONG)lpfnScrollProc);
ShowWindow (hWndMain, nCmdShow);
UpdateWindow (hWndMain);
return (TRUE);
}
>Dear Gurus:
> I am trying to understand anothers person's program and at the moment
>I am just curious as to how a WNDCLASS wndclass instance behaves if you give
>it values, RegisterClass it, then give it new values and register those.
For all beginners, read the excellent book Programming Windows 3.1 written
by Charles Petzold of Microsoft Press.
Every time you see "read Petzold", this book is meant.
Try to post some more advanced questions on this user group ;-)
Jacco Brok
etm...@etmsun.ericsson.se
Ericsson Telecommunications
The Netherlands
The WNDCLASS struct is just a conventient way to pass a lot of
parameters to RegisterClass in one go. Just imagine if you had
to pass all those values in as separate parameters... it would be
like calling CreateWindowEx()! An example of where the two
approaches coexist is the API pair CreateFont() and CreateFontIndirect()
(look them up in your WinAPI help file).
Internally, Windows copies the values passed in the user's WNDCLASS
to its own buffer (which vaguely resembles a WNDCLASS), and doesn't care
what happens to the WNDCLASS you passed once it's finished with it...
--
Miguel Carrasquer ____________________ ~~~
Amsterdam [ ||]~
m...@inter.NL.net ce .sig n'est pas une .cig
The second time you call RegisterClass(), the call will fail; trying to
re-register the class will have no effect.
It appeared to have worked, when I compiled and ran the whole program.