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:
#include <windows.h>
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);
}
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,
Waiting for Reply...