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 7676251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:09:27+00:00 2026-05-31T17:09:27+00:00

I am a newbie when it comes to using WinAPI. I am following a

  • 0

I am a newbie when it comes to using WinAPI. I am following a tutorial where I found a code snippet. The snippet demonstrates a basic program. I am posting my full code below:

#include "a.h"
#include "windows.h"

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
               LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX WndClsEx;
    WndClsEx.cbSize      = sizeof(WNDCLASSEX);
    WndClsEx.style       = CS_HREDRAW | CS_VREDRAW;
    WndClsEx.lpfnWndProc = WndProcedure;
    WndClsEx.cbClsExtra  = 0;
    WndClsEx.cbWndExtra  = 0;
    WndClsEx.hInstance   = hInstance;

    return 0;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
    case WM_DESTROY:
        PostQuitMessage(WM_QUIT);
        break;
    default:
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    return 0;
}

I don’t get any error while running the code from Qt Creator. However, when running it no windows appear but the output console shows:

“MyProgram.exe exited with code 0”

What might cause this?

  • 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-31T17:09:28+00:00Added an answer on May 31, 2026 at 5:09 pm

    I am posting my full code below:

    Your code looks a lot like standard Win32 but it is missing a lot of code.

    For example this very simple test.cpp file contains a full working Win32 application:

    #define STRICT
    #include <windows.h>
    
    long PASCAL WndProc (HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                         LPSTR lpszCmdParam, int nCmdShow)
    {
       static char szClassName[] = "Hello World";
       MSG         msg;
       WNDCLASS    wndclass;
    
       memset(&wndclass, '\0', sizeof(wndclass));
    
       wndclass.style          = CS_HREDRAW|CS_VREDRAW;
       wndclass.lpfnWndProc    = WndProc;
       wndclass.cbClsExtra     = 0;
       wndclass.cbWndExtra     = 0;
       wndclass.hInstance      = hInstance;
       wndclass.hIcon          = LoadIcon (NULL, IDI_APPLICATION);
       wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
       wndclass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
       wndclass.lpszMenuName   = 0;
       wndclass.lpszClassName  = szClassName;
       RegisterClass (&wndclass);
    
       // create a new window 
       HWND hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
                                  szClassName,
                                  "My Hello World Window",
                                  WS_OVERLAPPEDWINDOW,
                                  CW_USEDEFAULT,
                                  CW_USEDEFAULT,
                                  CW_USEDEFAULT,
                                  CW_USEDEFAULT,
                                  NULL,
                                  NULL,
                                  hInstance,
                                  NULL);
    
       ShowWindow (hwnd, nCmdShow);
    
       while (GetMessage (&msg, NULL, 0, 0)) {
          TranslateMessage (&msg);
          DispatchMessage (&msg);
       }
    
       return msg.wParam;
    }
    
    long APIENTRY WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message) {
           case WM_DESTROY:
              PostQuitMessage (0);
              return 0;
        }
    
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    

    It can be compiled and linked from the command line:

    C:\TEMP>cl test.cpp user32.lib gdi32.lib
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    test.cpp
    Microsoft (R) Incremental Linker Version 9.00.30729.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:test.exe
    test.obj
    user32.lib
    gdi32.lib
    

    The resulting test.exe can be run and it will display a window:

    C:\TEMP>test.exe
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a complete newbie when it comes to OCaml. I've only recently started using
I am writing a website using C# razor code. I'm a total newbie when
I'm a newbie when it comes to SQL. When creating a stored procedure with
I'm a newbie when it comes to LINQ... I have an IEnumerable generic list
I'm a total newbie when it comes to CSS so I've pretty much given
I'm a newbie when it comes to properties, and I read that XML is
I am a relative newbie when it comes to SQL Azure!! I was wondering
Hiya, I'm sort a newbie when it comes to hibernate so I'm going to
I am a newbie to Python and have come across the following example in
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,

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.