I'm a pretty competent C++ programmer, but all my experience is with non-gui
type programs of the type most often found running on unix systems.
That being said I'm currently trying to learn the Win32 API and I have
researched a lot of online tutorials, but when trying to compile an example
program (which I've included below) with mingw in Bloodshed Dev-C++ I keep
getting these errors:
main.cpp: In function `int WinMain(void *, void *, CHAR *, int)':
main.cpp:53: ANSI C++ forbids implicit conversion from `void *' in
assignment
main.cpp:69: ANSI C++ forbids implicit conversion from `void *' in argument
passing
However after a bit of research I found that I could compile with no errors
if I use the preprocessor definition
#define NO_STRICT
Which basically insures that STRICT is not defined. So anyway, here's the
code that's giving me problems.
main.cpp
==========================================================
//===================================//
// Hello.C //
// HELLO WORLD //
//===================================//
#include <windows.h>
long APIENTRY WndProc( HWND hwnd, UINT msg,
UINT wParam, LONG lParam )
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch( msg )
{
case WM_PAINT:
hdc = BeginPaint( hwnd, &ps );
GetClientRect( hwnd, &rect );
DrawText( hdc, "Hello, World! (Windows Style)", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER );
EndPaint( hwnd, &ps );
return( 0 );
case WM_DESTROY: // message: window being destroyed
PostQuitMessage(0);
break;
default: // if msg unproccessed,
// return to Windows
return( DefWindowProc( hwnd, msg, wParam, lParam ) );
}
return TRUE;
}
int APIENTRY WinMain( HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow )
{
static char szAppName[] = "WinHello";
HWND hwnd;
MSG msg;
WNDCLASS wc;
if( ! hPrevInstance )
{
wc.style = CS_HREDRAW | CS_VREDRAW;
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 = GetStockObject( WHITE_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
RegisterClass( &wc );
}
hwnd = ::CreateWindow(
szAppName, // window class name
"My First Program: Hello World", // window caption
WS_OVERLAPPEDWINDOW, // window style
100, // initial X position
100, // initial Y position
400, // initial X size
200, // initial Y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance
handle
NULL ); // creation parameters
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
==========================================================
Thanks in advance for any help,
Chad Simmons
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
|