Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 9th, 2006, 10:11 AM   #1
diamondustice
Newbie
 
diamondustice's Avatar
 
Join Date: Jan 2006
Posts: 11
Rep Power: 0 diamondustice is on a distinguished road
help in making gui using win32 api

I'm new in C++. I'm developing an Image Processing Program. I'm using cygwin as my compiler. I'm working in Windows OS

I've already finished its functionalities but I haven't done the gui yet. As of now I'm only using the console to serve as the interface of the program but I need to create a GUI!

So I start from scratch to develop the gui and I plan to combine those two codes. I'm also new in win32 api. But I manage to succesfully create a gui with no functions. These two programs works fine on their own but when I combined them I encountered these problem.

My previous program(w/o gui) is build like this:
g++ -o myprog myprog.cpp binary.o jpegio.o color.o filter.o libjpeg.a

WHILE the program with gui is compiled like

myapp.exe : myapp.o myapp.res
gcc -mwindows myapp.o myapp.res -o $@

myapp.res : myapp.rc resource.h
windres $< -O coff -o $@

When I already combined these two codes I try to build it like this
gcc -mwindows myprog.cpp binary.o jpegio.o color.o filter.o libjpeg.a -o myprog.exe

and I received these errors: (I'm stucked here need some help..)

In file included from myprog.cpp:7:
image.h:57: macro `max' used without args
image.h:58: macro `min' used without args
image.h:125: macro `max' used without args
image.h:135: macro `min' used without args

This image.h works with no errors like above when the program has no gui(console mode).. when I used it with the windows.h to make the gui the error above is encountered.
Can anyone help me with this prob? thank you very much!

******this is the code of image.h******

#ifndef IMAGE_H
#define IMAGE_H

#include <iostream.h>

template <class T> // an image of type T
// use only simple types like int, unsigned char
// double or float, etc.
class Image {

private:
T* pixel;
int mHeight;
int mWidth;

public:
Image() { pixel = new T[1]; mHeight = mWidth = 0; }
Image(const Image<T> & img );
Image(int w, int h);

Image<T> & operator=(const Image<T> & img); // copy constructor

// OLD element access operator
inline T & operator () (int x, int y) const {
#ifdef IMAGE_RANGE_CHECK
// cout << "Test range check..." << endl;
if (y >= mHeight || x >= mWidth || y < 0 || x < 0) {
cout << "Cannot access pixel (" << x << "," << y <<
") of Image[" << mWidth << " x " << mHeight << "]!" << endl;
exit(1);
}
#endif
return pixel[y * mWidth + x];
}

// one-dimensional element access operator;
inline T & operator [] (int i) const {
#ifdef IMAGE_RANGE_CHECK
if (i >= mWidth * mHeight || i < 0) {
cout << "Cannot access pixel [" << i <<
"] of Image[" << mWidth * mHeight << "]!" << endl;
exit(1);
}
#endif
return pixel[i];
}

// destructor
~Image(){ delete [] pixel; }

void resize(int w, int h);
void setAll( T x ); // set the values

inline int height() const { return mHeight; }
inline int width() const { return mWidth; }
T max();
T min();
};


// --------------------------------------------------------------------

template <class T>
Image<T>::Image( const Image<T> & img ) { // important for functions returning Image
int h = img.height(), w = img.width(), i;
pixel = new T[1];
resize( w,h );
for (i = 0; i < w*h; i++) pixel[i] = img[i];
// for a faster alternative, replace previous line with the one below ;
// and... you must #include <string.h>
// memcpy( pixel, & img[0], sizeof(T) * w * h );
}


// set the image size only
template <class T>
Image<T>::Image( int w, int h ) {
pixel = new T[1];
resize( w,h );
}


// ---------------- Copy constructor -----------------------------------
template <class T>
Image<T> & Image<T>::operator=(const Image<T> & img) {
int w,h,i;
if ( this != &img ) { // don't copy to yourself
resize( w = img.width(), h = img.height() );
for (i = 0; i < w*h; i++) pixel[i] = img[i];
// for a faster alternative, replace previous line with the one below ;
// and... you must #include <string.h>
// memcpy( pixel, & Img[0] , sizeof(T) * ht * wd );
}
return *this;
}


//----------- Allocates memory for an image, no initialization -----------
template <class T>
void Image<T>::resize(int w, int h) {
int i;
delete [] pixel;

if (w * h == 0) {
cout << "CreateImage: invalid dimensions (" << w << " x " <<
h << ")..." << endl;
exit(1);
}

pixel = new T[w*h];
mWidth = w; mHeight = h;
}


// set the values of an image
template <class T>
void Image<T>::setAll( T x ) {
int n = width() * height();
for (int i = 0; i < n; i++) pixel[i] = x;
}

// return the maximum value of the image
template <class T>
T Image<T>::max() {
int i,imax,n = height()*width();
for (i=imax=0; i < n; i++)
if (pixel[i] > pixel[imax])
imax = i;
return pixel[imax];
}

// return the minimum value of the image
template <class T>
T Image<T>::min() {
int i,imin,n = height()*width();
for (i=imin=0; i < n; i++)
if (pixel[i] < pixel[imin])
imin = i;
return pixel[imin];
}



#define RED(pixel) ((pixel) & 0xff)
#define GREEN(pixel) (((pixel)>>8) & 0xff)
#define BLUE(pixel) (((pixel)>>16) & 0xff)
#define COLOR_RGB(r,g,b) (((b)<<16)+((g)<<8)+(r))



class RGBImage : public Image<int> {

public:
RGBImage() { };
~RGBImage() { };
inline void setPix( int x, int y, unsigned char r, unsigned char g, unsigned char b) {
(*this)(x,y) = COLOR_RGB(r,g,b);
}
inline void setPix( int i, unsigned char r, unsigned char g, unsigned char b) {
(*this)[i] = COLOR_RGB(r,g,b);
}
};




#endif
diamondustice is offline   Reply With Quote
Old Jan 9th, 2006, 10:38 AM   #2
HaCkeR
Hobbyist Programmer
 
HaCkeR's Avatar
 
Join Date: Nov 2005
Location: UK
Posts: 131
Rep Power: 0 HaCkeR is an unknown quantity at this point
Send a message via AIM to HaCkeR Send a message via MSN to HaCkeR
May i strongly suggest you read the rules. As the first thing anyone will say to you is post you code in the "[code]" tags
HaCkeR is offline   Reply With Quote
Old Jan 9th, 2006, 9:29 PM   #3
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 884
Rep Power: 4 The Dark is on a distinguished road
Quote:
in file included from myprog.cpp:7:
image.h:57: macro `max' used without args
image.h:58: macro `min' used without args
image.h:125: macro `max' used without args
image.h:135: macro `min' used without args
This means that there are macros called "max" and "min" that are being defined somewhere (probably included from windows.h). These are clashing with your own "max" and "min" methods.
The best way around it is probably to use different names for your member functions (like "maximum" and "minimum").

Oh, and post in [code] tags (its the second thing anyone will say :p )
The Dark is offline   Reply With Quote
Old Jan 10th, 2006, 11:29 PM   #4
diamondustice
Newbie
 
diamondustice's Avatar
 
Join Date: Jan 2006
Posts: 11
Rep Power: 0 diamondustice is on a distinguished road
Thanks a lot The Dark! You EnLIGHTened me That solved my problem.. Whew! and OOoops.. It's kinda obvious I'm new here so sorry bout the code
diamondustice is offline   Reply With Quote
Old Jan 11th, 2006, 10:33 AM   #5
HaCkeR
Hobbyist Programmer
 
HaCkeR's Avatar
 
Join Date: Nov 2005
Location: UK
Posts: 131
Rep Power: 0 HaCkeR is an unknown quantity at this point
Send a message via AIM to HaCkeR Send a message via MSN to HaCkeR
lol no problem just don't do it again lol and good look with the programming
HaCkeR is offline   Reply With Quote
Old Jan 11th, 2006, 10:57 AM   #6
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by diamondustice
Thanks a lot The Dark! You EnLIGHTened me That solved my problem.. Whew! and OOoops.. It's kinda obvious I'm new here so sorry bout the code
Yeah it's obvious, that's why there is also an obvious "How to post a question" thread at the top of the forum .
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:26 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC