Error in Building - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Error in Building

VinayKhareVinayKhare Posts: 69Member
Hello everybody, I have started learning windows programming few days before. I am referring "Let Us C" for making a plot in my mind, then I will switch to "Charles Petzold". I got some doubt in the following code:
[code]
#include

HINSTANCE hInst;

LRESULT CALLBACK WndProc ( HWND, UINT, WPARAM, LPARAM );

BOOL InitInstance ( HINSTANCE, int, char*);

void OnDestroy(HWND);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG m;
/* perform application initialization */
InitInstance(hInstance,nShowCmd,"Title");
/* Message Loop */
while ( GetMessage(&m,0,0,0) )
DispatchMessage(&m);
return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
OnDestroy(hWnd);
break;
default:
return ( DefWindowProc(hWnd,message,wParam,lParam) );
}
return 0;
}

BOOL InitInstance( HINSTANCE hInstance, int nCmdShow, char* pTitle)
{
char classname[ ] = "MyWindowClass" ;
HWND hWnd ;

WNDCLASSEX wcex ;
wcex.cbSize = sizeof ( WNDCLASSEX ) ;
wcex.style = CS_HREDRAW | CS_VREDRAW ;
wcex.lpfnWndProc = ( WNDPROC ) WndProc ;
wcex.cbClsExtra = 0 ;
wcex.cbWndExtra = 0 ;
wcex.hInstance = hInstance ;
wcex.hIcon = NULL ;
wcex.hCursor = LoadCursor ( NULL, IDC_ARROW ) ;
wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 ) ;
wcex.lpszMenuName = NULL ;
wcex.lpszClassName = classname ;
wcex.hIconSm = NULL ;

if ( !RegisterClassEx ( &wcex ) )
return FALSE ;

hInst = hInstance ; // Store instance handle in our global variable

hWnd = CreateWindow ( classname, pTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL,
NULL, hInstance, NULL ) ;
if ( !hWnd )
return FALSE ;

ShowWindow ( hWnd, nCmdShow ) ;
UpdateWindow ( hWnd ) ;

return TRUE ;
}

void OnDestroy(HWND hWnd)
{
PostQuitMessage(0);
}
[/code]

Q1:-When tracing the above code, I have not passed through the WndProc function. may be in InitInstance(), but after WndProc, "()" is not used(it may be variable).
So I remove def of WndProc from above code.
Code Compiles well but on building the above code two errors occur.
Why so?

Q2:What is that WNDCLASSEX class? where it is defined. and in the above code how it is being used?

Q3: I am bit confused with the Handles. HWND or HINSTANCE.
How many types of handles are there? what are their specific functions??

Thank You,

[b]Waiting for Reply...[/b]

Comments

  • LundinLundin Posts: 3,711Member
    : Q1:-When tracing the above code, I have not passed through the
    : WndProc function. may be in InitInstance(), but after WndProc, "()"
    : is not used(it may be variable).

    You only enter WndProc when your window is receiving a message, such as a mouse click. So if you sit in your debugger and stare at the code, the window is likely not receiving any messages, as it will be in the background.


    : So I remove def of WndProc from above code.
    : Code Compiles well but on building the above code two errors occur.
    : Why so?

    You must have a WndProc for each window or the code won't work.


    : Q2:What is that WNDCLASSEX class? where it is defined. and in the
    : above code how it is being used?

    That one contains a lot, namely most info about your main window. See the Win API documentation for details.

    : Q3: I am bit confused with the Handles. HWND or HINSTANCE.
    : How many types of handles are there? what are their specific
    : functions??

    There are plenty of handles in the Win API. In reality, handle is just a fancy word for pointer. Think of HWND as a pointer to a window and HINSTANCE as a pointer to an application.
Sign In or Register to comment.