Hello, before I explain my problem I just wanted to say that I am quiet new to the programming.
I'll be quick and just describe the problem really briefly, I am attempting to create simple rectangle ( square ) on win32 application. I am using CodeBlocks and I have included the gdi32 and opengl32 library in build options.
However when I try to create rectangle using this function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <snake.hpp>
#include "intro_state.hpp"
#include <windows.h>
#include <vector>
void drawRectangle(Pen* pen, int x, int y, int width, int height)
{
Pen greenPen = new Pen(Color.Green, 3);
int x = 20;
int y = 20;
int width = 200;
int height = 200;
// Draw rectangle to screen
drawRectangle(greenPen, x, y, width, height)
}
I get this error:
1 2
..\..\inc\snake.hpp|13|error: 'Pen' has not been declared|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|
My header file for this particular function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef _LEVEL_HPP_
#define _LEVEL_HPP_
#include <intro_state.hpp>
#include <vector>
#include <windows.h>
#include <sstream>
#include <string>
class Snake
{
public:
void drawRectangle(Pen pen, int x, int y, int width, int height);
};
#endif // _LEVEL_HPP_
I really hope you guys can help me! I'd really appreciate it.
Thank you
well i'm not sure on rectangles (havn't drawn one in a while) but this is what i use to draw a filled ball
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics^ g = e->Graphics;
Graphics^ g1 = e->Graphics;
//create an ellipse with
// Black color
// start position = (10, 550) (start position is always Top Left of the object)
// width = 25 px, height = 25 px
g->SmoothingMode = Drawing2D::SmoothingMode::HighQuality;
g->FillEllipse(Brushes::Red, circlePos.X, circlePos.Y, 25, 25);
g->DrawEllipse(Pens::Black, circlePos.X, circlePos.Y, 25, 25);
}
okay yea so to draw a rectangle you use
1 2 3 4 5 6 7 8 9 10 11 12
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
// Paint event
Graphics^ g = e->Graphics;
//create class of g taking from Graphics class
int x = 20;
int y = 20;
Width = 200;
Height = 200;
g->DrawRectangle(Pens::Green, x, y, Width, Height;
}
This will draw a rectangle with size 20x20 at position 200x200 on screen
O btw the reason your getting the error 'Pen is not declared' is because the class is called 'Pens' not Pen. you have to be very exact in c++ especially if you don't have an intellisense library or the equivalent to your compiler
Erhmm, isn't that an example for forms? I am creating a snake game on client window (win32).
What I forgot to mention is that we have been provided with own library which include <windows.h> library. Correct me if Im wrong but doesn't Graphics^ @ line 3 belong to <graphics.h> library?
And lastly, I think you just got mixed on the last part. I think it draws a rectangle at position (20,20) of (200, 200 ) dimensions. And again please correct me if Im wrong.
Anyway, do u mind providing an example from <windows.h> library?
Ahh yes sorry I do apologize I must have skipped over the win32 application part my bad. I'm on my phone atm so can't give a code example but I will have alook as soon as I get on my pc if noone else replies by then.