//---------------------------------------------------------------------//
//                                                                     //
//  code2.cpp                                                          //
//  bkenwright@xbdev.net                                               //
//  www.xbdev.net                                                      //
//                                                                     //
//---------------------------------------------------------------------//


#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "Advapi32.lib")
#pragma comment(lib, "Winmm.lib")


#include <windows.h>
#include <stdio.h>                                // used for sprintf(..)

// Give our window a name, and of course name its class.
const char *CLASSNAME = "Tut Win32 - xbdev.net", *WINNAME = "Fonts are easy";

LRESULT CALLBACK WndProc(HWND hWnd, unsigned int iMessage, WPARAM wParam, LPARAM lParam);


// This function is our program entry point, but this time its got a lot
// of Windows initilisation code :-/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
	HWND hWnd;
	MSG Message;
    WNDCLASS WndClass;
    ZeroMemory(&WndClass, sizeof(WndClass));
    
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    // Casting, e.g. (HBRUSH), is for the compilers benefit, so that
	// it doesn't get unhappy, and to tell it that where passing a paramter
	// but we want it passes as a HBRUSH or what ever we've cast it to.
	WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon(hInstance, NULL);
	WndClass.hInstance = hInstance;
	WndClass.lpfnWndProc = WndProc;
	WndClass.lpszClassName = CLASSNAME;
	WndClass.style = CS_HREDRAW | CS_VREDRAW;
	if(!RegisterClass(&WndClass))
		return 0;
        
	hWnd = CreateWindow(CLASSNAME, WINNAME, WS_OVERLAPPEDWINDOW,
						CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
						NULL, NULL, hInstance, NULL);

	ShowWindow(hWnd, nCmdShow);
    
	// This is our windows messaging loop!
	while(GetMessage(&Message, hWnd, 0, 0))
	{
		TranslateMessage(&Message);
		DispatchMessage(&Message);
	}
	return Message.wParam;
}


/* Details for CreateFont(..) from the ms docs.
	HFONT CreateFont(
		int nHeight,               // height of font
		int nWidth,                // average character width
		int nEscapement,           // angle of escapement
		int nOrientation,          // base-line orientation angle
		int fnWeight,              // font weight
		DWORD fdwItalic,           // italic attribute option
		DWORD fdwUnderline,        // underline attribute option
		DWORD fdwStrikeOut,        // strikeout attribute option
		DWORD fdwCharSet,          // character set identifier
		DWORD fdwOutputPrecision,  // output precision
		DWORD fdwClipPrecision,    // clipping precision
		DWORD fdwQuality,          // output quality
		DWORD fdwPitchAndFamily,   // pitch and family
		LPCTSTR lpszFace           // typeface name
	);
*/

// This is our Call Back procedure, where you would put your code...this gets
// called repeatedly from our windows messaging loop.
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	switch(iMessage)
	{
	case WM_MOUSEMOVE:
		{
			HDC hDC = GetDC(hWnd);
			int xp = LOWORD(lParam);
			int yp = HIWORD(lParam);
			// Use the default Font to display our mouse position on screen
			char buf[200];           // Temp text buffer
			sprintf(buf, "xpos:%d, ypos:%d", xp, yp);

			// NEW ** NEW ** NEW ** NEW ** NEW ** NEW ** NEW ** NEW ** NEW **
			HGDIOBJ hObj;
			int iWeight = 2;
			DWORD dwItalic = 0; // 1 for italic/ 0 for no itallic
			// Create our font!  This is where the magic happens :)
			HFONT hNewFont = CreateFont(25, 12, 0, 0, iWeight, dwItalic, FALSE, FALSE, 
				    DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, 
					DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, NULL);

			// Select our new font into our DC so we can use it.
			hObj = SelectObject(hDC, hNewFont);

			//       +--- HDC, which is our screen drawing canvas
			//       |   +---+-- x and y position..where 0,0 is the top left
			//       |   |   |   +--- Our string of char's
			//       |   |   |   |       +------The number of characters to display
			//      \|/ \|/ \|/ \|/     \|/
			//       |   |   |   |       |
			TextOut(hDC, 5,  5, buf, strlen(buf));
			SelectObject(hDC, hObj); // Select our old object back into hDC - always leave 
			                         // it the way you found it as they say.
			ReleaseDC(hWnd, hDC);

			// NEW ** NEW ** NEW ** NEW ** NEW ** NEW ** NEW ** NEW ** NEW **
			DeleteObject(hNewFont);
		}
		break;
	case WM_CLOSE:
		if(MessageBox(hWnd, "Leave? Quit the our mini window?", "Message", MB_YESNO) == IDYES)
			PostQuitMessage(0);
		
		break;
	default:
		return DefWindowProc(hWnd, iMessage, wParam, lParam);
	}
	return 0;
}



