delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/02/24/14:59:17

From: colin AT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters)
Subject: RE: Please Help...
24 Feb 1998 14:59:17 -0800 :
Message-ID: <008401bd40df$bc37cc60$fa173185.cygnus.gnu-win32@gbird0.fu.is.saga-u.ac.jp>
Mime-Version: 1.0
To: "ShmooVe" <ShmooVe AT vvi DOT net>
Cc: "GNU-Win32" <gnu-win32 AT cygnus DOT com>

This is a multi-part message in MIME format.

------=_NextPart_000_0081_01BD412B.2B454100
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

ShmooVe <ShmooVe AT vvi DOT net> wrote:

[snip]
>                    Could someone send me a little test code ... say a
hello
>world proggie
>    that brings up a little window and a button??  (I hope I'm getting the
right
>impression on this gnuwin32) so I can get the feel of window mantiuplation.
Is
>it anything like JavaScript?  Thanx again guys


It's not much like JavaScript, I don't think. I've attached source for a
test program which creates a window with the string "Hello World" printed in
the middle of the upper half of the window, and a "Click Here" button in the
lower half (I've cc-d the gnu-win32 list in case any other Win32 newbies
would like a look).

You should be able to compile this source using

 gcc -c -o test.o test.c
 gcc -mwindows -o test.exe test.o

Good luck,
Colin.


------=_NextPart_000_0081_01BD412B.2B454100
Content-Type: application/octet-stream;
	name="test.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="test.c"

/*
 * A basic example of Win32 programming in C.
 *
 * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
 *
 * Colin Peters <colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT jp>
 */

#include <windows.h>
#include <string.h>

/*
 * This is the window function for the main window. Whenever a message =
is
 * dispatched using DispatchMessage (or sent with SendMessage) this =
function
 * gets called with the contents of the message.
 */
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	/* The window handle for the "Click Me" button. */
	static	HWND	hwndButton =3D 0;
	static int	cx, cy;	/* Height and width of our button. */

	HDC		hdc;	/* A device context used for drawing */
	PAINTSTRUCT	ps;	/* Also used during window drawing */
	RECT		rc;	/* A rectangle used during drawing */

	/*
	 * Perform processing based on what kind of message we got.
	 */
	switch (nMsg)
	{
		case WM_CREATE:
		{
			/* The window is being created. Create our button
			 * window now. */
			TEXTMETRIC	tm;

			/* First we use the system fixed font size to choose
			 * a nice button size. */
			hdc =3D GetDC (hwnd);
			SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
			GetTextMetrics (hdc, &tm);
			cx =3D tm.tmAveCharWidth * 30;
			cy =3D (tm.tmHeight + tm.tmExternalLeading) * 2;
			ReleaseDC (hwnd, hdc);

			/* Now create the button */
			hwndButton =3D CreateWindow (
				"button",	/* Builtin button class */
				"Click Here",
				WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
				0, 0, cx, cy,
				hwnd,		/* Parent is this window. */
				(HMENU) 1,	/* Control ID: 1 */
				((LPCREATESTRUCT) lParam)->hInstance,
				NULL
				);

			return 0;
			break;
		}

		case WM_DESTROY:
			/* The window is being destroyed, close the application
			 * (the child button gets destroyed automatically). */
			PostQuitMessage (0);
			return 0;
			break;

		case WM_PAINT:
			/* The window needs to be painted (redrawn). */
			hdc =3D BeginPaint (hwnd, &ps);
			GetClientRect (hwnd, &rc);

			/* Draw "Hello, World" in the middle of the upper
			 * half of the window. */
			rc.bottom =3D rc.bottom / 2;
			DrawText (hdc, "Hello, World", -1, &rc,
				DT_SINGLELINE | DT_CENTER | DT_VCENTER);

			EndPaint (hwnd, &ps);
			return 0;
			break;

		case WM_SIZE:
			/* The window size is changing. If the button exists
			 * then place it in the center of the bottom half of
			 * the window. */
			if (hwndButton &&
				(wParam =3D=3D SIZEFULLSCREEN ||
				 wParam =3D=3D SIZENORMAL)
			   )
			{
				rc.left =3D (LOWORD(lParam) - cx) / 2;
				rc.top =3D HIWORD(lParam) * 3 / 4 - cy / 2;
				MoveWindow (
					hwndButton,
					rc.left, rc.top, cx, cy, TRUE);
			}
			break;

		case WM_COMMAND:
			/* Check the control ID, notification code and
			 * control handle to see if this is a button click
			 * message from our child button. */
			if (LOWORD(wParam) =3D=3D 1 &&
			    HIWORD(wParam) =3D=3D BN_CLICKED &&
			    lParam =3D=3D hwndButton)
			{
				/* Our button was clicked. Close the window. */
				DestroyWindow (hwnd);
			}
			return 0;
			break;
	}

	/* If we don't handle a message completely we hand it to the system
	 * provided default window function. */
	return DefWindowProc (hwnd, nMsg, wParam, lParam);
}


int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
	HWND		hwndMain;	/* Handle for the main window. */
	MSG		msg;		/* A Win32 message structure. */
	WNDCLASSEX	wndclass;	/* A window class structure. */
	char*		szMainWndClass =3D "WinTestWin";
					/* The name of the main window class */

	/*
	 * First we create a window class for our main window.
	 */

	/* Initialize the entire structure to zero. */
	memset (&wndclass, 0, sizeof(WNDCLASSEX));

	/* This class is called WinTestWin */
	wndclass.lpszClassName =3D szMainWndClass;

	/* cbSize gives the size of the structure for extensibility. */
	wndclass.cbSize =3D sizeof(WNDCLASSEX);

	/* All windows of this class redraw when resized. */
	wndclass.style =3D CS_HREDRAW | CS_VREDRAW;

	/* All windows of this class use the MainWndProc window function. */
	wndclass.lpfnWndProc =3D MainWndProc;

	/* This class is used with the current program instance. */
	wndclass.hInstance =3D hInst;

	/* Use standard application icon and arrow cursor provided by the OS */
	wndclass.hIcon =3D LoadIcon (NULL, IDI_APPLICATION);
	wndclass.hIconSm =3D LoadIcon (NULL, IDI_APPLICATION);
	wndclass.hCursor =3D LoadCursor (NULL, IDC_ARROW);

	/* Color the background white */
	wndclass.hbrBackground =3D (HBRUSH) GetStockObject (WHITE_BRUSH);

	/*
	 * Now register the window class for use.
	 */
	RegisterClassEx (&wndclass);

	/*
	 * Create our main window using that window class.
	 */
	hwndMain =3D CreateWindow (
		szMainWndClass,		/* Class name */
		"Hello",		/* Caption */
		WS_OVERLAPPEDWINDOW,	/* Style */
		CW_USEDEFAULT,		/* Initial x (use default) */
		CW_USEDEFAULT,		/* Initial y (use default) */
		CW_USEDEFAULT,		/* Initial x size (use default) */
		CW_USEDEFAULT,		/* Initial y size (use default) */
		NULL,			/* No parent window */
		NULL,			/* No menu */
		hInst,			/* This program instance */
		NULL			/* Creation parameters */
		);
=09
	/*
	 * Display the window which we just created (using the nShow
	 * passed by the OS, which allows for start minimized and that
	 * sort of thing).
	 */
	ShowWindow (hwndMain, nShow);
	UpdateWindow (hwndMain);

	/*
	 * The main message loop. All messages being sent to the windows
	 * of the application (or at least the primary thread) are retrieved
	 * by the GetMessage call, then translated (mainly for keyboard
	 * messages) and dispatched to the appropriate window procedure.
	 * This is the simplest kind of message loop. More complex loops
	 * are required for idle processing or handling modeless dialog
	 * boxes. When one of the windows calls PostQuitMessage GetMessage
	 * will return zero and the wParam of the message will be filled
	 * with the argument to PostQuitMessage. The loop will end and
	 * the application will close.
         */
	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}
	return msg.wParam;
}


------=_NextPart_000_0081_01BD412B.2B454100--

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019