Software Development Resources
Main Page | Software Development | Categories | Recent changes | About DocForge
Log in / create account | Log in with OpenID | Help

Microsoft Windows

From DocForge

(Redirected from Windows)
Experimental-page.jpgThis page is a stub. It's lacking in details and can use your help. Please contribute your knowledge to this page.

Microsoft Windows is a family of operating systems created by the Microsoft Corporation. Windows was first developed for the IBM PC and compatible architectures and was the first graphical user interface on that architecture. It is still the predominant operating system on desktop PC platforms.

Versions 1.0 to 3.1 were basically graphical window managers on top of MS-DOS. Windows NT was the first version of Windows to qualify as a complete operating system, while Windows 95 was the first one that was widely distributed to users. The Windows 95-ME still had MS-DOS as the underlying platform, but no longer needed prior installation of MS-DOS to function.

For many years Microsoft Windows provided application developers with 16- and 32-bit APIs in the form of DLLs (Dynamic Link Libraries). Native applications could be written in C++ and Visual Basic and compiled into executables which used the DLLs distributed with the operating system. Today Microsoft provides the .NET framework for application development which underneath utilizes the older APIs to interact directly with Windows.

[edit] Versions

Versions with significant use today in reverse chronological order:

  • Microsoft Windows 7
  • Microsoft Windows Vista
  • Microsoft Windows XP
  • Microsoft Windows 2000
  • Microsoft Windows ME
  • Microsoft Windows 98
  • Microsoft Windows 95
  • Microsoft Windows NT 4.0

Older versions include:

  • Microsoft Windows 3.11 for Workgroups
  • Microsoft Windows 3.1
  • Microsoft Windows 3.0
  • Microsoft Windows 2.0
  • Microsoft Windows 1.0

[edit] Hello world

The following code produces a program that creates Hello World.

Due to the complexity of Windows, it is generally tedious to re-write all of this by hand each time you make a new application. As such, you will want to reuse the same initialization code for each application.

#include <windows.h>
#include <tchar.h>
 
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
 
/** 
 *_tWinMain is the startup function for the latest versions of the Windows API.  
 * With <tchar.h>, this name allows compiling a program for both the ANSI and Unicode
 * settings without making changes to the source. 
 *
 * There are four parameters, three of which are important for must usages:
 * * hInstance, which is a handle to the instance of the program.  Usually, this should get stored in a global variable.
 * * hPrevInstance, whichis a handle to an already existing instance of the same program.
 * * lpCmdLine, a pointer to a string containing the command line. 
 * * nCmdShow, the default window open state provided on program launch. 
 */
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
	WNDCLASSEX wcex;
	TCHAR szTitle[] = _T("Hello World!");					// The title bar text
	TCHAR szWindowClass[]= _T("Hello World");			// the main window class name
 
	/* Register the window class.  */
	wcex.cbSize		= sizeof(WNDCLASSEX);  // Must equal size of structure. 
	wcex.style		= CS_HREDRAW | CS_VREDRAW; // Specifies redraw on window resize.
	wcex.lpfnWndProc	= WndProc;  // Specifies callback function. 
	wcex.cbClsExtra		= 0; // Extra bytes for class function; usually 0.
	wcex.cbWndExtra		= 0; // Extra bytes for Window instance; usually 0.
	wcex.hInstance		= hInstance; // Refers to instance passed from _tWinMain
	wcex.hIcon		= LoadIcon(hInstance, IDI_APPLICATION); // Loads a stock icon.
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW); // Sets the stock cursor.
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOWFRAME); // Uses stock color. 
	wcex.lpszMenuName	= NULL; // Refernce to menu; unused here. 
	wcex.lpszClassName	= szWindowClass; // Name of the Window class. 
	wcex.hIconSm		= LoadIcon(hInstance, IDI_APPLICATION);
 
	if (!RegisterClassEx(&wcex))
	{
		return -1;
	}
 
	/* This creates and displays the window. */
	hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	if (!hwnd)
	{
		return -1; 
	}
 
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
 
	/* Message loop.  This will continue processing until the window is closed (see below) */
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
 
	return (int) msg.wParam;
}
 
/**
 * WndProc is the main callback function for the window created above. 
 */
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	RECT r;
 
	switch (message)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hWnd, &ps);
 
			/* Painting steps are shown here.  In this case, "Hello World" is shown at the top-left. */
			r.left=100; r.right=300; r.top=75; r.bottom=100; 
			DrawText(hdc, _T("Hello World"), 11, &r, 0);
 
			EndPaint(hWnd, &ps);
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		/* Any other messages should be handled by DefWindowProc. */
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

[edit] See also

Discussion

comments powered by Disqus