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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:10:45+00:00 2026-05-28T03:10:45+00:00

I am using Netbeans 7.1 to toy around with the AI tutorial I found

  • 0

I am using Netbeans 7.1 to toy around with the AI tutorial I found here.

edit: I am using the GCC compiler.

I’ve gotten everything working, but I can’t seem to get the application to compile and run with the Windows Subsystem… The application appears to be written properly for Windows API, and the executable that came with the source files from that website launches without producing the black console window that my own executable creates.

I’ve tried adding -mwindows as an option to the linker, and I’ve tried -Wl,-subsystem,windows. Neither of these have worked for me. I’ve provided the main.cpp below.

#define WIN32_LEAN_AND_MEAN

#include <windows.h> 

#include <stdlib.h>
#include <time.h>


#include "utils.h"
#include "CController.h"
#include "CTimer.h"
#include "resource.h"
#include "CParams.h"


// edited this out, still not working

// #pragma comment(linker, “/SUBSYSTEM:windows /ENTRY:mainCRTStartup”)

///////////////////////GLOBALS ////////////////////////////////////

char*           szApplicationName = "Smart Sweepers v1.0";
char*           szWindowClassName = "sweeper";


//The controller class for this simulation
CController*    g_pController    = NULL; 

//create an instance of the parameter class.
CParams   g_Params;

//---------------------------- Cleanup ----------------------------------
//
//  simply cleans up any memory issues when the application exits
//-----------------------------------------------------------------------
void Cleanup()
{
    if (g_pController) 

        delete g_pController;
}
//-----------------------------------WinProc-----------------------------
//
//-----------------------------------------------------------------------
LRESULT CALLBACK WindowProc(HWND hwnd, 
                                        UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{
    //these hold the dimensions of the client window area
    static int cxClient, cyClient;

    //used to create the back buffer
    static HDC        hdcBackBuffer;
    static HBITMAP  hBitmap;
    static HBITMAP  hOldBitmap; 


    switch(msg)
    {   
        case WM_CREATE: 
        {
            //seed the random number generator
            srand((unsigned) time(NULL));

            //get the size of the client window
            RECT rect;
            GetClientRect(hwnd, &rect);

            cxClient = rect.right;
            cyClient = rect.bottom;

            //setup the controller
            g_pController = new CController(hwnd);

                //create a surface for us to render to(backbuffer)
            hdcBackBuffer = CreateCompatibleDC(NULL);

            HDC hdc = GetDC(hwnd);

            hBitmap = CreateCompatibleBitmap(hdc,
                                                            cxClient,
                                                            cyClient);
            ReleaseDC(hwnd, hdc);

            hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap); 
        } 

        break;

        //check key press messages
        case WM_KEYUP:
        {
            switch(wparam)
            {

                case VK_ESCAPE:
                {
                    PostQuitMessage(0);
                }

                break;

                case 'F':
                    {
                        g_pController->FastRenderToggle();
                    }

                    break;

        //reset the demo
        case 'R':
          {
             if (g_pController)
             {
               delete g_pController;
             }

             //setup the new controller
                   g_pController = new CController(hwnd);
          }

          break;

            }//end WM_KEYUP switch
        }

        break;

        //has the user resized the client area?
        case WM_SIZE:
        {
            cxClient = LOWORD(lparam);
            cyClient = HIWORD(lparam);

            //resize the backbuffer accordingly
            SelectObject(hdcBackBuffer, hOldBitmap);

            HDC hdc = GetDC(hwnd);

            hBitmap = CreateCompatibleBitmap(hdc,
                                                             cxClient,
                                                             cyClient);
            ReleaseDC(hwnd, hdc);

            hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap); 
        } 

        break;

        case WM_PAINT: 
        {
      PAINTSTRUCT ps;

          BeginPaint(hwnd, &ps);

            //fill our backbuffer with white
            BitBlt(hdcBackBuffer,
             0,
             0,
             cxClient,
             cyClient,
             NULL,
             NULL,
             NULL,
             WHITENESS);

            //render the mines and sweepers
            g_pController->Render(hdcBackBuffer);

            //now blit backbuffer to front
            BitBlt(ps.hdc, 0, 0, cxClient, cyClient, hdcBackBuffer, 0, 0, SRCCOPY); 

            EndPaint(hwnd, &ps);
        } 

        break;

        case WM_DESTROY: 
        {
            SelectObject(hdcBackBuffer, hOldBitmap);

            //clean up our backbuffer objects
            DeleteDC(hdcBackBuffer);
            DeleteObject(hBitmap); 

      // kill the application, this sends a WM_QUIT message 
            PostQuitMessage(0);
        } 

        break;

        default:break;

    }//end switch

    // default msg handler 
    return (DefWindowProc(hwnd, msg, wparam, lparam));

}//end WinProc


//-----------------------------------WinMain-----------------------------------------
//  Entry point for our windows application
//-----------------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hinstance,
                              HINSTANCE hprevinstance,
                              LPSTR lpcmdline,
                              int ncmdshow)
{

    WNDCLASSEX winclass; 
    HWND       hwnd;     
    MSG        msg;      

    // first fill in the window class stucture
    winclass.cbSize       = sizeof(WNDCLASSEX);
    winclass.style            = CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc    = WindowProc;
    winclass.cbClsExtra     = 0;
    winclass.cbWndExtra     = 0;
    winclass.hInstance      = hinstance;
    winclass.hIcon            = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));
    winclass.hCursor          = LoadCursor(NULL, IDC_ARROW); 
    winclass.hbrBackground= NULL; 
    winclass.lpszMenuName   = NULL;
    winclass.lpszClassName= szWindowClassName;
    winclass.hIconSm      = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));


    // register the window class
    if (!RegisterClassEx(&winclass))
    {
        MessageBox(NULL, "Error Registering Class!", "Error", 0);
    return 0;
    }

    // create the window (one that cannot be resized)
    if (!(hwnd = CreateWindowEx(NULL,                                   
                                              szWindowClassName,                        
                                              szApplicationName,                        
                                              WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
                              GetSystemMetrics(SM_CXSCREEN)/2 - CParams::WindowWidth/2,
                              GetSystemMetrics(SM_CYSCREEN)/2 - CParams::WindowHeight/2,                                    
                                              CParams::WindowWidth,
                              CParams::WindowHeight,                
                                              NULL,                                 
                                              NULL,                             
                                              hinstance,                                
                                              NULL)))   
    {
    MessageBox(NULL, "Error Creating Window!", "Error", 0);
        return 0;
    }

    //Show the window
    ShowWindow(hwnd, SW_SHOWDEFAULT );
    UpdateWindow(hwnd);

    //create a timer
    CTimer timer(CParams::iFramesPerSecond);

    //start the timer
    timer.Start();

    // Enter the message loop
    bool bDone = FALSE;

    while(!bDone)
    {

        while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
        {
            if( msg.message == WM_QUIT ) 
            {
                //Stop loop if it's a quit message
                bDone = TRUE;
            } 

            else 
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        }

        if (timer.ReadyForNextFrame() || g_pController->FastRender())
        {   
          if(!g_pController->Update())
            {
                //we have a problem, end app
                bDone = TRUE;
            }

            //this will call WM_PAINT which will render our scene
            InvalidateRect(hwnd, NULL, TRUE);
            UpdateWindow(hwnd);
    }                   

    }//end while


    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( szWindowClassName, winclass.hInstance );

    return 0;

} // end WinMain
  • 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-28T03:10:45+00:00Added an answer on May 28, 2026 at 3:10 am

    This seems a bit strange, but windows subsystem application uses WinMainCRTStartup as entry point. So the following line looks inconsistent:

    #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
    

    It probably should be "/SUBSYSTEM:windows /ENTRY:WinMainCRTStartup" or "/SUBSYSTEM:console /ENTRY:mainCRTStartup"

    On the other hand, I never trried to make a windows app with gcc. It may completely ignore this #pragma… Anyway, try to comment it out and see what happens. Generally compiler should be able to select the proper entry point without the compile time parameter anyway.

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

Sidebar

Related Questions

I'm using netbeans to develop some BPEL but can't figure out how to add
im using Netbeans 7 for make a desktop application. But i can't find how
Iam using netbeans 6.9 for PHP , the file i was working on corrupted
I'm using netbeans and want to edit the text in a label. I want
I enjoy using NetBeans, especially for development with Maven, however, I've found recently that
I was using NetBeans but it seems that support for Ruby is officially dead
I'm using NetBeans 6.1 as my primary IDE, in there I can't run this
Using NetBeans IDE and Glassfish Server. For some reason I can't get a DataSource
im using netbeans with svn. i've checked out a project and then i used
im using netbeans for svn. i open a project in netbeans and then i

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.