如何在没有控制台的情况下运行可执行文件?

时间:2015-04-26 19:10:02

标签: windows-7 windows command-line

是的,所以我在这里有点腌菜。我已经编写了多年(非专业,只有比赛的算法,我还在高中),我试图创建我的第一个实际的程序/应用程序,运行一个窗口。

根据MSDN的信息和我在谷歌上发现的几个主题,我设法输入一些基本的东西,只需打开一个500x100的空白窗口。问题是,当我运行编译后得到的可执行文件时,一个空白的控制台窗口与我的窗口一起打开。我想要一些如何禁用它的帮助。这是我的代码:

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

static TCHAR szWindowClass[] = _T("Snake Class");
static TCHAR szTitle[] = _T("Snake");

HINSTANCE hInst;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow){

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = NULL;//LoadIcon(hInstance,     MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = NULL;//LoadIcon(wcex.hInstance,     MAKEINTRESOURCE(IDI_APPLICATION));

    if(!RegisterClassEx(&wcex)){
        MessageBox(NULL,_T("Call to RegisterClassEx     failed!"),_T("Snake"),NULL);

        return 1;
    }

    HWND hWnd =     CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAU    LT,500,100,NULL,NULL,hInstance,NULL);

    if(!hWnd){
        MessageBox(NULL,_T("Call to CreateWindow     failed!"),_T("Snake"),NULL);

        return 1;
    }

    hInst = hInstance;

    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);

    MSG msg;
    while(GetMessage(&msg,NULL,0,0)){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)    {
    PAINTSTRUCT ps;
    HDC hdc;

    TCHAR greeting[] = _T("Hello World!");

    switch(message){
    case WM_PAINT:
        hdc = BeginPaint(hWnd,&ps);

        //Paint

        EndPaint(hWnd,&ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd,message,wParam,lParam);
        break;
    }

    return 0;
}

0 个答案:

没有答案