CreateWindowEx does not throw an exception on error so there is no point to the try/catch block. If the function fails then you have to call GetLastError() to find out the error number, and you can pass that to FormatMessage() to get a human-readable error message.
I don't think you want to use the console's window handle as the parent of a Windows GUI program. Instead, pass NULL as that parameter.
>>But I can't use WindowProc, because I use windows API here in my code
That's what the WindowProc function is for. Establish the WindowProc when you call RegisterClass before CreateWindowEx()
If you want to write win32 api programs then don't start out with a console program. Set this tutorial for the basics.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>Used the console window as the main window because my application also console based application.
CreateWindowsEx REQUIRES a win32 api program because it is a GUI. You can't create one with a console program. Period.
>>He use API i tought that is for windows application.And must have WinProc.
I agree. Which is why his program crashes. And he doesn't have a message pump so the window will never get any messages even if it were created.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I can send messages to the window. Send a message to close the window, (WM_CLOSE) and try to destroy the window. But not work. I can send messages to it.
You can send all the messages you want, but without a message pump to pass them along to the correct window they will just be tossed into the bit bucket by the Windows operating system. You need to read and code a tutorial about how to write a windows program.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>You says that, according to my code I can't send message to the window
Read Very Carefully and Very sloooooooooooowly. I did not say that. Shall I repeat -- I did not say that. What I said was that the window will never receive any of the messages your console program sends it. Calling PostMessage() does not guarentee the receipient will receive the message. When you mail a letter at the post office the person to whom you sent the letter may or may not receive it. If the person lives some place that has no post office then your letter will be sent to the Post Office's dead letter office. Same with Windows messages.
If you will just read this win32 api tutorial you will probably understand more.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343