|
-
March 28th, 2012, 11:57 AM
#8
Re: Class Constructor Parameters
Okay, will then post my entire code, along with the error. I will ignore the files i got that are currently empty, since they dont really do anything.
main.cpp
Code:
#include <windows.h>
#include "include/WinProcedure.h"
#include "include/WSmaker.h"
#include "include/WinClass.h"
#include "include/WinException.h"
#include "include/WinMenuFile.h"
#include "include/OpenFile.h"
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
MSG msg;
WinClassMain WCM1(hInstance, WndProc);
WCM1.DeclareWinProp ();
WCM1.RegisterWin ();
WinCreator Wincreate(WCM1);
Wincreate.CreateWin();
Wincreate.ShowWin(CmdShow);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) &msg.wParam;
}
WSmaker and WinException are both empty at the moment.
WinProcedure.h
Code:
#ifndef WINPROCEDURE_H_INCLUDED
#define WINPROCEDURE_H_INCLUDED
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
#endif // WINPROCEDURE_H_INCLUDED
WinProcedure.cpp
Code:
#include <windows.h>
#include "WinProcedure.h"
#include "Resources.h"
#include "WinMenuFile.h"
#include "OpenFile.h"
#include "SaveFile.h"
HWND ghwndEdit;
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
AddMenus(hwnd);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_FILE_NEW:
::MessageBox (hwnd, "Not Implemented Yet!", "New File", MB_ICONINFORMATION | MB_OK);
break;
case IDM_FILE_OPEN:
OpenDialog(hwnd);
break;
case IDM_FILE_SAVE:
::MessageBox (hwnd, "Not Implemented Yet!", "Save File", MB_ICONINFORMATION | MB_OK);
break;
case IDM_FILE_SAVEAS:
SaveDialog(hwnd);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void LoadFile(LPSTR file)
{
HANDLE hFile;
DWORD dwSize;
DWORD dw;
LPBYTE lpBuffer = NULL;
hFile = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
dwSize = GetFileSize(hFile, NULL);
lpBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwSize + 1);
ReadFile(hFile, (LPWSTR)lpBuffer, dwSize, &dw, NULL);
CloseHandle(hFile);
lpBuffer[dwSize] = 0;
SetWindowText(ghwndEdit, (LPSTR) lpBuffer);
HeapFree(GetProcessHeap(), 0, lpBuffer);
}
void SaveFile(LPSTR)
{
}
Resources.h
Code:
#ifndef RESOURCES_H_INCLUDED
#define RESOURCES_H_INCLUDED
#define IDM_FILE_NEW 1
#define IDM_FILE_OPEN 2
#define IDM_FILE_SAVE 3
#define IDM_FILE_SAVEAS 4
#endif // RESOURCES_H_INCLUDED
WinMenuFile.h
Code:
#ifndef WINMENUFILE_H_INCLUDED
#define WINMENUFILE_H_INCLUDED
#include "Resources.h"
void AddMenus(HWND);
#endif // WINMENUFILE_H_INCLUDED
WinMenuFile.cpp
Code:
#include <windows.h>
#include "WinMenuFile.h"
#include "Resources.h"
void AddMenus(HWND hwnd)
{
HMENU hMenubar;
HMENU hMenu;
hMenubar = CreateMenu();
hMenu = CreateMenu();
AppendMenu(hMenu, MF_STRING, IDM_FILE_NEW, "&New");
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, IDM_FILE_OPEN, "&Open");
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, IDM_FILE_SAVE, "&Save");
AppendMenu(hMenu, MF_STRING, IDM_FILE_SAVEAS, "&Save as");
AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hMenu, "&File");
SetMenu(hwnd, hMenubar);
}
WinClass.h
Code:
#ifndef WINCLASS_H_INCLUDED
#define WINCLASS_H_INCLUDED
#include "WinProcedure.h"
#include <string>
class WinClassPara
{
public:
WinClassPara (HINSTANCE hInstance): hInst (hInstance){}
HINSTANCE GethInst () const { return hInst; }
char const * GetwcName () const {return wcName.c_str();}
protected:
HINSTANCE hInst;
std::string wcName;
};
class WinClassMain: public WinClassPara
{
public:
WinClassMain (HINSTANCE hInstance, WNDPROC WndProc);
void RegisterWin();
void DeclareWinProp();
protected:
WNDCLASSEX wc;
};
class WinCreator: public WinClassMain
{
public:
WinCreator(); //Here is the issue.
operator HWND () {return _hwnd;}
void CreateWin();
void ShowWin(int nShowWin = SW_SHOWNORMAL);
protected:
WinClassMain & wc;
HWND _hwnd;
DWORD ExStyle;
char const * WinName;
DWORD Style;
int xPos;
int yPos;
int cHeight;
int cWidth;
HWND WinOwn;
HMENU Menu;
void * Data;
};
#endif // WINCLASS_H_INCLUDED
WinClass.cpp
Code:
#include <windows.h>
#include "WinClass.h"
#include "Resources.h"
WinClassMain::WinClassMain(HINSTANCE hInstance, WNDPROC WndProc): WinClassPara (hInstance)
{
wc.lpfnWndProc = WndProc;
DeclareWinProp();
}
void WinClassMain::DeclareWinProp()
{
wc.lpszClassName = GetwcName();
wc.hInstance = GethInst ();
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.cbSize = sizeof(wc);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
}
void WinClassMain::RegisterWin()
{
RegisterClassEx(&wc);
}
// And also here, where i need the parameters again.
WinCreator::WinCreator ()
:_hwnd (0), wc (),
ExStyle (0), WinName (0), Style (WS_OVERLAPPED), xPos (CW_USEDEFAULT), yPos (0), cHeight (CW_USEDEFAULT),
cWidth (0), WinOwn (0), Menu (0), Data (0)
{
}
void WinCreator::CreateWin()
{
CreateWindowEx(ExStyle, GetwcName(), WinName, Style, xPos, yPos, cHeight, cWidth, WinOwn, Menu, GethInst (), Data);
}
void WinCreator::ShowWin(int nShowWin)
{
::ShowWindow (_hwnd, nShowWin);
::UpdateWindow (_hwnd);
}
OpenFile.h
Code:
#ifndef OPENFILE_H_INCLUDED
#define OPENFILE_H_INCLUDED
void OpenDialog(HWND);
void LoadFile(LPSTR);
#endif // OPENFILE_H_INCLUDED
OpenFile.cpp
Code:
#include <windows.h>
#include "Resources.h"
#include "OpenFile.h"
void OpenDialog(HWND hwnd)
{
OPENFILENAME ofn;
TCHAR szFile[MAX_PATH];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.hwndOwner = hwnd;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = TEXT("All Files(*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = NULL;
ofn.lpstrFileTitle = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetOpenFileName(&ofn))
{
LoadFile(ofn.lpstrFile);
}
}
SaveFile.h
Code:
#ifndef SAVEFILE_H_INCLUDED
#define SAVEFILE_H_INCLUDED
void SaveDialog(HWND);
void SaveFile(LPSTR);
#endif // SAVEFILE_H_INCLUDED
SaveFile.cpp
Code:
#include <windows.h>
#include "SaveFile.h"
#include "Resources.h"
void SaveDialog(HWND hwnd)
{
OPENFILENAME sfn;
TCHAR szSaveFileName[MAX_PATH];
ZeroMemory(&sfn, sizeof(sfn));
sfn.lStructSize = sizeof(sfn);
sfn.lpstrFile = szSaveFileName;
sfn.hwndOwner = hwnd;
sfn.nMaxFile = sizeof(szSaveFileName);
sfn.lpstrFilter = TEXT("AndysLvlEditorFile (*.Alef)\0*.Alef\0*All Files(*.*)\0*.*\0");
sfn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
sfn.lpstrDefExt = "Alef";
if(GetSaveFileName(&sfn))
{
SaveFile(sfn.lpstrFile);
}
}
And as for the error im getting:
||=== Level Editor, Debug ===|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.h||In constructor 'WinCreator::WinCreator()':|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.h|43|warning: 'WinCreator::_hwnd' will be initialized after|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.h|42|warning: 'WinClassMain& WinCreator::wc'|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.cpp|36|warning: when initialized here|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.cpp|39|error: no matching function for call to 'WinClassMain::WinClassMain()'|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.cpp|5|note: candidates are: WinClassMain::WinClassMain(HINSTANCE__*, LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM))|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.h|20|note: WinClassMain::WinClassMain(const WinClassMain&)|
C:\Documents and Settings\nkpit09aski\Mina dokument\Dropbox\Spelet - P100\RIKTIGT HEMLIG PROGRAMMERINGSKOD\Andreas Brosum LvL editor of Awesumness\Level Editor\include\WinClass.cpp|36|error: value-initialization of 'WinClassMain& WinCreator::wc', which has reference type|
||=== Build finished: 2 errors, 3 warnings ===|
The exact error im referring to is this:
error: no matching function for call to 'WinClassMain::WinClassMain()'|
That is so far my entire level editor. Hope it isnt too hard to read.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|