Problem beim ändern der Farbe des Fenster



  • Hallo

    Ich bin daran, eine DLL zu schreiben. Nun bin ich auf ein Problem gestossen. Ich will die Farbe des Fensters durch eine Funktion ändern.

    Hier ist der Code meiner DLL:

    // Dark3DCubeEnginedll.h
    //
    // Definitions of the functions
    //
    #ifndef DARK_HPP
    #define DARK_HPP
    
    #include <windows.h>
    #include "Structures.h"
    #include "Enumerations.h"
    #include "Definitions.h"
    
    // create a namespace, called DCE
    //
    namespace DCE
    {
    	// Create a class, called Dark3DCubeEngine
    	//
    	class Dark3DCubeEngine
    	{
    	public:
    
    		static __declspec(dllexport) void Initialize (DCE::Dark3DCubeEngineProperties & props);
    		static __declspec(dllexport) void SetWindowProperties (const int WindowWidth, const int WindowHeight,
    															   const int WindowDepth);
    		static __declspec(dllexport) void SetWindowColor (int R, int G, int B);
    		static __declspec(dllexport) HWND OpenWindow (HINSTANCE hInstance);
    		static __declspec(dllexport) LRESULT WINAPI MsgProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    
    	private:
    
    		static int m_WindowWidth;
    		static int m_WindowHeight;
    		static int m_WindowDepth;
    		static int m_R;
    		static int m_G;
    		static int m_B;
    
    	}; // End of the class
    
    } // End of the namespace
    
    #endif
    
    // Dark3DCubeEnginedll.cpp
    //
    // Definitions of the functions
    //
    #include "Dark3DCubeEnginedll.h"
    
    // Create a namespace, called DCE
    //
    namespace DCE
    {
    	Dark3DCubeEngineProperties * props = new Dark3DCubeEngineProperties();
    	int Dark3DCubeEngine::m_WindowDepth;  // = 0
    	int Dark3DCubeEngine::m_WindowHeight; // = 0
    	int Dark3DCubeEngine::m_WindowWidth;  // = 0
    	int Dark3DCubeEngine::m_R;			  // = 0
    	int Dark3DCubeEngine::m_G;			  // = 0
    	int Dark3DCubeEngine::m_B;			  // = 0
    
    	void Dark3DCubeEngine::Initialize(DCE::Dark3DCubeEngineProperties & props)
    	{
    		props.WindowWidth = m_WindowWidth;
    		props.WindowHeight = m_WindowHeight;
    		props.WindowDepth = m_WindowDepth;
    	}
    
    	void Dark3DCubeEngine::SetWindowProperties(const int WindowWidth, const int WindowHeight,
    											   const int WindowDepth)
    	{
    		m_WindowWidth = WindowWidth;
    		m_WindowHeight = WindowHeight;
    		m_WindowDepth = WindowDepth;
    	}
    
    	void Dark3DCubeEngine::SetWindowColor(int R, int G, int B)
    	{
    		m_R = R;
    		m_G = G;
    		m_B = B;
    	}
    
    	HWND Dark3DCubeEngine::OpenWindow(HINSTANCE hInstance)
    	{
    		WNDCLASSEX wc;
    
    		wc.style			= CS_HREDRAW | CS_VREDRAW;
    		wc.cbSize			= sizeof (wc);
    		wc.lpfnWndProc		= MsgProc;
    		wc.cbClsExtra		= 0;
    		wc.cbWndExtra		= 0;
    		wc.hInstance		= hInstance;
    		wc.hIcon			= LoadIcon (NULL, IDI_APPLICATION);
    		wc.hCursor			= LoadCursor (NULL, IDC_ARROW);
    		wc.hbrBackground	= (HBRUSH)CreateSolidBrush(RGB(m_R, m_G, m_B));
    		wc.lpszMenuName		= NULL;
    		wc.lpszClassName	= TEXT ("Dark3DCubeEngine");
    		wc.hIconSm			= LoadIcon (NULL, IDI_APPLICATION);
    
    		if (RegisterClassEx (&wc) == 0) return 0;
    
    		return CreateWindowEx (NULL, TEXT("Dark3DCubeEngine"), "Dark3DCubeEngine",
    							   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    							   GetSystemMetrics(SM_CXSCREEN)/2 - 250,
    							   GetSystemMetrics(SM_CYSCREEN)/2 - 187,
    							   m_WindowWidth, m_WindowHeight, NULL,
    							   NULL, hInstance, NULL);
    	}
    
    	LRESULT WINAPI Dark3DCubeEngine::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    	{
    		switch (msg)
    		{
    			// key was pressed
    			//
    		case WM_KEYDOWN:
    			{
    				switch (wParam)
    				{
    				case VK_ESCAPE:
    					{
    						PostMessage (hwnd, WM_CLOSE, 0, 0);
    						return 0;
    					} break;
    				default: break;
    				}
    			} break;
    
    		case WM_DESTROY:
    			{
    				PostQuitMessage (0);
    				return 0;
    			}
    		default: break;
    		}
    
    		return DefWindowProc(hwnd, msg, wParam, lParam);
    	}
    } // End of the namespace
    

    Doch wenn ich nun eine Farbe bei der .exe mit der Funktion SetWindowColor angebe, kommt immer nur ein schwarzes Fenster heraus.

    Hier der Code der .exe:

    // main.h
    //
    #include <windows.h>
    #include <Dark3DCubeEnginedll.h>
    #pragma comment(lib, "Dark3DCubeEngine.lib")
    
    // Create a class, called MyApplication
    //
    class MyApplication : public DCE::Dark3DCubeEngine
    {
    public:
    
    	MyApplication () {}
    	virtual ~MyApplication () {}
    
    };
    
    // main.cpp
    //
    #include "main.h"
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
    					LPSTR lpCmdLine, int nShowCmd)
    {
    	MSG msg;
    	HWND hwnd;
    	bool bDone = false;
    	MyApplication * pApp = new MyApplication ();
    	DCE::Dark3DCubeEngineProperties props;
    
    	pApp->Initialize(props);
    	pApp->SetWindowProperties(1200, 1000, 32);
    	pApp->SetWindowColor(100, 250, 100);
    	hwnd = pApp->OpenWindow(hInstance);
    
    	if (hwnd)
    	{
    		MessageBox(NULL, "Fehler beim Initialisieren!", "Fehler aufgetreten",
    				   MB_OK | MB_ICONEXCLAMATION);
    	}
    
    	while (!bDone)
    	{
    		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    
    	delete pApp;
    
    	return 0;
    }
    

    Kann mir hier jemand helfen?

    Gruss Patrick


Anmelden zum Antworten