|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Win32 API is Haaard help |
|
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
Ive been trying to set up a class for creating and registering a basic win32 application so i can work on my game , but im getting lots of errors... can u give me some advice on this?// cApplication.h // Creates and Manages Win32 Window Application // Armando Alva@2005 #ifndef CAPPLICATION_H__ #define CAPPLICATION_H__ #include <windows.h> #include <iostream> class cApplication { public: // Constructor Destructor cApplication(); ~cApplication(); // WindowClassEx WNDCLASSEX wcex; // WindowHandle HWND hWnd; // Methods void CreateWnd(); void RegisterWnd(); private: } #endif // cApplication.cpp // Definition for cApplication.h // Armando Alva@2005 #include "cApplication.h" // ----------------------------------------------------- // Constructor Destructor // ----------------------------------------------------- cApplication() { RegisterWnd(); CreateWnd(); } ~cApplication() { // Do Nothing (for now) } // ----------------------------------------------------- // RegisterWnd() // ----------------------------------------------------- void cApplication::RegisterWnd() { // Registering Window Class wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = MsgProc; // Points to the name of the MsgProcedure funct. wcex.cbWndExtra = 0L; wcex.cbClsExtra = 0L; wcex.hInstance = GetModuleHandle(NULL); // Or hInstance wcex.hIcon = NULL; wcex.hCursor = NULL; wcex.hbrBackground = NULL; wcex.hIconSm = NULL; wcex.lpszMenuName = NULL; wcex.lpszClassName = "Game Class"; if(!RegisterClassEx(&wcex)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_OK); } } // ----------------------------------------------------- // CreateWnd() // ----------------------------------------------------- void cApplication::CreateWnd() { hWnd = CreateWindowEx(NULL, "Game Class", "Double Dragon Clone", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, NULL, NULL, wcex.hInstance, NULL); } // ----------------------------------------------------- // WinMain.cpp // Application Main Starting Point // Armando Alva@2005 // ----------------------------------------------------- #include <windows.h> #include "cApplication.h" INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT) { cApplication TestApp; } |
||||
|
||||
![]() KittyRa Member since: 1/9/2005 From: Ann Arbor, MI, United States |
||||
|
|
||||
| Can you post the errors please so we can help more |
||||
|
||||
![]() Spoonbender Member since: 1/7/2003 From: Copenhagen, Denmark |
||||
|
|
||||
Not unless you tell us what the problem is ![]() |
||||
|
||||
![]() Dave Member since: 3/22/2004 From: London, United Kingdom |
||||
|
|
||||
| I found it extremely hard as well, so i moved to wxWidgets. wxWidgets is marvellous quite frankly and i recommend it to anyone looking for a quick GUI. Here is the linky. Seriously, USE IT, it rocks. Hope it helps you, im sure it will... ace |
||||
|
||||
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
Ok only beacuse uve asked it1>Compiling... 1>cApplication.cpp 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(12) : error C3861: 'RegisterWnd': identifier not found 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(13) : error C3861: 'CreateWnd': identifier not found 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(16) : error C2588: '::~cApplication' : illegal global destructor 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(17) : error C2556: 'int cApplication(void)' : overloaded function differs only by return type from 'cApplication cApplication(void)' 1> c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(10) : see declaration of 'cApplication' 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(17) : error C2371: 'cApplication' : redefinition; different basic types 1> c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(10) : see declaration of 'cApplication' 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(29) : error C2065: 'MsgProc' : undeclared identifier 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(38) : error C2440: '=' : cannot convert from 'const char [11]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(42) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(54) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>WinMain.cpp 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : error C2143: syntax error : missing ';' before '__stdcall' 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : error C2377: 'INT' : redefinition; typedef cannot be overloaded with any other symbol 1> c:\archivos de programa\microsoft visual studio 8\vc\include\windef.h(171) : see declaration of 'INT' 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : error C2061: syntax error : identifier 'INT' 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(11) : error C2731: 'WinMain' : function cannot be overloaded 1> c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : see declaration of 'WinMain' 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(13) : warning C4508: 'WinMain' : function should return a value; 'void' return type assumed 1>Generating Code... 1>Build log was saved at "file://c:\Documents and Settings\Armando Alva\Mis documentos\Visual Studio 2005\Projects\Double Dragon Clone\Double Dragon Clone\Debug\BuildLog.htm" 1>Double Dragon Clone - 15 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
||||
|
||||
![]() CTar Member since: 3/20/2005 From: Farum, Denmark |
||||
|
|
||||
| Where and how is the MsgProc function defined? Edit: You also need to prefix your constructor and destructor with "cApplication::", like this: // ----------------------------------------------------- // Constructor Destructor // ----------------------------------------------------- cApplication::cApplication() { RegisterWnd(); CreateWnd(); } cApplication::~cApplication() { // Do Nothing (for now) } |
||||
|
||||
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
Quote: errr.. MsgProc is not defined yet , I just wanted to see if my code worked til now |
||||
|
||||
![]() KittyRa Member since: 1/9/2005 From: Ann Arbor, MI, United States |
||||
|
|
||||
| Wow! Only took a quick look but it seems that you don't have a MsgProcfunction. also winmain should return a value like:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int lpCmdShow)
{
.
.
.
return msg.wParam;
} |
||||
|
||||
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
| Thanks Ill work hard on this one Ill post up my progress |
||||
|
||||
![]() CTar Member since: 3/20/2005 From: Farum, Denmark |
||||
|
|
||||
Quote: Well it have to, look at this line: wcex.lpfnWndProc = MsgProc; How should it know what it should assign lpfnWndProc to? You'll have to create a MsgProc function, just a simple one to test if it works. |
||||
|
||||
![]() CTar Member since: 3/20/2005 From: Farum, Denmark |
||||
|
|
||||
| Ok, I have got your code to work. You'll have to: - Define MsgProc, maybe like this for a start:
LRESULT CALLBACK MsgProc(HWND pWindow,UINT pMsg,WPARAM pWParam ,LPARAM pLParam)
{
return DefWindowProc(pWindow,pMsg,pWParam,pLParam);
}
- Add a ; after your declaration so that it looks like this: class cApplication { public: // Constructor Destructor cApplication(); ~cApplication(); // WindowClassEx WNDCLASSEX wcex; // WindowHandle HWND hWnd; // Methods void CreateWnd(); void RegisterWnd(); private: //////////////////////////////// //////////////////////////////// //////////////////////////////// // Notice the added ; //////////////////////////////// //////////////////////////////// }; - Add "cApplication::" before your constructor and destructor, so it'll look like this:
cApplication::cApplication()
{
RegisterWnd();
CreateWnd();
}
cApplication::~cApplication()
{
// Do Nothing (for now)
}
[Edited by - CTar on September 11, 2005 12:01:23 PM] |
||||
|
||||
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
| Thanks a lot thanks thanks thanks now my program just got down to 4 errors wich I presume are generated because of my stinking compiler.. do u know how I fix this? >Compiling... 1>cApplication.cpp 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(43) : error C2440: '=' : cannot convert from 'const char [11]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(47) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(59) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>WinMain.cpp 1>Generating Code... 1>Build log was saved at "file://c:\Documents and Settings\Armando Alva\Mis documentos\Visual Studio 2005\Projects\Double Dragon Clone\Double Dragon Clone\Debug\BuildLog.htm" 1>Double Dragon Clone - 3 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== and thanks again |
||||
|
||||
![]() dyerseve Member since: 7/31/2005 From: Silver Spring, MD, United States |
||||
|
|
||||
| Apparently, it's expecting unicode. |
||||
|
||||
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
| What do I have to do then? |
||||
|
||||
![]() python_regious Member since: 2/28/2001 From: Bath, United Kingdom |
||||
|
|
||||
I believe something like this should work (It's been a long time since I've done anything like this however).wcex.lpszClassName = L"Game Class"; If at first you don't succeed, redefine success. |
||||
|
||||
![]() EvilNando Member since: 5/20/2002 From: Barcelona, Spain |
||||
|
|
||||
| Yes u were right the L fixed the problem but is there a way to omit the L after every string I have to use? |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|