Skip to main content
GameDev.net gamedev.net
🔒 Locked

Win32 API is Haaard help

Started by EvilNando Sep 11, 2005 at 11:24 AM 14 replies 4k views
Original Post
EvilNando
EvilNando
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
KittyRa
Can you post the errors please
so we can help more
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
Spoonbender
Spoonbender
Not unless you tell us what the problem is [wink]
dave
dave
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
EvilNando
Ok only beacuse uve asked it

1>Compiling...1>cApplication.cpp1>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 found1>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 found1>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 destructor1>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-int1>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 types1>        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 identifier1>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 cast1>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 cast1>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 cast1>WinMain.cpp1>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 symbol1>        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-int1>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 overloaded1>        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 assumed1>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
CTar
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
EvilNando
Quote:
Original post by CTar
Where and how is the MsgProc function defined?

Edit: You also need to prefix your constructor and destructor with "cApplication::", like this:
*** Source Snippet Removed ***



errr.. MsgProc is not defined yet , I just wanted to see if my code worked til now
KittyRa
KittyRa
Wow!
Only took a quick look but it seems that you don't have a
MsgProc
function. also winmain should return a value like:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                     LPSTR lpCmdLine, int lpCmdShow){...    return msg.wParam;}
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
EvilNando
EvilNando
Thanks Ill work hard on this one
Ill post up my progress
CTar
CTar
Quote:
Original post by EvilNando
errr.. MsgProc is not defined yet , I just wanted to see if my code worked til now


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
CTar
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
EvilNando
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.cpp1>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 cast1>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 cast1>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 cast1>WinMain.cpp1>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
dyerseve
Apparently, it's expecting unicode.
EvilNando
EvilNando
What do I have to do then?
python_regious
python_regious
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
EvilNando
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.