C++ thing ( I guess)

Started by
7 comments, last by MaulingMonkey 16 years, 3 months ago
Hi, I'm trying to write my game engine and I'm stucked up here; I basicly want to create a window, here is my ErEngine.h file,


class ErEngine{
Properties Er_Properties;
public:
LRESULT	Er_CreateWindow(HINSTANCE hInst, int nCmdShow);
LRESULT CALLBACK Er_WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
};


And here is my ErEngine.cpp file,

#include <windows.h>
#include <windowsx.h>
#include "ErEngine.h"

LRESULT CALLBACK ErEngine::Er_WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{

};

LRESULT ErEngine::Er_CreateWindow(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
//////////////////////////////////////////////////////////////////////////////////////

    wc.lpfnWndProc = ErEngine::Er_WindowProc;
//here is my problem :(
//////////////////////////////////////////////////////////////////////////////////////
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = "WindowClass1";
    RegisterClassEx(&wc);
    hWnd = CreateWindowEx(NULL,
                          "WindowClass1",   
                          "Our First Windowed Program",   
                          WS_OVERLAPPEDWINDOW,    
                          300,   
                          300,   
                          500,  
                          400,   
                          NULL,  
                          NULL,    
                          hInstance,    
                          NULL);    
    ShowWindow(hWnd, nCmdShow);
}; 

It doesnt accept a Class-function as windowproc.. no matter if I write it ErEngine::Er_WindowProc or just Er_WindowProc or (WNDPROC)Er_WindowProc.. What should I do? And Thank you for your helps :)
Advertisement
Link.
Quote:Original post by Gage64
Link.


oh THANKS :))
It accepts a class function, it does not however accept non-static functions.

You will have to make the wnd static.


Quote:Original post by marius1930
You will have to make the wnd static.


How could he handle multiple windows, if he makes the window static?
The basic problem here is: classes are not simply a place to store code. They define a data type.. So in order to call a (non-static) member function, you need to say which instance (also object) of the class you are going to call it on. An ordinary pointer to the member function doesn't know which instance to use, and it definitely doesn't provide its own. (Actually, a "pointer to member function" isn't really a pointer at all, in general.) You can "bind" it to an instance, but first there must be one.

It's very likely, though, that you don't really want to go this route: just use a normal function instead.. What do you think the class will gain you?

Oh, and by the way: don't just prefix everything with 'Er'. Use a namespace instead. You know that 'using namespace std;' thingy you had to deal with when you wrote "hello world"? It (the feature of namespaces, in general) is not there to make your life harder; it's there to make your life easier.
Quote:Original post by Eralp
Hi, I'm trying to write my game engine and I'm stucked up here;


This might be of interest to you.
Quote:Original post by Captain_Thunder
Quote:Original post by Eralp
Hi, I'm trying to write my game engine and I'm stucked up here;


This might be of interest to you.



Oh for god's sakes. I agree with the article, but are we going to brain-wash people with it? The guy wants to write an engine and asks a question. He doesn't want to be questioned about how he's going to manage his programming time. Answer the question(if you can) and that's it. I'm worried that I see a shift in the forums; instead of discussing about technical stuff, we're endessly having discussions about meta-problems that leak into every thread. If that article(or similar) is so loved, make it a sticky and be done.
Quote:Original post by mikeman
He doesn't want to be questioned about how he's going to manage his programming time.

Presumably this is why the article was simply linked, so that the OP might read/recognize/discard/acknowledge-and-move-on, rather than a reiteration of the points of that article made directly within the post.

Quote:If that article(or similar) is so loved, make it a sticky and be done.

Nobody reads stickies, sadly. I think dropping the link within relevant posts is an acceptable, sufficient, and probably best alternative to repeating ourselves or never having the OP aware of it in the first place?

This topic is closed to new replies.

Advertisement