why do these two programs have different outputs when you run em...i've been tryin to figure it ...all morning

FIRST PRORAM
//----------------------------------------------------------------
#include <windows.h>
//#pragma hdrstop
//--------------------------------------------------------
//#pragma argsused
//--------------------------------------------------------
const char *ClsName="FundApp";
const char *WndName="Resouces Fundamental";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


//------------------------------------------------------------------------------------
INT WINAPI  WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG  Msg;
	HWND hWnd;
	WNDCLASSEX WndClsEx;

	//create application window

	WndClsEx.cbSize     =sizeof(WNDCLASSEX);
	WndClsEx.style       =CS_HREDRAW | CS_VREDRAW;
	WndClsEx.lpfnWndProc =WndProcedure;
	WndClsEx.cbWndExtra  =0;
	WndClsEx.cbClsExtra  =0;
	WndClsEx.hCursor     =LoadIcon(NULL, IDC_ARROW);
	WndClsEx.hIcon       =LoadIcon(NULL, IDI_APPLICATION);
	WndClsEx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	WndClsEx.lpszMenuName=NULL;
	WndClsEx.lpszClassName=ClsName;
	WndClsEx.hInstance    =hInstance;
	WndClsEx.hIconSm      =LoadIcon(NULL ,IDI_APPLICATION);

	// Register application
	RegisterClassEx(&WndClsEx);
	 
	// create the window object

	hWnd= CreateWindow(
		                  ClsName,
						  WndName,
						  WS_OVERLAPPEDWINDOW,
						  CW_USEDEFAULT,
						  CW_USEDEFAULT,
						  CW_USEDEFAULT,
						  CW_USEDEFAULT,
						  NULL,
						  NULL,
						  hInstance,
						  NULL);
	// foind out of the window was created

	if ( !hWnd)  // if the window wasn't created
		 return FALSE; // STOP APPLICATION

	// DISPLAY THE WINDOW TO THE USER

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

	// Decode and treat the messages as long as application is running

	while (GetMessage(&Msg, NULL, 0, 0))
    {
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}

//----------------------------------------------------------------------------

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
    default:
		//process leftover messages
		return DefWindowProc(hWnd, Msg, wParam, lParam);
	}
	// if something was not done, let it go
	return 0;
}
//--------------------------------------------------------------------------------

SECOND PROGRAM

#include <windows.h>
#pragma hdrstop

#pragma argused 

const char *ClsName="BasicApp";
const char *WndName="A Simple Window";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, 
                       WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                LPSTR lpCmdLine, int nCmdShow)
{
	MSG Msg;
	HWND hWnd;
	WNDCLASSEX WndClsEx;

	//create application window
	WndClsEx.cbSize      =sizeof(WNDCLASSEX);
	WndClsEx.style        =CS_HREDRAW | CS_VREDRAW;
	WndClsEx.lpfnWndProc  =WndProcedure;
	WndClsEx.cbClsExtra   =0;
	WndClsEx.cbWndExtra   =0;
	WndClsEx.hIcon        =LoadIcon(NULL, IDI_APPLICATION);
	WndClsEx.hCursor      =LoadCursor(NULL, IDC_ARROW);
	WndClsEx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	WndClsEx.lpszMenuName =NULL;
	WndClsEx.lpszClassName=ClsName;
	WndClsEx.hInstance    =hInstance;
	WndClsEx.hIconSm        =LoadIcon(NULL, IDI_APPLICATION); 
       // WHY DID YOU DO IT TWO TIMES

	 // Register the application
	 RegisterClassEx(&WndClsEx);

	//Create a window Object
	hWnd= CreateWindowEx(0,ClsName,
		               WndName,
					   WS_OVERLAPPEDWINDOW,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   NULL,
					   NULL,
					   hInstance,
					   NULL);
	
	
	// Find Out IF the  Window Was Created
	if (!hWnd) // if the window wasn't created
		return 0; //stop the application
	
	
	//Display the window to the user
     ShowWindow(hWnd, SW_SHOWNORMAL);
	 UpdateWindow(hWnd);

	 //Decode and treat the messages
	 //as long as the application is running

	while (GetMessage(&Msg, NULL, 0, 0))
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}


LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch (Msg)
	{
		//if the user wants to close the application
	case WM_DESTROY:
		//then close it
		PostQuitMessage(WM_QUIT);
		break;
	default:
		// Process the leftover messages
		return DefWindowProc(hWnd,Msg,wParam,lParam);
	}
	// if something was not done let it go
	return 0;
}

Recommended Answers

All 3 Replies

>>why do these two programs have different outputs
Don't know either. What are the two outputs?

one of em shows a cursor ...and the other doesn't.....d first one is supposed to be an example of windows resources

line 28 of the first program is wrong. compare it to line 26 of the second program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.