I'm at the "hello world" stage, and I've typed in the code at the bottom of
this post. The call to RegisterClass fails with a return code of 87 ( "The
parameter is incorrect" ).
What am i doing wrong?
Here's my code:
===================================================
#include <windows.h>
#ifdef __BORLANDC__
#pragma argsused
#endif
LRESULT CALLBACK WindowFunc( HWND, UINT, WPARAM, LPARAM );
char szWinName[] = "MyWin";
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow )
{
HWND hwnd;
MSG msg;
WNDCLASS wcl;
wcl.style = 0;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.lpfnWndProc = WindowFunc;
wcl.hInstance = hInstance;
wcl.hbrBackground - (HBRUSH) GetStockObject( COLOR_WINDOW+1 );
wcl.hCursor = 0;
wcl.hIcon = 0;
wcl.lpszMenuName = 0;
wcl.lpszClassName = szWinName;
if (!RegisterClass(&wcl)) return GetLastError();
hwnd = CreateWindow( szWinName,
"My First C++ Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
ShowWindow( hwnd, nCmdShow ) ;
UpdateWindow( hwnd );
while( GetMessage( &msg, NULL, 0, 0 ))
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc( HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam )
{
switch( message ) {
case WM_DESTROY :
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
There is a typo in what you show. The equal sign is missing and a minus
sign is in its place.
Change
wcl.hbrBackground - (HBRUSH) GetStockObject( COLOR_WINDOW+1 );
To
wcl.hbrBackground = (HBRUSH) (COLOR_WINDOW+1 );
This change seems to have come about after the source you are using was
written (after Windows went to 32 bit). GetMessage now may also return a
negative value on error.
Change
while( GetMessage( &msg, NULL, 0, 0 ))
To
while( GetMessage( &msg, NULL, 0, 0 ) > 0)
While not originally built for CBuilderX you may find the examples in this
file informative. Unzip it into its own directory and be sure to allow the
unzipper to create the subdirectories stored in the zip file.
http://www.mulroy.org/hello.zip
. Ed
> Kirk Evans wrote in message
> news:441afa1a$1...@newsgroups.borland.com...