Hi!
I had creater a workspace with 2 projects, uno is MFC APP Wizzar(exe) named "draw" and other WIN32 Console Application named as "Principal". What I want it to call "draw" from "Principal". In principal i select a number between 1 to 11. I check global variables coordinates that corresponds to the number, I save them in other global variables and then I call OnDraw(pDC). Because of the Globeal Variables mi intention to call pDC->Ellipse(x1,y1,x2,y2) from OnDraw so I can draw a cicrcle with the data stored in the variables.
I can compile the 2 projects separately and I get no errors but when I want to run Principal.exe I got 0 x C0000005: Acces Violation errer. I guess the problem is in the OnDraw() function call. How can I call Ondraw() form other project?
Here I put the main code and the draw code.
Hope someone can help
Thank you!
********* CÓDIGO DE PRINCIPAL ************
#include <iostream.h>
#include "stdafx.h"
#include "draw.h"
#include "drawDoc.h"
#include "drawView.h"
//////////////////////////////
// INITIALS COORDENATES //
//////////////////////////////
int Coord_x1 [ ] = {450, 300, 200, 350, 550, 700, 800, 650, 475, 625, 550};
int Coord_y1 [ ] = { 50, 150, 350, 450, 500, 450, 275, 100, 300, 300, 400};
int Coord_x2 [ ] = {750, 600, 500, 650, 850,1000,1125, 950, 675, 825, 750};
int Coord_y2 [ ] = {350, 450, 650, 750, 800, 750, 600, 400, 500, 500, 600};
int x1,y1,x2,y2;
CDrawView *drawer;
CDC *pDC;
/////////////////////////////////////////////////
// SUBSCRIBE //
/////////////////////////////////////////////////
void main () {
int num;
cout << "Number of Antenna: " << endl;
cin >> num;
x1= Coord_x1[num-1];
y1= Coord_y1[num-1];
x2= Coord_x2[num-1];
y2= Coord_y2[num-1];
drawer ->OnDraw(pDC);
}
******** CODIGO DE drawView.cpp **********
int x1,y1,x2,y2;
void CDrawView::OnDraw(CDC* pDC) {
CDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/////////////////////////////////////////////////////
// wRITE TEXT //
/////////////////////////////////////////////////////
char text [] = "Cover zone for mobile telephony ";
pDC ->SetTextColor(RGB(0,0,0));
pDC ->TextOut(25,25,text,strlen (text));
//////////////////////////////////////////////////////
// DRAW POLYGON //
//////////////////////////////////////////////////////
CPen * draw_poly;
CPen Pen (PS_SOLID, 3, RGB (0,0,0));
POINT points [7] = {600, 50, 350, 250, 250, 550, 550, 750, 950, 650, 1100, 350, 600, 50};
draw_poly = pDC ->SelectObject(&Pen);
pDC ->Polyline (points,7);
pDC ->SelectObject (Pen);
//////////////////////////////////////////////////////
// DRAW CIRCLES //
//////////////////////////////////////////////////////
CPen * draw_circles;
CPen Pen2 (PS_SOLID, 1, RGB (0,0,0));
CBrush * antiguoRelleno;
CBrush Relleno (RGB (0,0,255));
draw_circles = pDC ->SelectObject(&Pen2);
antiguoRelleno = pDC ->SelectObject (&Relleno);
pDC->Ellipse(x1,y1,x2,y2);
pDC ->SelectObject (Pen2);
}
I had creater a workspace with 2 projects, uno is MFC APP Wizzar(exe) named "draw" and other WIN32 Console Application named as "Principal". What I want it to call "draw" from "Principal". In principal i select a number between 1 to 11. I check global variables coordinates that corresponds to the number, I save them in other global variables and then I call OnDraw(pDC). Because of the Globeal Variables mi intention to call pDC->Ellipse(x1,y1,x2,y2) from OnDraw so I can draw a cicrcle with the data stored in the variables.
I can compile the 2 projects separately and I get no errors but when I want to run Principal.exe I got 0 x C0000005: Acces Violation errer. I guess the problem is in the OnDraw() function call. How can I call Ondraw() form other project?
Here I put the main code and the draw code.
Hope someone can help
Thank you!
********* CÓDIGO DE PRINCIPAL ************
#include <iostream.h>
#include "stdafx.h"
#include "draw.h"
#include "drawDoc.h"
#include "drawView.h"
//////////////////////////////
// INITIALS COORDENATES //
//////////////////////////////
int Coord_x1 [ ] = {450, 300, 200, 350, 550, 700, 800, 650, 475, 625, 550};
int Coord_y1 [ ] = { 50, 150, 350, 450, 500, 450, 275, 100, 300, 300, 400};
int Coord_x2 [ ] = {750, 600, 500, 650, 850,1000,1125, 950, 675, 825, 750};
int Coord_y2 [ ] = {350, 450, 650, 750, 800, 750, 600, 400, 500, 500, 600};
int x1,y1,x2,y2;
CDrawView *drawer;
CDC *pDC;
/////////////////////////////////////////////////
// SUBSCRIBE //
/////////////////////////////////////////////////
void main () {
int num;
cout << "Number of Antenna: " << endl;
cin >> num;
x1= Coord_x1[num-1];
y1= Coord_y1[num-1];
x2= Coord_x2[num-1];
y2= Coord_y2[num-1];
drawer ->OnDraw(pDC);
}
******** CODIGO DE drawView.cpp **********
int x1,y1,x2,y2;
void CDrawView::OnDraw(CDC* pDC) {
CDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/////////////////////////////////////////////////////
// wRITE TEXT //
/////////////////////////////////////////////////////
char text [] = "Cover zone for mobile telephony ";
pDC ->SetTextColor(RGB(0,0,0));
pDC ->TextOut(25,25,text,strlen (text));
//////////////////////////////////////////////////////
// DRAW POLYGON //
//////////////////////////////////////////////////////
CPen * draw_poly;
CPen Pen (PS_SOLID, 3, RGB (0,0,0));
POINT points [7] = {600, 50, 350, 250, 250, 550, 550, 750, 950, 650, 1100, 350, 600, 50};
draw_poly = pDC ->SelectObject(&Pen);
pDC ->Polyline (points,7);
pDC ->SelectObject (Pen);
//////////////////////////////////////////////////////
// DRAW CIRCLES //
//////////////////////////////////////////////////////
CPen * draw_circles;
CPen Pen2 (PS_SOLID, 1, RGB (0,0,0));
CBrush * antiguoRelleno;
CBrush Relleno (RGB (0,0,255));
draw_circles = pDC ->SelectObject(&Pen2);
antiguoRelleno = pDC ->SelectObject (&Relleno);
pDC->Ellipse(x1,y1,x2,y2);
pDC ->SelectObject (Pen2);
}