Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;使用附加窗口打开窗口应用程序。我如何摆脱第二个窗口? 我最近开始C++编程,当我完成第一个程序时,我编译并运行了程序,但是运行时它总是打开第二个窗口,标题是bin \调试\ C++ 2D游戏教程。下面是正在发生的事情的图像_C++_Windows_Winapi_Compiler Construction - Fatal编程技术网

C++;使用附加窗口打开窗口应用程序。我如何摆脱第二个窗口? 我最近开始C++编程,当我完成第一个程序时,我编译并运行了程序,但是运行时它总是打开第二个窗口,标题是bin \调试\ C++ 2D游戏教程。下面是正在发生的事情的图像

C++;使用附加窗口打开窗口应用程序。我如何摆脱第二个窗口? 我最近开始C++编程,当我完成第一个程序时,我编译并运行了程序,但是运行时它总是打开第二个窗口,标题是bin \调试\ C++ 2D游戏教程。下面是正在发生的事情的图像,c++,windows,winapi,compiler-construction,C++,Windows,Winapi,Compiler Construction,发生这种事我做错了什么?我只想让我的应用程序窗口在后台不运行另一个窗口。这里还提供了我编写的代码 // winmain.cpp #define DEFINE_LEAN_AND_MEAN #include <iostream> #include <windows.h> #include "StdAfx.h // Function prototypes int WINAPI WinMain (HINSTANCE, HIN

发生这种事我做错了什么?我只想让我的应用程序窗口在后台不运行另一个窗口。这里还提供了我编写的代码

    // winmain.cpp
    #define DEFINE_LEAN_AND_MEAN
    #include <iostream>
    #include <windows.h>
    #include "StdAfx.h
    // Function prototypes
    int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
    bool CreateMainWindow(HINSTANCE, int);
    LRESULT WINAPI WinProc(HWND, UINT, WPARAM, LPARAM);
    // Global variable
    HINSTANCE hinst;
    // Constants
    const char CLASS_NAME[] = "WinMain";
    const char APP_TITLE[] = "Hello World";  // title bar text
    const int WINDOW_WIDTH = 400;
    const int WINDOW_HEIGHT = 400;
    //=================
    // Starting point for a windows application
    // parameters are
    //       hInstance. Handle to the current instance of the application
    // hPrevInstance. Always NULL, obsolete parameter
    // lpCmdLine. Pointer to null-terminated string of command line arguements
    // nCmdShow. Specifies how the window is to be shown
    //=======================
    int WINAPI WinMain(HINSTANCE hInstance,
                                            HINSTANCE hPrevInstance,
                                            LPSTR        lpCmdLine,
                                            int                   nCmdShow)
    {
        MSG msg;
        // Create the window
        if(!CreateMainWindow(hInstance, nCmdShow) )
                    return false;
             // Main message loop
             int done = 0;
             while (!done)
                        {
                                 //PeekMessage is non blocking test for Windows messages
                         if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE) )
                            {

                                    // Look for quit message
                                    if (msg.message == WM_QUIT)
                                               done = 1;
                                    // Decode and pass messages on to WinProc
                                    TranslateMessage(&msg);
                                    DispatchMessage(&msg);

                                                            }

        }
        return msg.wParam;
    }
    //==================
    // Window event callback function
    //===================
    LRESULT WINAPI WinProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
          switch( msg )
          {
                  case WM_DESTROY:
                  // Tell windows to kill the program
                  PostQuitMessage(0);
                  return 0;

           }
           return DefWindowProc (hWnd, msg, wParam, lParam );

    }
    //==========
    // Create the window
    // returns: false on error
    //=============
    bool CreateMainWindow(HINSTANCE hInstance, int nCmdShow)
    {
             WNDCLASSEX wcx;
             HWND hwnd;

           // Fill in the window clasa structure with parameters
           // that describes the main window
   wcx.cbSize = sizeof(wcx);          // size of structure
   wcx.style = CS_HREDRAW | CS_VREDRAW;  // Redraw if size changes
   wcx.lpfnWndProc =WinProc;                // Points to the window Procedure
   wcx.cbClsExtra = 0;                               // No extra class memory
   wcx.cbWndExtra = 0;      // No extra window memory
   wcx.hInstance = hInstance;   // Handle to instance
   wcx.hIcon = NULL;
   wcx.hCursor =LoadCursor(NULL, IDC_ARROW);    // Predefined arrow
   // Background brush
   wcx.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
   wcx.lpszMenuName =NULL; // Name of the menu resource
   wcx.lpszClassName = CLASS_NAME;   // Name of the window class
   wcx.hIconSm = NULL;                         // Small class icon


    // Register the window class
    // RegisterClassEx return 0 on error
    if (RegisterClassEx(&wcx) == 0)                // If error
           return false;
    // Create Window
    hwnd = CreateWindow(
       CLASS_NAME,             // Name of the window class
       APP_TITLE,                   // Title bar text
       WS_OVERLAPPEDWINDOW,          // Window style
       CW_USEDEFAULT,            // Default horizontal position of the window
       CW_USEDEFAULT,         //  Default horizontal positin of the window
       WINDOW_WIDTH,     // Width of window
       WINDOW_HEIGHT,      // Height of the window
       (HWND) NULL,          // No parent menu
       (HMENU) NULL,     // No menu
       hInstance,      // Handle to application instance
       (LPVOID) NULL);      // No window parameters
       // If there was an error creating the window
       if (!hwnd)
                    return false;
        // Show the window
        ShowWindow(hwnd, nCmdShow);
        // Send a WM_PAINT message to the window procedure
        UpdateWindow(hwnd);
        return true;
        }
//winmain.cpp
#定义精益和平均
#包括
#包括
#包括“StdAfx.h
//功能原型
int-WINAPI-WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
bool createmain窗口(HINSTANCE,int);
LRESULT WINAPI WinProc(HWND、UINT、WPARAM、LPARAM);
//全局变量
HINSTANCE hinst;
//常数
const char CLASS_NAME[]=“WinMain”;
const char APP_TITLE[]=“Hello World”//标题栏文本
const int WINDOW_WIDTH=400;
窗内常数=400;
//=================
//windows应用程序的起点
//参数为
//应用程序当前实例的句柄
//HPPreInstance.始终为空,过时参数
//指向以null结尾的命令行参数字符串的指针
//指定窗口的显示方式
//=======================
int WINAPI WinMain(HINSTANCE HINSTANCE,
HINSTANCE HPPrevenstance,
LPSTR lpCmdLine,
国际展览(nCmdShow)
{
味精;
//创建窗口
如果(!CreateMainWindow(hInstance,nCmdShow))
返回false;
//主消息循环
int done=0;
而(!完成)
{
//PeekMessage是针对Windows消息的非阻塞测试
if(peek消息(&msg,NULL,0,0,PM_-REMOVE))
{
//查找退出消息
如果(msg.message==WM\u退出)
完成=1;
//解码消息并将其传递给WinProc
翻译信息(&msg);
发送消息(&msg);
}
}
返回msg.wParam;
}
//==================
//窗口事件回调函数
//===================
LRESULT WINAPI WinProc(HWND HWND、UINT msg、WPARAM WPARAM、LPARAM LPARAM)
{
开关(msg)
{
案例WM_销毁:
//告诉windows终止该程序
PostQuitMessage(0);
返回0;
}
返回DefWindowProc(hWnd、msg、wParam、lParam);
}
//==========
//创建窗口
//返回:错误时为false
//=============
bool createmain窗口(HINSTANCE HINSTANCE,int nCmdShow)
{
WNDCLASSEX wcx;
HWND-HWND;
//用参数填充窗口类别结构
//这描述了主窗口
wcx.cbSize=sizeof(wcx);//结构的大小
wcx.style=CS|HREDRAW | CS_VREDRAW;//如果大小更改,请重新绘制
wcx.lpfnWndProc=WinProc;//指向窗口过程
wcx.cbClsExtra=0;//没有额外的类内存
wcx.cbWndExtra=0;//没有额外的窗口内存
wcx.hInstance=hInstance;//实例句柄
wcx.hIcon=NULL;
wcx.hCursor=LoadCursor(NULL,IDC_箭头);//预定义箭头
//背景画笔
wcx.hbrBackground=(HBRUSH)GetStockObject(黑色画笔);
wcx.lpszMenuName=NULL;//菜单资源的名称
wcx.lpszClassName=CLASS_NAME;//窗口类的名称
wcx.hIconSm=NULL;//小类图标
//注册窗口类
//RegisterClassEx在出现错误时返回0
if(RegisterClassEx(&wcx)==0)//if错误
返回false;
//创建窗口
hwnd=CreateWindow(
CLASS\u NAME,//窗口类的名称
APP_TITLE,//标题栏文本
WS\u重叠窗口,//窗口样式
CW_USEDEFAULT,//窗口的默认水平位置
CW_USEDEFAULT,//窗口的默认水平位置
窗宽,//窗宽
窗高度,//窗的高度
(HWND)NULL,//无父菜单
(humenu)NULL,//无菜单
hInstance,//应用程序实例的句柄
(LPVOID)NULL);//没有窗口参数
//如果创建窗口时出错
如果(!hwnd)
返回false;
//显示窗口
显示窗口(hwnd、nCmdShow);
//向窗口程序发送WM_PAINT消息
更新窗口(hwnd);
返回true;
}
如果有人能帮我解决这个问题,我将不胜感激。正如我之前所说的,我是新手,我不知道我做错了什么。如果有帮助的话,这是在代码块中编译的


另一个窗口是控制台窗口,您正在将其编译为控制台应用程序。因此,您需要将您的应用程序编译为GUI应用程序。

尝试将您的应用程序更改为
项目属性/build targets
中的
GUI应用程序
。它可能设置为
console
o调试属性中的控制台,现在它可以正常工作。另外,我现在知道为什么会发生这种情况。非常感谢您的帮助!:)它在deb中设置为控制台