NO

Author Topic: Declaring a class in a header, then instantiating in source. Can't Compile.  (Read 3305 times)

EdPellesC99

  • Guest


   Hi,

   I am trying to learn to declare, define and use a class.
I found a tutorial on having a user defined class in c programming, to help with clarity in win32 programming source code.

http://www.functionx.com/win32/Lesson06.htm

   They have several examples on the page .... you decare the class in the .h file, and use in the .c file.

I am having trouble getting anything to compile at all. I have tried a few variations.

I will show the header file, and the source file.
Can anyone help me get it to compile in PellesC as a win32 exe ?

Here is the header file:
Code: [Select]
pragma once
#include <windows.h>

//---------------------------------------------------------------------------
void class WApplication
{
public:
// This constructor will initialize the application
WApplication(HINSTANCE hInst, char *ClasName,
     WNDPROC WndPrc, LPCTSTR MenuName = NULL);

// Class Registration
void Register();

protected:
// Global variable that holds the application
WNDCLASSEX _WndClsEx;
};
//---------------------------------------------------------------------------
 

And now the Source file:
Code: [Select]
#include "WinApp.h"

//---------------------------------------------------------------------------
WApplication::WApplication(HINSTANCE hInst, char *ClsName,WNDPROC WndPrc, LPCTSTR MenuName)
{
// Initializing the application using the application member variable
_WndClsEx.cbSize        = sizeof(WNDCLASSEX);
_WndClsEx.style         = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
_WndClsEx.lpfnWndProc   = WndPrc;
_WndClsEx.cbClsExtra    = 0;
_WndClsEx.cbWndExtra    = 0;
_WndClsEx.hInstance     = hInst;
_WndClsEx.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
_WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
_WndClsEx.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
_WndClsEx.hbrBackground = GetStockObject(WHITE_BRUSH));

_WndClsEx.lpszMenuName  = MenuName;
_WndClsEx.lpszClassName = ClsName;
_WndClsEx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
}
//---------------------------------------------------------------------------
void WApplication::Register()
{
RegisterClassEx(&_WndClsEx);
}
//---------------------------------------------------------------------------


Also, though I used code tags, and my code indents nicely in my entry window, the indentation disappears in the preview ..... what is the trick to keep the code indentation in the post ?
   Tx in advance,

   Ed


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
You can't use classes with PellesC C99 compiler, it is not a C++ compiler.
May the source be with you

EdPellesC99

  • Guest
   Thanks.  Well that explains things.
I have been trying to learn C and the win32api use.  It is not easy to find info on win32api that is worked with directly, and most info of recent times having to do with C is info for C++.

   The functionX tutorials are so old on working directly with win32api, that I assumed it was C: though I now clearly see it was C++.

An irritating thing is that C information never talks about C++, and thus never gives you the differences. The differences are only described in information on C++, and I am not trying do C++ yet !! 

   Tx again