Question

I'm learning C++. I wonder is any C++ application have HWND. Example bellow app, with no window created. If it have, how I can get its HWND? Thank you very much!

#include <windows.h>

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow )
{
    MSG msg;
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
}
Was it helpful?

Solution 2

You need to create one.

check out CreateWindowEx and ShowWindow

OTHER TIPS

"I'm learning C++. I wonder is any C++ application have HWND." The shortest answer is no. HWND is a defined type in a library used to write Windows applications. C++ is a language that can be used to do that as long as you have library that gives you functions (including HWND type.)

You can write programs for CMD prompt or for Unix which have nothing to do with Windows. Try this C style program. Copy text below to a.cpp file, and compile it to generate a.exe:

#include <stdio.h>
int main()
{
    printf( "Hello world\n" ) ;
    return 0 ;
}

When you run cmd, change directory to where a.exe is, and run a.exe then you will see:

Hello world

If you plan on learning C++ you don't need to write Windows applications. You can write CMD or Linux programs. Find a good book on the C++ subject. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top