-5

Why does this happen?

1>------ Build started: Project: Client, Configuration: Debug Win32 ------
1> WindowManager.cpp
1> Generating Code...
1> Compiling...
1> Main.cpp
1> Generating Code...
1>WindowManager.obj : error LNK2001: unresolved external symbol
"private: static int WindowManager::win_stat" (?win_stat@WindowManager@@0HA) 1>C:\Users\user\documents\visual studio 2012\Projects\TalkToMe\Debug\Client.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

WindowManager.cpp

#include "WindowManager.h"

void WindowManager::PekMessage()
{
    if(PeekMessage(&msg, window, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

bool WindowManager::isWindowOpen()
{
    return win_stat != -1;
}

HWND WindowManager::textbox(int width, int height, int xPos, int yPos, LPCSTR content, bool edit_able)
{
    int type = (edit_able) ? (WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL) : (WS_CHILD|WS_VISIBLE|WS_HSCROLL|ES_AUTOHSCROLL);
    return CreateWindowEx(
        WS_EX_CLIENTEDGE,
        "EDIT",
        content,
        type,
        xPos,
        yPos,
        width,
        height,
        window,
        (HMENU)50,
        GetModuleHandle(NULL),
        NULL
    );
}

HWND WindowManager::textbox(Vector size, Vector position, LPCSTR content, bool edit_able)
{
    return textbox(size.getX(), size.getY(), position.getX(), position.getY(), content, edit_able);
}

LRESULT CALLBACK WindowManager::WindowProcedure(HWND winhan,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
{
    switch(uint_Message)
    {
        case 16: // exit button
            win_stat = -1;
        break;
    }

    return DefWindowProc(winhan,uint_Message,parameter1,parameter2);
}

WindowManager::WindowManager(LPCTSTR title,int x, int y, int width, int height)
{
    WNDCLASSEX wnd;
    wnd.cbSize = sizeof(wnd);
    wnd.style  = CS_HREDRAW | CS_VREDRAW;
    wnd.lpfnWndProc = WindowProcedure;
    wnd.cbClsExtra  = 0;
    wnd.cbWndExtra  = 0;
    wnd.hInstance   = GetModuleHandle(NULL);
    wnd.hIcon       = NULL;
    wnd.hCursor     = LoadCursor(NULL,IDC_ARROW);
    wnd.hbrBackground = GetSysColorBrush(NULL);
    wnd.lpszClassName = "TalkToMe";
    wnd.lpszMenuName  = NULL;
    wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    RegisterClassEx(&wnd);

    window = CreateWindowEx(WS_EX_CONTROLPARENT, wnd.lpszClassName, title, 
        WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, x, y, width, height,NULL, NULL, 
        GetModuleHandle(NULL), NULL);
}

WindowManager::~WindowManager()
{
    DestroyWindow(window);
}

WindowManager.h

#pragma once
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

#include <Windows.h>
#include "Vector.h"

class WindowManager
{
private:
    MSG msg;
    HWND window;

    static int win_stat;
public:
    WindowManager(LPCTSTR title,int x, int y, int width, int height);
    ~WindowManager();
    static LRESULT CALLBACK WindowProcedure(HWND winhan,UINT uint_Message,WPARAM parameter1,LPARAM parameter2);

    HWND textbox(int width, int height, int xPos, int yPos, LPCSTR content, bool edit_able=true);
    HWND textbox(Vector size, Vector position, LPCSTR content, bool edit_able=true);

    bool isWindowOpen();
    void PekMessage();
};
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • Duplicate: http://stackoverflow.com/questions/195207/unresolved-external-symbol-on-static-class-members – tenfour Sep 08 '12 at 12:31

1 Answers1

3

The part in the header

static int win_stat;

is only a declaration. You also have to add

int WindowManager::win_stat;

to the .cpp file, just like you define the member functions there.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203