delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/14/03:00:25

From: "G Gravagne" <fudd3 AT msn DOT com>
Subject: RSXNTDJ compile error
Date: Thu, 14 May 1998 02:57:23 -0400
Lines: 161
Message-ID: <#sD8NWwf9GA.352@upnetnews03>
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

When attempting to compile the menudemo program from Petzold, the following
error message occurred:

menudemo.c:  In function 'WndProc':
menudemo.c:91: 'GCL_HBRBACKGROUND' undeclared (first use this function)
menudemo.c:91: (Each undeclared identifier is reported only once
menudemo.c:91:   for each function it appears in.)

The source code which produced this error - with the offending line marked -
is as follows:

#include <windows.h>
#include "menudemo.h"

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

char szAppName[] = "MenuDemo";

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
  HWND hwnd;
  MSG msg;
  WNDCLASSEX wndclass;

  wndclass.cbSize = sizeof(wndclass);
  wndclass.style = CS_HREDRAW | CS_VREDRAW;
  wndclass.lpfnWndProc = WndProc;
  wndclass.cbClsExtra = 0;
  wndclass.cbWndExtra = 0;
  wndclass.hInstance = hInstance;
  wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  wndclass.lpszMenuName = szAppName;
  wndclass.lpszClassName = szAppName;
  wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

  RegisterClassEx(&wndclass);

  hwnd = CreateWindow(szAppName, "Menu Demonstration",
                      WS_OVERLAPPEDWINDOW,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      NULL, NULL, hInstance, NULL);

  ShowWindow(hwnd, iCmdShow);
  UpdateWindow(hwnd);

  while(GetMessage(&msg, NULL, 0, 0))
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM
lParam)
{
  static int iColorID[5] = {WHITE_BRUSH, LTGRAY_BRUSH, GRAY_BRUSH,
                            DKGRAY_BRUSH, BLACK_BRUSH};
  static int iSelection = IDM_WHITE;
  HMENU hMenu;

  switch (iMsg)
  {
    case WM_COMMAND:
      hMenu = GetMenu(hwnd);
      switch (LOWORD(wParam))
      {
        case IDM_NEW:
        case IDM_OPEN:
        case IDM_SAVE:
        case IDM_SAVEAS:
   MessageBeep(0);
   return 0;
 case IDM_EXIT:
   SendMessage(hwnd,WM_CLOSE,0,0L);
   return 0;
        case IDM_UNDO:
        case IDM_CUT:
        case IDM_COPY:
        case IDM_PASTE:
        case IDM_DEL:
          MessageBeep(0);
          return 0;

        case IDM_WHITE:       // Note: Logic below
        case IDM_LTGRAY:      //   assumes that IDM_WHITE
        case IDM_GRAY:        //   through IDM_BLACK are
        case IDM_DKGRAY:      //   consecutive number in
        case IDM_BLACK:       //   the order shown here.
          CheckMenuItem(hMenu, iSelection, MF_UNCHECKED);
          iSelection = LOWORD(wParam);
          CheckMenuItem(hMenu, iSelection, MF_CHECKED);
//**************************************************************************
************************
          SetClassWord(hwnd, GCL_HBRBACKGROUND,
// line 91
          (LONG)GetStockObject(iColorID[LOWORD(wParam) - IDM_WHITE]));
//**************************************************************************
************************
          InvalidateRect(hwnd,NULL,TRUE);
   return 0;

 case IDM_START:
   if (SetTimer(hwnd,1,1000,NULL))
   {
     EnableMenuItem(hMenu, IDM_START, MF_GRAYED);
     EnableMenuItem(hMenu, IDM_STOP, MF_ENABLED);
   }
   return 0;

 case IDM_STOP:
   KillTimer(hwnd,1);
   EnableMenuItem(hMenu,IDM_START,MF_ENABLED);
   EnableMenuItem(hMenu,IDM_STOP,MF_GRAYED);
   return 0;

 case IDM_HELP:
          MessageBox(hwnd,"Help not yet implemented.",
                     szAppName,MB_ICONINFORMATION | MB_OK);
          return 0;

      case IDM_ABOUT:
          MessageBox(hwnd,"Menu Demonstration Program.",
                     szAppName,MB_ICONINFORMATION | MB_OK);
          return 0;

        }
        break;

      case WM_TIMER:
 MessageBeep(0);
 return 0;

      case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
      }
    return DefWindowProc(hwnd,iMsg,wParam,lParam);
  }

The source code was modified later on by pasting in the #define statements
for the GCL_ and GWL_ constants from the winuser.h file in the Microsoft
SDK; however, problems continued to persist. The program managed to compile
cleanly, but accessing any of the background color choices from the menu led
to an execution error:

Exception at 0x0000000001
Application got signal at SIGSEGV

I suspect there is a very straightforword solution to my difficulties -
perhaps I must use makelib to create a new library, and include the new
library as a link library - but as a newbie to Win32 programming, C, and
RSXNTDJ the debugging is quite a task. Any input would be greatly
appreciated. Thanks in advance.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019