Sorry in advance! I did solved thread before I checked if the code somebody said worked. It turned out they didn't help much. The problem is MattyRobot gave me code to open a new window. Now it opens with CMD to; I only wanted the window. I will give you the code, and would appreciate if you edited so the cmd window does not open with the window. So basicly I want a code where just the window opens. If you could sort out the one i was given, would be appreciated. Just sort it out and post it back on this forum.
Thanks!

#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG msg;


    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = "classname";
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "FAILED!!!!", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    }

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "classname", "Hello World", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "FAILED!!!", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    }

    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);


    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

Sorry, forgot to add; please dont comment if you dont understand. Nevertheless if you can help, feel free to :)

I'm afraid the code is correct :)
The problem is a compiler setting, make sure the project is a "Windows Application".

And if you seriously can't figure out the compiler option (and you're using VC++), add this line of code to the very start of your program.

#pragma comment(linker, "/SUBSYSTEM:WINDOWS")

Sorry that dont seem to work. CMD still opens

Ok thankyou. It turned out i was using the wrong application,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.