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

  • SEARCH
  • Home
  • 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 8677981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:35:59+00:00 2026-06-12T20:35:59+00:00

I am trying to create window already for several days, but always it tells

  • 0

I am trying to create window already for several days, but always it tells me “Cannot create window”
When it randomly creates window, CPU goes 50%. Can you help me and tell what causes that error?
Here is source code:

#include<Windows.h> 
int AppRunning=1;
void TellError(LPCWSTR error,HWND hWnd=NULL);
LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
    switch(msg){
        case WM_KEYDOWN:
            AppRunning=0;
            break;
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    }
    return DefWindowProc(hWnd,msg,wparam,lparam);
}

HWND NewWindow(LPCTSTR title,int xpos, int ypos, int width, int height)
{
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WindowProcedure;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = GetModuleHandle(NULL);
    wcex.hIcon = NULL;
    wcex.hCursor = NULL;
    wcex.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = L"Svet-ver1.0";
    wcex.hIconSm = LoadIcon(NULL,IDI_APPLICATION); 
    if(!RegisterClassEx(&wcex)){
        TellError(L"Cannot register window!");
        return NULL;
    }
    return CreateWindowEx(WS_EX_CONTROLPARENT, L"Svet3D-ver1.0", title, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, xpos, ypos, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
 }

 int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nCmdShow)
 {
    MSG msg;
    HWND hWnd = NewWindow(L"Svet",100,100,500,500); 
    if(!hWnd){
        TellError(L"Cannot create window!");
        return 0;
    }
    while(AppRunning){
        if(PeekMessage(&msg,hWnd,0,0,PM_REMOVE)){
            if(!IsDialogMessage(hWnd,&msg)){
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }
    DestroyWindow(hWnd);
    return 0;
 }
 void TellError(LPCWSTR error,HWND hWnd){
     MessageBox(hWnd,error,NULL,MB_OK);
 }
  • 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-06-12T20:35:59+00:00Added an answer on June 12, 2026 at 8:35 pm

    The class name passed to RegisterClassEx is "Svet-ver1.0", but when creating the window you are using a different class name "Svet3D-ver1.0".

    Also you are using PeekMessage in the main loop and this will just loop quickly when there are no messages in the queue. This empty loop is what is burning all your CPU (50% is probably because you’ve a dual core system).

    You should use GetMessage instead, that will wait for next message without wasting CPU time.

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

Sidebar

Related Questions

I'm trying to create a facebook/gtalk custom chat window. Already created a Facebook application
I'm trying to programmatically create a window with my own custom OpenGL NSView as
I am trying to create a status window which content(textbox) should change in a
I'm trying to create a preferences window. In it I have some checkbox style
I am trying to create a child window in WPF.this child window should open
I am trying to create a sort of a window, formed by multiple divs.
I am trying to create a very simple chat window that simply has the
I am trying to create an application that makes a window (external to the
I am trying to create a series of dynamic, calculated fields on my window.
Well... I am trying to create an application using the TTS Engine. I can

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.