win32 and user defined classes

This is a discussion on win32 and user defined classes within the Windows Programming forums, part of the Platform Specific Boards category; #include <windows.h> #include "resource.h" and MS visual C++ prof 6 SP 5 I am fairly adept with c++ oo console ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    4

    Angry win32 and user defined classes

    #include <windows.h>
    #include "resource.h"
    and MS visual C++ prof 6 SP 5

    I am fairly adept with c++ oo console programming.

    I have been playing around with the win32 api. I have made a simple program which creates a pushbutton on the main window. When it's clicked it launches a dialog box where i wish to input data in an object.

    Now i tried to create a class but the compiler will not recognize class xxxx{} ....it gives me errors....

    what am i missing here....
    even this simple one will not work:
    class dayof year
    {
    public:
    void output();
    int month;
    int day;
    };
    //// this in the dialog proc
    dayofyear today;
    ////
    void dayofyear::output();
    {
    }
    Even trying structs gave me errors. Am i missing the whole point of win32 or what?


    PLease help. Source code example with user defined class in simple win32 app would be nice.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    class dayof year//Beware spaces where they shouldnt be
    {
    public:
    void output();
    int month;
    int day;
    };
    //// this in the dialog proc
    dayofyear today;
    ////
    void dayofyear::output();
    {
    }

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    4
    Still does not work... Gives me syntax error at the class xxxx line.

    Am i missing a include or what am i doing wroing

    I put the class def right after the includes. But it does not recognise this. Gives me syntax error

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    I'm not sure of exactly how your files are structured but this is what you would want:

    (I just used "doty" to shorten the filename)

    A file called doty.h which has:

    Code:
    #inndef DOTY_H
    #define DOTY_H
    
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    
    class dayoftheyear
    {
    public:
      //constructor
      dayoftheyear();
      //destructor
      ~dayoftheyear();
      void output();
      int month;
      int day;
    };
    
    #endit DOTY_H
    A file called doty.cpp which has:
    Code:
    #include "doty.h"
    
    dayotheyear::dayoftheyear()
    {
        //clean out any previous variable values
        month=0;
        day=0;
    }
    
    dayoftheyear::~dayoftheyear()
    {
       //clean up when you're done
       month=0;
       day=0;
    }
    
    void dayoftheyear::output()
    {
        char cDay[20], cMonth[20];
        _itoa(day,cDay,10);
        _itoa(month,cMonth,10);
        strcat(cMonth,"/");
        strcat(cMonth,cDay);
        MessageBox(NULL,cMonth,"debug",NULL);
    }
    In your main *.cpp file:

    Code:
    #include "doty.h"
    
    dayoftheyear dotyDay;
    Of course, I filled in the output function with a some generic stuff, just for the sake of example. Is this how your files are structured? Also, I recommend having at least 2 more functions ( 1 to set the day value and 1 to set the month value, if not even 2 additional functions to return the values set from the day and month individually ).

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    4
    The problem was i called my files with .c extension....whoops.

    should be .cpp

    Thanks for the help people
    Last edited by paulf; 04-17-2002 at 11:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  2. compiling and executing issue with lcc win32
    By GanglyLamb in forum C Programming
    Replies: 10
    Last Post: 12-22-2004, 01:24 PM
  3. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  4. Win32 API - Dynamic Link Library Loading - behind the scenes
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 04-05-2002, 07:31 AM
  5. Stopping a user from typeing.
    By knave in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2001, 12:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21