C++ - Win32 API - A Window Does Not Appear

Hi, programmers!

I was experimenting with Win32 API & eventually ran into a problem - window I want to create does not appear at all. Command line appears as except, but that's about it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// -----------
/// @author God
/// -----------
#ifndef __TENGINE_GUI_WINDOW_HPP__
#define __TENGINE_GUI_WINDOW_HPP__
#ifdef _WIN32
    #include <windows.h>
    #include <windowsx.h>
#endif // _WIN32
namespace TEngine{
	/// ------------------------------
	/// @class	GUIWindow
	/// @brief	Represents GUI window.
	/// ------------------------------
	class GUIWindow{
	public:
		/// Constructors & destructors:
		#ifndef _WIN32
			explicit GUIWindow(char const* name, unsigned width, unsigned height);
		#endif // !_WIN32
		~GUIWindow(void);
		/// Constructors & destructors (Windows only):
		#ifdef _WIN32
			explicit GUIWindow(char const* name, unsigned width, unsigned height, ::HINSTANCE h, int const& cmd_show);
		#endif // _WIN32
		/// Member functions:
		void close(void);
		void create(void);
		void display(void) const;
	private:
		/// Member variables:
        bool _m_bOpen;
		char const* _m_cpName;
		unsigned _m_uiSizeHeight, _m_uiSizeWidth;
		/// Member variables (Windows only):
		#ifdef _WIN32
			::HWND _m_opWindow;
			::HINSTANCE _m_opHandleInstance;
			::MSG mutable* _m_opMessage;
			int const& _m_iCmdShow;
		#endif // _WIN32
	};
}
#endif // __TENGINE_GUI_WINDOW_HPP__ 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <tengine/guiwindow.hpp>
using namespace TEngine;

/// ------------------------------
/// @class	GUIWindow
/// @brief	Represents GUI window.
/// ------------------------------
/// Anonymous namespace:
namespace{
	#ifdef _WIN32
		::LRESULT CALLBACK __TEngine_GUIWindow_WndProc(::HWND h, ::UINT message, ::WPARAM w, ::LPARAM l){
			switch(message){
				case WM_CLOSE:
					::DestroyWindow(h);
					return 0;
				case WM_DESTROY:
					::PostQuitMessage(0);
					return 0;
				default:
					return ::DefWindowProc(h, message, w, l);
			}
		}
	#endif // _WIN32
}
/// Constructors & destructors:
#ifndef _WIN32
GUIWindow::GUIWindow(char const* name, unsigned width, unsigned height) : _m_bOpen(true), _m_cpName(name), _m_uiSizeHeight(height), _m_uiSizeWidth(width){

}
#endif // !_WIN32
GUIWindow::~GUIWindow(void){
    if(_m_bOpen)
        this->close();
}
/// Constructors & destructors (Windows only):
#ifdef _WIN32
GUIWindow::GUIWindow(char const* name, unsigned width, unsigned height, ::HINSTANCE h, int const& cmd_show) : _m_bOpen(true), _m_cpName(name), _m_uiSizeHeight(height), _m_uiSizeWidth(width), _m_opHandleInstance(h), _m_iCmdShow(cmd_show){

}
#endif // _WIN32
/// Member functions:
void GUIWindow::close(void){
    _m_bOpen = false;
    ::exit(0);
}
void GUIWindow::create(void){
    #ifdef _WIN32
    {
        // Create the window class:
        ::WNDCLASSEX __wcx;{
            __wcx.cbClsExtra = 0;
            __wcx.cbWndExtra = 0;
            __wcx.hbrBackground = (::HBRUSH)::GetStockObject(BLACK_BRUSH);
            __wcx.hCursor = ::LoadCursor (NULL, IDC_ARROW);
            __wcx.hIcon = ::LoadIcon(_m_opHandleInstance, IDI_APPLICATION);
            __wcx.hInstance = _m_opHandleInstance;
            __wcx.lpfnWndProc = __TEngine_GUIWindow_WndProc;
            __wcx.lpszClassName = _m_cpName;
            __wcx.lpszMenuName = NULL;
            __wcx.style = (CS_HREDRAW | CS_VREDRAW);
        }
        ::RegisterClassEx(&__wcx);

        // Create the window:
        _m_opWindow = ::CreateWindowEx(
            WS_EX_APPWINDOW,
            _m_cpName, _m_cpName,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            NULL, NULL, _m_opHandleInstance, NULL
        );

        // Set the window visible:
        ::ShowWindow(_m_opWindow, _m_iCmdShow);
		::UpdateWindow(_m_opWindow);
    }
    #endif // _WIN32
}
void GUIWindow::display(void) const{
    while(::GetMessage(_m_opMessage, NULL, 0, 0)){
        ::TranslateMessage(_m_opMessage);
        ::DispatchMessage(_m_opMessage);
    }
}


1
2
3
4
5
6
7
/// -----------
/// @author God
/// -----------
#ifndef __TENGINE_HPP__
#define __TENGINE_HPP__
#include <tengine/guiwindow.hpp>
#endif // __TENGINE_HPP__ 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <tengine/tengine.hpp>

#ifdef _WIN32
int WINAPI WinMain(::HINSTANCE h, ::HINSTANCE, ::LPSTR, int nCmdShow){
	TEngine::GUIWindow window("Tapz!", 800, 600, h, nCmdShow);
#else
int main(int argc, char* argv[]){
	TEngine::GUIWindow window("Tapz!", 800, 600);
#endif // _WIN32, #else
	window.create();
	while(true){
		window.display();
	}
	return 0;
}


Suggestions, please.
Topic archived. No new replies allowed.