<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>CodeGuru Forums</title>
		<link>https://forums.codeguru.com/</link>
		<description>Hard hitting articles, dicussions, resources, and more all focusing for real developers in the real world.</description>
		<language>en</language>
		<lastBuildDate>Wed, 03 Jun 2026 23:00:10 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>https://forums.codeguru.com/images/misc/rss.png</url>
			<title>CodeGuru Forums</title>
			<link>https://forums.codeguru.com/</link>
		</image>
		<item>
			<title><![CDATA[[RESOLVED] OakTree - Window creation]]></title>
			<link>https://forums.codeguru.com/showthread.php?566561-RESOLVED-OakTree-Window-creation&amp;goto=newpost</link>
			<pubDate>Thu, 28 May 2026 17:44:37 GMT</pubDate>
			<description><![CDATA[I have created a basic class that creates a win32 application.  I only want windows to handle events I specify in WindowProc(). My goal is to place an openGL window/renderer inside that (win32) window, that also has it's own event system.  I have managed to get that running but it crashes, so I have removed the code for now.  *I only want a single instance* of the win32 window class, but I am allowed to create one as you can see.  Is there a way other than Singleton approach?

Can I please ask an experienced programmer if s/he would look over my code and see if I have made any mistakes.  I have placed comments OakMain.cpp and OakTree.cpp and hope you can advise.

OakMain.cpp

Code:
---------
#include "OakTree.hpp"


int main()
{
    oak::OakTree OakApp;
    oak::OakTree OakApp1;  // *** This works, see comment below... ***


    while (OakApp.IsRunning()) {
        OakApp.ProcessWinMessages();
        // OakApp1.ProcessWinMessages();  // *** How is this allowed? Don't see window tho? ***
    }


    return 0;
}
---------
OakTree.hpp

Code:
---------
#ifndef OAKTREE_OAKTREE_HPP
#define OAKTREE_OAKTREE_HPP


#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
constexpr int OAK_PLATFORM_WINDOWS = 1;
#else
#error "Windows OS only supported at this time."
#endif


#include <Windows.h>


namespace oak
{
    class OakTree
    {
    public:
        OakTree();
        ~OakTree();


        void ProcessWinMessages();
        bool IsRunning() const { return m_IsRunning; }
        HWND GetWindowHandle() const { return m_window; }


    private:
        WNDCLASSEX m_wc{ 0 };
        HWND m_window{ nullptr };
        bool m_IsRunning{ false };
    };


}  // namespace oak


#endif  // OAKTREE_OAKTREE_HPP
---------
OakTree.cpp

Code:
---------
#include "OakTree.hpp"
#include <iostream>


static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);


oak::OakTree::OakTree()
{
    std::cout << "In OakTree() C'tor.\n";


    m_wc.cbSize = sizeof(WNDCLASSEX);
    m_wc.style = CS_HREDRAW | CS_VREDRAW;
    m_wc.lpfnWndProc = WindowProc;
    m_wc.hInstance = GetModuleHandleW(nullptr);
    m_wc.lpszClassName = L"OakTree";
    m_wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    m_wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
    m_wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
    m_wc.hIconSm = LoadIconW(NULL, IDI_APPLICATION);


    if (!RegisterClassExW(&m_wc)) { return; }


    m_window = CreateWindowExW(
        0, m_wc.lpszClassName, L"OakTree",
        WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        nullptr, nullptr, GetModuleHandleW(nullptr), nullptr
    );


    if (m_window == nullptr) { return; }


    ShowWindow(m_window, SW_SHOWMAXIMIZED);
    //UpdateWindow(m_window);  // *** Do I need this? Works ok without? ***


    m_IsRunning = true;
}


oak::OakTree::~OakTree()
{
    std::cout << "In OakTree() D'tor.\n";
}


void oak::OakTree::ProcessWinMessages()
{
    MSG msg = { 0 };
    while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) {
        if (msg.message == WM_QUIT) {
            m_IsRunning = false;
            break;
        }
        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }
}


LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_DESTROY: {
        PostQuitMessage(0);
        return 0;
    }


    /*
    case WM_PAINT: {     // *** Not sure if this is needed? ***
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);


        // All painting occurs here, between BeginPaint and EndPaint.


        FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
        EndPaint(hwnd, &ps);
        return 0;
    }
    */
    }


    return DefWindowProcW(hwnd, msg, wParam, lParam);
}
---------
]]></description>
			<content:encoded><![CDATA[<div>I have created a basic class that creates a win32 application.  I only want windows to handle events I specify in WindowProc(). My goal is to place an openGL window/renderer inside that (win32) window, that also has it's own event system.  I have managed to get that running but it crashes, so I have removed the code for now.  <b>I only want a single instance</b> of the win32 window class, but I am allowed to create one as you can see.  Is there a way other than Singleton approach?<br />
<br />
Can I please ask an experienced programmer if s/he would look over my code and see if I have made any mistakes.  I have placed comments OakMain.cpp and OakTree.cpp and hope you can advise.<br />
<br />
OakMain.cpp<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &quot;OakTree.hpp&quot;<br />
<br />
<br />
int main()<br />
{<br />
&nbsp; &nbsp; oak::OakTree OakApp;<br />
&nbsp; &nbsp; oak::OakTree OakApp1;&nbsp; // *** This works, see comment below... ***<br />
<br />
<br />
&nbsp; &nbsp; while (OakApp.IsRunning()) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; OakApp.ProcessWinMessages();<br />
&nbsp; &nbsp; &nbsp; &nbsp; // OakApp1.ProcessWinMessages();&nbsp; // *** How is this allowed? Don't see window tho? ***<br />
&nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; return 0;<br />
}</code><hr />
</div>OakTree.hpp<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#ifndef OAKTREE_OAKTREE_HPP<br />
#define OAKTREE_OAKTREE_HPP<br />
<br />
<br />
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)<br />
constexpr int OAK_PLATFORM_WINDOWS = 1;<br />
#else<br />
#error &quot;Windows OS only supported at this time.&quot;<br />
#endif<br />
<br />
<br />
#include &lt;Windows.h&gt;<br />
<br />
<br />
namespace oak<br />
{<br />
&nbsp; &nbsp; class OakTree<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; public:<br />
&nbsp; &nbsp; &nbsp; &nbsp; OakTree();<br />
&nbsp; &nbsp; &nbsp; &nbsp; ~OakTree();<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; void ProcessWinMessages();<br />
&nbsp; &nbsp; &nbsp; &nbsp; bool IsRunning() const { return m_IsRunning; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; HWND GetWindowHandle() const { return m_window; }<br />
<br />
<br />
&nbsp; &nbsp; private:<br />
&nbsp; &nbsp; &nbsp; &nbsp; WNDCLASSEX m_wc{ 0 };<br />
&nbsp; &nbsp; &nbsp; &nbsp; HWND m_window{ nullptr };<br />
&nbsp; &nbsp; &nbsp; &nbsp; bool m_IsRunning{ false };<br />
&nbsp; &nbsp; };<br />
<br />
<br />
}&nbsp; // namespace oak<br />
<br />
<br />
#endif&nbsp; // OAKTREE_OAKTREE_HPP</code><hr />
</div>OakTree.cpp<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &quot;OakTree.hpp&quot;<br />
#include &lt;iostream&gt;<br />
<br />
<br />
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);<br />
<br />
<br />
oak::OakTree::OakTree()<br />
{<br />
&nbsp; &nbsp; std::cout &lt;&lt; &quot;In OakTree() C'tor.\n&quot;;<br />
<br />
<br />
&nbsp; &nbsp; m_wc.cbSize = sizeof(WNDCLASSEX);<br />
&nbsp; &nbsp; m_wc.style = CS_HREDRAW | CS_VREDRAW;<br />
&nbsp; &nbsp; m_wc.lpfnWndProc = WindowProc;<br />
&nbsp; &nbsp; m_wc.hInstance = GetModuleHandleW(nullptr);<br />
&nbsp; &nbsp; m_wc.lpszClassName = L&quot;OakTree&quot;;<br />
&nbsp; &nbsp; m_wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);<br />
&nbsp; &nbsp; m_wc.hCursor = LoadCursorW(NULL, IDC_ARROW);<br />
&nbsp; &nbsp; m_wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);<br />
&nbsp; &nbsp; m_wc.hIconSm = LoadIconW(NULL, IDI_APPLICATION);<br />
<br />
<br />
&nbsp; &nbsp; if (!RegisterClassExW(&amp;m_wc)) { return; }<br />
<br />
<br />
&nbsp; &nbsp; m_window = CreateWindowExW(<br />
&nbsp; &nbsp; &nbsp; &nbsp; 0, m_wc.lpszClassName, L&quot;OakTree&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE,<br />
&nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; nullptr, nullptr, GetModuleHandleW(nullptr), nullptr<br />
&nbsp; &nbsp; );<br />
<br />
<br />
&nbsp; &nbsp; if (m_window == nullptr) { return; }<br />
<br />
<br />
&nbsp; &nbsp; ShowWindow(m_window, SW_SHOWMAXIMIZED);<br />
&nbsp; &nbsp; //UpdateWindow(m_window);&nbsp; // *** Do I need this? Works ok without? ***<br />
<br />
<br />
&nbsp; &nbsp; m_IsRunning = true;<br />
}<br />
<br />
<br />
oak::OakTree::~OakTree()<br />
{<br />
&nbsp; &nbsp; std::cout &lt;&lt; &quot;In OakTree() D'tor.\n&quot;;<br />
}<br />
<br />
<br />
void oak::OakTree::ProcessWinMessages()<br />
{<br />
&nbsp; &nbsp; MSG msg = { 0 };<br />
&nbsp; &nbsp; while (PeekMessageW(&amp;msg, nullptr, 0, 0, PM_REMOVE)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (msg.message == WM_QUIT) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_IsRunning = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; TranslateMessage(&amp;msg);<br />
&nbsp; &nbsp; &nbsp; &nbsp; DispatchMessageW(&amp;msg);<br />
&nbsp; &nbsp; }<br />
}<br />
<br />
<br />
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
&nbsp; &nbsp; switch (msg) {<br />
&nbsp; &nbsp; case WM_DESTROY: {<br />
&nbsp; &nbsp; &nbsp; &nbsp; PostQuitMessage(0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
&nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; /*<br />
&nbsp; &nbsp; case WM_PAINT: {&nbsp; &nbsp;  // *** Not sure if this is needed? ***<br />
&nbsp; &nbsp; &nbsp; &nbsp; PAINTSTRUCT ps;<br />
&nbsp; &nbsp; &nbsp; &nbsp; HDC hdc = BeginPaint(hwnd, &amp;ps);<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // All painting occurs here, between BeginPaint and EndPaint.<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; FillRect(hdc, &amp;ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));<br />
&nbsp; &nbsp; &nbsp; &nbsp; EndPaint(hwnd, &amp;ps);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; */<br />
&nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; return DefWindowProcW(hwnd, msg, wParam, lParam);<br />
}</code><hr />
</div></div>

]]></content:encoded>
			<category domain="https://forums.codeguru.com/forumdisplay.php?9-C-(Non-Visual-C-Issues)">C++  (Non Visual C++ Issues)</category>
			<dc:creator>Gerald Bates</dc:creator>
			<guid isPermaLink="true">https://forums.codeguru.com/showthread.php?566561-RESOLVED-OakTree-Window-creation</guid>
		</item>
		<item>
			<title>A decent Microsoft forum anyone?</title>
			<link>https://forums.codeguru.com/showthread.php?566549-A-decent-Microsoft-forum-anyone&amp;goto=newpost</link>
			<pubDate>Sat, 09 May 2026 14:10:17 GMT</pubDate>
			<description><![CDATA[Can anyone here recommend a trustworthy forum for MS Windows issues? I'm suddenly having a problem with System Restore so I typed *Microsoft Windows forum *into Google but there are literally dozens of them (none of which are affiliated to Microsoft). so I'm guessing that at least some will likely be malevolent.]]></description>
			<content:encoded><![CDATA[<div>Can anyone here recommend a trustworthy forum for MS Windows issues? I'm suddenly having a problem with System Restore so I typed <b>Microsoft Windows forum </b>into Google but there are literally dozens of them (none of which are affiliated to Microsoft). so I'm guessing that at least some will likely be malevolent.</div>

]]></content:encoded>
			<category domain="https://forums.codeguru.com/forumdisplay.php?22-General-Discussion-Chit-Chat">General Discussion / Chit Chat</category>
			<dc:creator>John E</dc:creator>
			<guid isPermaLink="true">https://forums.codeguru.com/showthread.php?566549-A-decent-Microsoft-forum-anyone</guid>
		</item>
	</channel>
</rss>
