Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 865569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:39:33+00:00 2026-05-15T09:39:33+00:00

I am confused. Sometimes when I initiate my window, the Handle returned is good.

  • 0

I am confused. Sometimes when I initiate my window, the Handle returned is good. and sometimes its not. Here is my code

void GXRenderManager::InitWindows()
{
    WNDCLASSEX wndcex;

    wndcex.cbSize   = sizeof(WNDCLASSEX);
    wndcex.style    = CS_HREDRAW | CS_VREDRAW;
    wndcex.lpfnWndProc = GXRenderManager::WndProc;
    wndcex.cbClsExtra = 0;
    wndcex.cbWndExtra = 0;
    wndcex.hInstance = *GXRenderManager::hinstance;
    wndcex.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wndcex.hCursor  =   LoadCursor(NULL,IDC_ARROW);
    wndcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wndcex.lpszMenuName = NULL;
    wndcex.lpszClassName = L"GXRenderClass";
    wndcex.hIconSm  =   LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wndcex))
        throw GXWindowsException(L"Failed To Register Window");

    //EDIT AREA: This is a static size for window. Needs to be changed for dynamic size
    RECT rectangle = {0,0,GXRenderManager::width,GXRenderManager::height};
    AdjustWindowRect(&rectangle, WS_OVERLAPPEDWINDOW, FALSE);

    HWND tempWin;

    tempWin = CreateWindowEx(WS_EX_CLIENTEDGE,L"GXRenderClass",L"GXRender Engine",
        WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, 
        (rectangle.right - rectangle.left),
        (rectangle.bottom - rectangle.top), NULL, NULL,*GXRenderManager::hinstance, NULL);

    if(!tempWin)
        GXWindowsException(L"GX had an issue creating a window.");

    GXRenderManager::mainWindow = &tempWin;

    ShowWindow(*GXRenderManager::mainWindow, *GXRenderManager::nCmdShow);

}

Sometimes GXRenderManager::mainWindow returns a number, but most of the time it returns a “expression can not be evaluated. Any takers ??

[edit]

the header

#ifndef GXRM
#define GXRM
#include <windows.h>
#include "DeviceEnum.h"
#include "GXRenderDevice.h"
#include "GXExceptions.h"

class GXRenderManager {

public:
    static int Ignite(HINSTANCE*, int*, GXDEVICE , int w = 800, int h = 600);
    static GXRenderer* Device();
    static void InitWindows();
    static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

    static int Run();

private:
    bool running;
    static GXRenderer *renderDevice;

protected:
    static HINSTANCE * hinstance;
    static int *nCmdShow;
    static HWND mainWindow;
    static int width;
    static int height;

};

#endif

.cpp

GXRenderManager::mainWindow is a static member . Prior to the responses below. I updated the code to the following…

void GXRenderManager::InitWindows()
{
    WNDCLASSEX wndcex;

    wndcex.cbSize   = sizeof(WNDCLASSEX);
    wndcex.style    = CS_HREDRAW | CS_VREDRAW;
    wndcex.lpfnWndProc = GXRenderManager::WndProc;
    wndcex.cbClsExtra = 0;
    wndcex.cbWndExtra = 0;
    wndcex.hInstance = *GXRenderManager::hinstance;
    wndcex.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wndcex.hCursor  =   LoadCursor(NULL,IDC_ARROW);
    wndcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wndcex.lpszMenuName = NULL;
    wndcex.lpszClassName = L"GXRenderClass";
    wndcex.hIconSm  =   LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wndcex))
        throw GXWindowsException(L"Failed To Register Window");

    //EDIT AREA: This is a static size for window. Needs to be changed for dynamic size
    RECT rectangle = {0,0,GXRenderManager::width,GXRenderManager::height};
    AdjustWindowRect(&rectangle, WS_OVERLAPPEDWINDOW, FALSE);

    HWND tempWin;

    tempWin = CreateWindowEx(WS_EX_CLIENTEDGE,L"GXRenderClass",L"GXRender Engine",
        WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, 
        (rectangle.right - rectangle.left),
        (rectangle.bottom - rectangle.top), NULL, NULL,*GXRenderManager::hinstance, NULL);

    if(!tempWin)
        GXWindowsException(L"GX had an issue creating a window.");

    GXRenderManager::mainWindow = tempWin;

    ShowWindow(GXRenderManager::mainWindow, *GXRenderManager::nCmdShow);

}

Still I see the same issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:39:33+00:00Added an answer on May 15, 2026 at 9:39 am

    You are saving a pointer to a local variable (tempWin) and expecting that will be valid after you return from the InitWindows() function. Instead of making GXRenderManager::mainWindow a pointer, declare it as an actual data member. So:

    class GXRenderManager {
        ...
        HWND mainWindow; // not a pointer
        ...
    };
    
    GXRenderManager::mainWindow = tempWin;
    
    ShowWindow(GXRenderManager::mainWindow, *GXRenderManager::nCmdShow);
    

    I suspect you might have a similar problem with nCmdShow, but you haven’t shown enough of your code to tell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi: I am learning struts,however I was often confused by its configuration,sometimes I do
Sometimes I get confused about when not releasing an object. I have: NSTimer *timer2;
I am really confused as to why sometimes vars will not work when var
I'm sometimes confused to using which one of them, say I have a function
I am confused why Microsoft documentation sometimes refer to the List class as List<T>
Confused here... I have two dates which I NSLog to console and get: dates
Very confused here, trying out the yuicompressor on a simple javascript file. My js
I'm a little confused why I see some code in PHP with string placed
I'm confused sometimes with iOS development. Won't this always return true? if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
Sometimes after adding a library to an Eclipse Java project, Eclipse is still confused

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.