![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 11
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
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
|
|
|
|
|
|
#3 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 884
Rep Power: 4
![]() |
Quote:
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 ) |
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jan 2006
Posts: 11
Rep Power: 0
![]() |
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 ![]() |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
lol no problem just don't do it again lol and good look with the programming
|
|
|
|
|
|
#6 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|