#open a blank window in C

1 messages · Page 1 of 1 (latest)

silent nacelle
#

hi all,

i am trying to open up a window

i have coded out word for word from this youtube video
https://www.youtube.com/watch?v=8GCvZs55mEM&list=PLWzp0Bbyy_3i750dsUj7yq4JrPOIUR_NK&index=1

but i am getting errors, can anyone help

#include <windows.h>



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

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

    //MessageBox(NULL, "HELLO","My first GUI",MB_OK);

    WNDCLASSEXW wc = {0};

    wc.hbrBackground = (HBRUSH) COLOR_WINDOW ;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hInstance = hInst;
    wc.lpszClassName = L"myWindowClass";
    wc.lpfnWndProc = WindowProcedure;



    if(!RegisterClassW(&wc));
        return -1;

        CreateWindowW(L"myWindowClass",L"My Window",WS_EX_OVERLAPPEDWINDOW | WS_VISIBLE,100,100,500,500,
                      NULL,NULL,NULL,NULL);


    MSG msg = {0};

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

    return 0;

}

LRESULT CALLBACK WindowProcedure(HWND HWND,UINT msg,WPARAM wp,LPARAM lp)
{
    switch ( msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProcW(HWND,msg,wp,lp);

    }
}

Win32 API ( Windows GUI ) Programming with C++/C.

--Part 1--
Creating a basic empty windows from a windows class.

Part 2 : https://youtu.be/7K6HCeog09c

Facebook page :
https://www.facebook.com/pentamollis

▶ Play video
keen furnaceBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

silent nacelle
#

open a blank window in C

mortal dove
#

What errors?

silent nacelle
#

error: 'hInst' undeclared (first use in this function)|

patent ginkgo
#

Probably you followed the video incorrectly.

#

Helps to learn C properly first as this is a very trivial error.

silent nacelle
#

ye some codes were wrong, looked into it

mortal dove
#

That would be this line: wc.hInstance = hInst;. likely because you named the argument hinstance instead of hInst

silent nacelle
#

i have corrected it

#

its running but nothing happens

#

new code

#include <windows.h>



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

int WINAPI WinMain(HINSTANCE hInst , HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{

    //MessageBox(NULL, "HELLO","My first GUI",MB_OK);

    WNDCLASSEXW wc = {0};

    wc.hbrBackground = (HBRUSH) COLOR_WINDOW ;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hInstance = hInst;
    wc.lpszClassName = L"myWindowClass";
    wc.lpfnWndProc = WindowProcedure;



    if(!RegisterClassW(&wc));
        return -1;

        CreateWindowW(L"myWindowClass",L"My Window",WS_EX_OVERLAPPEDWINDOW | WS_VISIBLE,100,100,500,500,
                      NULL,NULL,NULL,NULL);


    MSG msg = {0};

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

    return 0;

}

LRESULT CALLBACK WindowProcedure(HWND HWND,UINT msg,WPARAM wp,LPARAM lp)
{
    switch ( msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProcW(HWND,msg,wp,lp);

    }
}

mortal dove
#

Are you compiling your code with warnings enabled? You may have other issues