|
-
July 27th, 1999, 12:25 PM
#1
Hello World program in Windows with source
I posted about the error of Hello world program yesterday. It said that "Can't convert void* to HBRUSH_
Here is the code
/*
program 1
Hello world in Windows
*/
#include <windows.h>
// prototype declarations
int WINAPI WinMain(
HINSTANCE hInstance, //handle of current instance
HINSTANCE hPrevInstance, //handle of the prev instance
LPSTR pszCmdLine, // command line
int nCmdShow // show state of the window
);
LRESULT CALLBACK WindowProc(
HWND hWnd, // handle of window
UINT uMsgId, // message identifier
WPARAM wParam, //first message parameter
LPARAM lParam // second message parameter
);
// WinMain- where it begins
int WINAPI WinMain(
HINSTANCE hInstance, //handle of current instance
HINSTANCE hPrevInstance, // handle of prev instance
LPSTR pszCmdLine, // command line
int nCmdShow // show state of window
)
{
static char szAppName[]="Prog1";
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
// first register to Window class
wndClass.style=0;
wndClass.lpfnWndProc=WindowProc; // call back fn
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hInstance=hInstance;
wndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName=NULL;
wndClass.lpszClassName=szAppName;
if (RegisterClass(&wndClass)== 0) // register class
{
return 0; // quit if it doesn't work
}
// now create the app's one window
hWnd=CreateWindow(
szAppName, //the window class name
szAppName, //the window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, //initial x and...
CW_USEDEFAULT, //...y position
CW_USEDEFAULT, // window size in x
CW_USEDEFAULT, //window size in y
NULL, //parent window handle
NULL, // menu handle
hInstance, //program instance handle
NULL);
if (hWnd==0)
{
return 0;
}
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
// Window Proc- this function gets called to process Window message
LRESULT CALLBACK WindowProc(
HWND hWnd, //handle of window
UINT uMsgId, //message identifier
WPARAM wParam, //first message parameter
LPARAM lParam //second message parameter
)
{
static char *pszHello="Hello, world";
//decide what to do with each different message type
switch (uMsgId)
{
// handle the window paint message by dispalying the string
// "Hello,world" in the upper left corner of the window
case WM_PAINT:
HDC hDC;
PAINTSTRUCT paintStruct;
hDC=BeginPaint(hWnd,&paintStruct);
TextOut(hDC,
0,0,
pszHello,
lstrlen(pszHello));
EndPaint(hWnd,&paintStruct);
return 0;
//handle the window destroy message by quiting the application
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
// let Windows handle all other message types
return DefWindowProc(hWnd,uMsgId,wParam,lParam);
}
}
-
July 27th, 1999, 12:37 PM
#2
Re: Hello World program in Windows with source
Try changing
wndClass.hbrBackground=GetStockObject(WHITE_BRUSH);
To
wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
HTH,
Chris
-
July 27th, 1999, 08:05 PM
#3
Re: Hello World program in Windows with source
I tried but the compiler informed 2 errors: external and can't execute even there was nothing wrong with the code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|