עבור לתוכן

בעיה ב CPP WIN 32 API לאחר הוספת עוד קובץ

Featured Replies

פורסם

אחרי שהוספתי עוד קובץ של players (סתם שם)

כדי להשים שמה את ה CLASS

קובץ אחד של CPP ואחד של H נוצרה בעיה שאין לי מושג איך לפתור אותה..אני עובד עם VISUAL STUDIO 2003

אני אצרף פה את כל הפרוייקט אם מישהו יוכל לעזור לי אני אודה לו מאוד..

אם תוכלו חוץ מהעזרה לתת גם כמה עצות לשיפור הפרוייקט זה יעזור מאוד ..

(אני עושה משחק כובש/סוגר שטחים)

הקובץ נמצא פה http://www.f2h.co.il/866751 האתר הזה עושה קצת בעיות עם FF אז תנסו ישר עם IE טאב או אקספלורר..

תודה רבה

פורסם

אולי תספר לנו מה הבעיה?

פורסם
  • מחבר

חשבתי שזה ברור

יש שגיאה שאין לי מושג איך לפתור אותה משהו עם uneccepted end של הקובץ..פעם ראשונה שאני רואה דבר כזה..

פורסם

אם תכתוב כאן את הקוד הרלוונטי ואת השגיאה יהיה הרבה יותר פשוט לעזור לך.

פורסם

וגם את השגיאה המדוייקת.

תבדוק שיש לך נקודה פסיק בסוף הגדרת המחלקה.

פורסם
  • מחבר

אם תכתוב כאן את הקוד הרלוונטי ואת השגיאה יהיה הרבה יותר פשוט לעזור לך.

לא יותר פשוט להוריד את כל הפרוייקט כמו שהבאתי פה ופשוט להפעיל אותו ..אבל איך שבא לכם..

conq.cpp

// conq.cpp : Defines the entry point for the application.
//
#include <windows.h>
#include "stdafx.h"
#include "conq.h"
#include "players.h"
//#include <iostream.h>


#define MAX_LOADSTRING 100

int fMouse,cButtons;
int screen;
HFONT BigSidewayFont,font2;
HBRUSH hBluebrush,hGreenbrush,hRedbrush,hYellowbrush,hAzurebrush;

HPEN hRedpen,hBluepen,hYellowpen;
COLORREF bkAzure,bkGreen,bkRed,bkYellow,bkBlue; //הצהרת משתנים מסוג COLORREF
//בשביל ה"הצבע האחורי" של הכתב
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

void PaintWelcomeScr(HWND hWnd,HDC hdc,WPARAM xPos,WPARAM yPos);
void PaintHelpScr(HWND hWnd,HDC hdc,WPARAM xPos,WPARAM yPos);
void PaintGameScr(HWND hWnd,HDC hdc,int Xplayer, int Yplayer,int Xdown,int Ydown);
void PaintExitScr(HWND hWnd,HDC hdc);
void PaintRecScr(HWND hWnd,HDC hdc,WPARAM xPos,WPARAM yPos);


int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
Player p();
MSG msg;
HACCEL hAccelTable;
screen=1;
bkAzure = RGB(11,155,242); //הגדרת הצבע התכלת
hAzurebrush = CreateSolidBrush(RGB(11,155,242));

bkGreen = RGB(3,250,21); //הגדרת הצבע הירוק
hGreenbrush = CreateSolidBrush(RGB(3,250,21));

bkRed=RGB(248,5,12); //הגדרת הצבע האדום
hRedbrush = CreateSolidBrush(RGB(248,5,12));
hRedpen = CreatePen(PS_SOLID,3,RGB(248,5,12));

bkYellow =RGB(243,226,10); //הגדרת הצבע הצהוב
hYellowbrush = CreateSolidBrush(RGB(243,226,10));
hYellowpen = CreatePen(PS_SOLID,2,RGB(255,255,0));

bkBlue =RGB(0,0,255); //הגדרת הצבע הכחול
hBluebrush = CreateSolidBrush(RGB(0,0,255));
hBluepen = CreatePen(PS_SOLID,2,RGB(0,100,255));



// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CONQ, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CONQ);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_CONQ);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR)IDC_CONQ;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
0, 0, 1032, 743, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, SW_MAXIMIZE);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;


PAINTSTRUCT ps;
HDC hdc;
RECT rect;
// HBRUSH hBluebrush,hGreenbrush,hRedbrush;
// HPEN hRedpen,hBluepen,hYellowpen;
int xPos=LOWORD(lParam),yPos=HIWORD(lParam);

BigSidewayFont=CreateFont(70,90,90,50,FW_BOLD,TRUE,0,0,0,0,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"EliorFont1"); //הגדרת פונט גדול שנוטה לצד
font2=CreateFont(25,30,0,0,FW_BOLD,TRUE,0,0,0,0,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"EliorFont2"); //הגדרת פונט

switch (message)
{
case WM_LBUTTONDOWN:
{
hdc=GetDC(hWnd);
switch(screen)
{
case 1:
{
if((340<xPos)&&(xPos<700)&&(100<yPos)&&(yPos<150)&& screen==1)
{
screen=4;
PaintGameScr(hWnd,hdc,505,685,515,695);

}
if((340<xPos)&&(xPos<700)&&(240<yPos)&&(yPos<290)&&screen==1)
{
screen=2;
PaintHelpScr(hWnd,hdc,xPos,yPos);

}
if((340<xPos)&&(xPos<700)&&(310<yPos)&&(yPos<360)&&screen==1)
{
screen=3;
PaintExitScr(hWnd,hdc);
}
if((340<xPos)&&(xPos<700)&&(170<yPos)&&(yPos<220)&&screen==1)
{
screen=5;
PaintRecScr(hWnd,hdc,xPos,yPos);
}
}break;
case 2:
{
if((790<xPos)&&(xPos<1000)&&(40<yPos)&&(yPos<85)&&screen==2)
{
PaintWelcomeScr(hWnd,hdc, xPos, yPos);
screen=1;
}
}break;
case 5:
{
if((790<xPos)&&(xPos<1000)&&(40<yPos)&&(yPos<85)&&screen==5)
{
PaintWelcomeScr(hWnd,hdc, xPos, yPos);
screen=1;
}
}break;

}
}break;

case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd,&rect);
switch(screen)
{
case 1:
{
PaintWelcomeScr(hWnd,hdc, xPos, yPos);
}break;
case 2:
{
PaintHelpScr(hWnd,hdc,xPos,yPos);
}break;
case 3:
{
PaintExitScr(hWnd,hdc);
}break;
case 4:
{
PaintGameScr(hWnd,hdc,505,685,515,695);
}break;
case 5:
{
PaintRecScr(hWnd,hdc,xPos,yPos);
}break;

}


// TODO: Add any drawing code here...

EndPaint(hWnd, &ps);
break;
case WM_DESTROY:

PostQuitMessage(0);
break;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{


case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

void PaintWelcomeScr(HWND hWnd,HDC hdc,WPARAM xPos,WPARAM yPos)
{
SelectObject(hdc,hBluebrush);//בחירה בצבע כחול
Rectangle(hdc,0,0,1024,690);
SelectObject(hdc,font2);
SetBkColor(hdc,bkBlue);
SetTextColor(hdc,RGB(162,0,166));
TextOut(hdc,300,50,"The Conqueror",13);
SelectObject(hdc,hAzurebrush);
RoundRect(hdc,340,100,700,150,20,20);
SetBkColor(hdc,bkAzure);
SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc,350,115,"NEW GAME",8);
SelectObject(hdc,hGreenbrush);
RoundRect(hdc,340,170,700,220,20,20);
SetBkColor(hdc,bkGreen);
TextOut(hdc,370,185,"RECORDS",7);
SelectObject(hdc,hRedbrush);
RoundRect(hdc,340,240,700 ,290,20,20);
SetBkColor(hdc,bkRed);
TextOut(hdc,440,255,"HELP",4);
SelectObject(hdc,hYellowbrush);
RoundRect(hdc,340,310,700,360,20,20);
SetBkColor(hdc,bkYellow);
TextOut(hdc,450,325,"EXIT",4);

/* DeleteObject(hBluebrush);
DeleteObject(font2);
DeleteObject(hAzurebrush);
DeleteObject(hGreenbrush);*/

if((340<xPos)&&(xPos<700)&&(100<yPos)&&(yPos<150)&&screen==1)
{
PaintGameScr(hWnd,hdc,505,685,515,695);
screen= 4;
}
if((340<xPos)&&(xPos<700)&&(240<yPos)&&(yPos<290)&&screen==1)
{
PaintHelpScr(hWnd,hdc,xPos,yPos);
screen= 2;
}
if((340<xPos)&&(xPos<700)&&(310<yPos)&&(yPos<360)&&screen==1)
{
PaintExitScr(hWnd,hdc);
screen= 3;
}

if((340<xPos)&&(xPos<700)&&(170<yPos)&&(yPos<220)&&screen==1)
{
PaintExitScr(hWnd,hdc);
screen= 5;
}



// fMouse=GetSystemMetrics(SM_MOUSWPRESENT); //חיובי אם עכבר קיים

// if(fMouse)
// {
// cButtons=GetSystemMetrics(SM_MOUSEBUTTONS); //מחזיר מספר לחצני עכבר
/* switch(wParam)
case MK_LBUTTON:
{
if((340<LOWORD(lParam)<700) && (100<HIWORD(lParam)<150))
PaintGameScr(hWnd,hdc);
}break;
// }*/

}

void PaintHelpScr(HWND hWnd,HDC hdc,WPARAM xPos,WPARAM yPos)
{
SelectObject(hdc,hBluebrush);
Rectangle(hdc,0,0,1024,690);
SelectObject(hdc,font2);
SetBkColor(hdc,bkBlue);
TextOut(hdc,100,50,"The Conqueror HELP",18);
SelectObject(hdc,hRedbrush);
RoundRect(hdc,790,40,1000,85,20,20);
SetTextColor(hdc,RGB(0,255,0));
SetBkColor(hdc,bkRed);
TextOut(hdc,800,50,"BACK",4);

/* DeleteObject(hBluebrush);
DeleteObject(font2);
DeleteObject(hRedbrush);*/

if((790<xPos)&&(xPos<1000)&&(40<yPos)&&(yPos<85)&&screen==2)
{
PaintWelcomeScr(hWnd,hdc, xPos, yPos);
screen= 1;
}


}

void PaintGameScr(HWND hWnd,HDC hdc,int Xup, int Yup,int Xdown,int Ydown)
{
POINT p1;
SelectObject(hdc,hRedpen);
SelectObject(hdc,hYellowbrush);
Rectangle(hdc,1,1,1024,690);
SelectObject(hdc,hBluebrush);
SelectObject(hdc,hBluepen);
Rectangle(hdc,Xup,Yup,Xdown,Ydown);
SelectObject(hdc,hBluepen);
MoveToEx(hdc,0,20,&p1);
LineTo(hdc,1024,20);
TextOut(hdc,5,3,"Time:",5);
TextOut(hdc,475,3,"To exit press Esc",17);

/* DeleteObject(hYellowpen);
DeleteObject(hRedbrush);
DeleteObject(hRedpen);
DeleteObject(hBluepen);*/
}

void PaintExitScr(HWND hWnd,HDC hdc)
{
/*SelectObject(hdc,hRedbrush);
Rectangle(hdc,0,0,1024,690);
SetBkColor(hdc,RGB(0,255,0));
SetTextColor(hdc,RGB(0,0,255));
SelectObject(hdc,BigSidewayFont);
TextOut(hdc,100,350,"BYE BYE",7);*/
MessageBeep(MB_OK);
if(MessageBox(hWnd,"Do you wish to exit?","EXIT",MB_YESNO | MB_ICONQUESTION)==IDYES)
DestroyWindow(hWnd);
else screen=1;
}

void PaintRecScr(HWND hWnd,HDC hdc,WPARAM xPos,WPARAM yPos)
{
SelectObject(hdc,hBluebrush);
Rectangle(hdc,0,0,1024,690);
SelectObject(hdc,font2);
SetTextColor(hdc,RGB(0,255,255));
SetBkColor(hdc,bkBlue);
TextOut(hdc,400,75,"Records",7);
SelectObject(hdc,hRedbrush);
RoundRect(hdc,790,40,1000,85,20,20);
SetTextColor(hdc,RGB(0,255,0));
SetBkColor(hdc,bkRed);
TextOut(hdc,800,50,"BACK",4);

/* DeleteObject(hBluebrush);
DeleteObject(font2);
DeleteObject(hRedbrush);*/

if((790<xPos)&&(xPos<1000)&&(40<yPos)&&(yPos<85)&&screen==5)
{
PaintWelcomeScr(hWnd,hdc, xPos, yPos);
screen=1; //screen=1
}
}


players.h

#ifndef PLAYER_H

#define PLAYER_H

class Player
{
private:
int Xpos,Ypos;

public:
Player();
void ShowPlayer(int Xpos,int Ypos);

};

#endif

players.cpp

#include "players.h"
//#include "conq.h"
//#include <windows.h>



Player::Player()
{
Xpos=512;
Ypos=690;
}

void Player::ShowPlayer(int Xpos,int Ypos)
{
// PaintGameScr(hWnd,hdc,Xpos-=7,Ypos-=5,Xpos+=3,Ypos+=5);
}

שגיאה fatal error C1010: unexpected end of file while looking for precompiled header directive

ראוי לציין שהשגיאה הגיע מיד לאחר שהוספתי עוד קובץ ( players.h , players.cpp ) לפרוייקט..לפני כן הכל היה בסדר..

פורסם

תוודא ששם המחלקה ושם הקובץ זהה.

פורסם
  • מחבר

אותו שם עדיין אותה השגיאה :P

פורסם
  • מחבר

תודה קובי :xyxthumbs:

באמת ההוספה של stdafx.h פתרה את הבעיה..

עכשיו יש לי טעויות אחרות..נדמה לי שזה בגלל שלא קישרתי נכון בין הקבצים players.cpp ו players.h איך אני אמור לעשות את זה..

אני כתבתי ב players.cpp ככה.

#include "players.h"

זה מספיק?

בכל מקרה הטעויות הן אלה:

error C2653: 'Player' : is not a class or namespace name

error C2065: 'Xpos' : undeclared identifier

error C2065: 'Ypos' : undeclared identifier

error C2653: 'Player' : is not a class or namespace name

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים