Jump to content
  • Advertisement
Sign in to follow this  
Eralp

C++ thing ( I guess)

This topic is 3995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!