Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

LNK2001

Ostatnio zmodyfikowano 2015-03-20 16:37
Autor Wiadomość
michal11
» 2015-03-16 22:42:38
Najlepiej wstaw cały aktualny kod.
P-128598
maly
» 2015-03-17 07:16:17
Ze statycznej metody nie dostaniesz się do nie statycznego pola klasy.

Miej pole statyczne jak wcześniej i tak jak napisał pekfos zdefiniuj HInput, lub zainteresuj się SetWindowLong, GetWindowLong + GWL_USERDATA albo SetWindowLongPtr, GetWindowLongPtr + GWLP_USERDATA.
P-128618
TheReclif
Temat założony przez niniejszego użytkownika
» 2015-03-18 22:45:11
To co zrobić? Tak jak pisałem w ostatnim poście definicja klasy inputClass jest przed definicją klasy handlingClass, przez co uważam, że redefinicja jest lekko bez sensu. A SetWindowLong, GetWindowLong + GWL_USERDATA i SetWindowLongPtr, GetWindowLongPtr + GWLP_USERDATA nic mi nie mówią(tzn. Google nie jest idealne i czasem nie umie wytłumaczyć. Ci z Microsoftu też). Na wszelki wypadek wstawiam cały kod:
C/C++
class inputClass
{
public:
    inputClass() { };
    ~inputClass() { };
   
    void init();
   
    void keyUp( unsigned int key );
    void keyDown( unsigned int key );
    bool isKeyDown( unsigned int key ) { return keyStat[ key ]; };
   
private:
    bool keyStat[ 256 ];
};

void inputClass::init()
{
    for( int i = 0; i < 256; i++ )
    {
        keyStat[ i ] = false;
    }
    return;
}

void inputClass::keyUp( unsigned int key )
{
    keyStat[ key ] = false;
}

void inputClass::keyDown( unsigned int key )
{
    keyStat[ key ] = true;
}

class handlingClass
{
private:
    static inputClass * HInput;
    hwnd win = NULL;
    int width;
    int height;
    int showWnd;
    lpctstr winName;
    lpctstr winClassName;
    hinstance appInst = NULL;
    RECT rect;
   
public:
    handlingClass();
    handlingClass( lpctstr name, int w, int h );
    virtual ~handlingClass() { delete HInput; HInput = NULL; };
    hwnd * getWin() { return & win; };
    void showWindow( int wndShow );
    void mainInit( UINT style, hinstance instance, LPCSTR curFile = NULL, LPCSTR icoFile = NULL, LPCSTR menuName = NULL );
    void createWindow( lpctstr winName, int w, int h, DWORD style = WS_VISIBLE, DWORD exStyle = NULL );
    static LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam );
    void wndEnd();
};

handlingClass::handlingClass()
{
    win = NULL;
    width = 0;
    height = 0;
    winName = "NULL";
    HInput = new inputClass;
    HInput->init();
}

handlingClass::handlingClass( lpctstr name, int w, int h )
{
    this->width = w;
    this->height = h;
    this->winName = name;
    HInput = new inputClass;
    HInput->init();
}

void handlingClass::mainInit( UINT style, hinstance instance, LPCSTR curFile, LPCSTR icoFile, LPCSTR menuName )
{
    wndclass winClass;
    winClass.cbSize = sizeof( wndclass );
    winClass.style = CS_HREDRAW | CS_VREDRAW;
    winClass.lpfnWndProc = WndProc;
    winClass.cbClsExtra = NULL;
    winClass.cbWndExtra = NULL;
    winClass.hInstance = instance;
    appInst = instance;
    if( curFile != NULL )
    {
        winClass.hCursor = LoadCursorFromFile( curFile );
    }
    else
    {
        winClass.hCursor = LoadCursor( NULL, IDC_ARROW );
    }
   
    if( icoFile != NULL )
    {
        winClass.hIcon = LoadIcon( instance, icoFile );
        winClass.hIconSm = LoadIcon( instance, icoFile );
    }
    else
    {
        winClass.hIcon = LoadIcon( NULL, IDICO_APP );
        winClass.hIconSm = LoadIcon( NULL, IDICO_APP );
    }
   
    winClass.hbrBackground =( HBRUSH ) COLOR_WINDOW;
    winClass.lpszClassName = winClassName;
    winClass.lpszMenuName = menuName;
    if( !RegisterClassEx( & winClass ) )
    {
        throw WNDCLASS_RECORDER_ERROR;
    }
}

void handlingClass::createWindow( lpctstr winName, int w, int h, DWORD style, DWORD exStyle )
{
    this->width = w;
    this->height = h;
   
    rect = { 0, 0, this->width, this->height };
    AdjustWindowRect( & rect, WS_OVERLAPPEDWINDOW, FALSE );
   
    this->winName = winName;
    this->win = CreateWindowEx( exStyle, winClassName, winName, style, CW_USEDEFAULT, CW_USEDEFAULT,( rect.right - rect.left ),( rect.bottom - rect.top ), NULL, NULL, appInst, NULL );
}

LRESULT CALLBACK handlingClass::WndProc( HWND hwin, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
    case WM_KEYUP:
        HInput->keyUp(( unsigned int ) wParam );
        return 0;
    case WM_KEYDOWN:
        HInput->keyDown(( unsigned int ) wParam );
        return 0;
    case WM_DESTROY:
        //komunikat włącza się gdy naciśniemy na [x] w lewym górnym narożniku okna
        return 0;
    }
    return DefWindowProc( hwin, msg, wParam, lParam );
}
P-128758
maly
» 2015-03-20 07:17:04
Deklarację
static inputClass * HInput;
 widzę ale definicji nie.
http://en.cppreference.com/w​/cpp/language/static
P-128793
TheReclif
Temat założony przez niniejszego użytkownika
» 2015-03-20 16:37:51
Działa! Wielkie dzięki i zamykam temat.
P-128814
1 « 2 »
Poprzednia strona Strona 2 z 2