Skip to content

Commit

Permalink
Initial commit of Windows 1 Example Application.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPayne committed Aug 27, 2016
0 parents commit 7308e61
Show file tree
Hide file tree
Showing 14 changed files with 456 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore compiled binaries
*.exe
*.map
*.obj
*.res
49 changes: 49 additions & 0 deletions AboutDlg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <windows.h>
#include "aboutdlg.h"
#include "resource.h"
#include "globals.h"

/* Dialog procedure for our "about" dialog */
BOOL FAR PASCAL AboutDialogProc(hwndDlg, uMsg, wParam, lParam)
HWND hwndDlg;
unsigned uMsg;
WORD wParam;
LONG lParam;
{
switch (uMsg)
{
case WM_COMMAND:
{
WORD id = wParam;

switch (id)
{
case IDOK:
case IDCANCEL:
{
EndDialog(hwndDlg, id);
return TRUE;
}
}
break;
}

case WM_INITDIALOG:
return TRUE;
}

return FALSE;
}

/* Show our "about" dialog */
void ShowAboutDialog(owner)
HWND owner;
{
/* Create dialog callback thunk */
FARPROC aboutProc = MakeProcInstance(AboutDialogProc, g_hInstance);

DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), owner, aboutProc);

/* Free dialog callback thunk */
FreeProcInstance(aboutProc);
}
10 changes: 10 additions & 0 deletions AboutDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef ABOUTDLG_H
#define ABOUTDLG_H

/* Dialog procedure for our "about" dialog */
BOOL FAR PASCAL AboutDialogProc(HWND, unsigned, WORD, LONG);

/* Show our "about" dialog */
void ShowAboutDialog(HWND);

#endif
Binary file added App.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions Globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef GLOBALS_H
#define GLOBALS_H

/* Global instance handle */
extern HANDLE g_hInstance;

#endif
24 changes: 24 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
124 changes: 124 additions & 0 deletions MainWnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <windows.h>
#include <string.h>
#include "mainwnd.h"
#include "aboutdlg.h"
#include "resource.h"
#include "globals.h"

/* Main window class and title */
static char MainWndClass[] = "Windows 1 Example Application";

/* Window procedure for our main window */
LONG FAR PASCAL MainWndProc(hWnd, msg, wParam, lParam)
HWND hWnd;
unsigned msg;
WORD wParam;
LONG lParam;
{
switch (msg)
{
case WM_COMMAND:
{
WORD id = wParam;

switch (id)
{
case ID_HELP_ABOUT:
{
ShowAboutDialog(hWnd);
break;
}

case ID_FILE_EXIT:
{
DestroyWindow(hWnd);
break;
}

default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}

break;
}

case WM_GETMINMAXINFO:
{
/* Prevent our window from being sized too small */
MINMAXINFO *minMax = (MINMAXINFO*) lParam;
minMax->ptMinTrackSize.x = 220;
minMax->ptMinTrackSize.y = 110;

break;
}

/* Item from system menu has been invoked */
case WM_SYSCOMMAND:
{
WORD id = wParam;

switch (id)
{
case ID_HELP_ABOUT:
{
ShowAboutDialog(hWnd);
break;
}

default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}

break;
}

case WM_DESTROY:
{
PostQuitMessage(0);
break;
}

default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}

return 0;
}

/* Register a class for our main window */
BOOL RegisterMainWindowClass()
{
WNDCLASS wc;

memset(&wc, 0, sizeof(wc));

wc.lpfnWndProc = MainWndProc;
wc.hInstance = g_hInstance;
wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APPICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName = MainWndClass;

return (RegisterClass(&wc)) ? TRUE : FALSE;
}

/* Create an instance of our main window */
HWND CreateMainWindow()
{
HWND hWnd;
HMENU hSysMenu;

hWnd = CreateWindow(MainWndClass, MainWndClass, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
320, 200, NULL, NULL, g_hInstance, NULL);

if (hWnd)
{
/* Add "about" to the system menu. */
hSysMenu = GetSystemMenu(hWnd, FALSE);
ChangeMenu(hSysMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
ChangeMenu(hSysMenu, 0, "About", ID_HELP_ABOUT, MF_APPEND | MF_STRING);
}

return hWnd;
}
42 changes: 42 additions & 0 deletions MainWnd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef MAINWND_H
#define MAINWND_H

/* Window procedure for our main window */
LONG FAR PASCAL MainWndProc(HWND, unsigned, WORD, LONG);

/* Register a class for our main window */
BOOL RegisterMainWindowClass();

/* Create an instance of our main window */
HWND CreateMainWindow();

/* Minimum and maximum window sizing */
#ifndef WM_GETMINMAXINFO
#define WM_GETMINMAXINFO 0x0024

typedef struct tagMINMAXINFO
{
POINT ptReserved;
POINT ptMaxSize;
POINT ptMaxPosition;
POINT ptMinTrackSize;
POINT ptMaxTrackSize;
} MINMAXINFO;
#endif

/* Button colour */
#ifndef COLOR_BTNFACE
#define COLOR_BTNFACE 15
#endif

/* Overlapped window style */
#ifndef WS_OVERLAPPEDWINDOW
#define WS_OVERLAPPEDWINDOW WS_TILED | WS_CAPTION | WS_SYSMENU | WS_SIZEBOX | 0x00010000L | 0x00020000L
#endif

/* Default window positioning */
#ifndef CW_USEDEFAULT
#define CW_USEDEFAULT ((int)0x8000)
#endif

#endif
47 changes: 47 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Windows 1 Example Application

## Table of Contents

- [Introduction](#introduction)
- [Terms of Use](#terms-of-use)
- [Problems?](#problems)
- [Changelog](#changelog)

## Introduction

This application is an example 16 bit Windows application written in C. It
accompanies the
[Building Win16 GUI Applications in C](http://www.transmissionzero.co.uk/computing/win16-apps-in-c/)
article on [Transmission Zero](http://www.transmissionzero.co.uk/). The
application runs under Windows 1 to Windows 3.11, and all versions of Windows NT
which support Win16 apps (Windows NT 3.1 to at least the x86 version of Windows
8.1). It does not run under Windows 9x (Windows 95 to Windows ME). The reason
for this is not known at the moment.

To build the application with Microsoft C, open a command prompt, change to the
directory containing the Makefile, and run "make Win1App". Note that you will
need a very old version of the C compiler and Windows SDK to build the
application. I built it with Microsoft C 4 (not to be confused with Visual C++
4), but I believe it will compile with Microsoft C 5 as well. It cannot be built
with newer tools, e.g. Visual C++ 1.52, and I'm not aware of any freely
available tools you can use to build it.

## Terms of Use

Refer to "License.txt" for terms of use.

## Problems?

If you have any problems or questions, please ensure you have read this readme
file and the
[Building Win16 GUI Applications in C](http://www.transmissionzero.co.uk/computing/win16-apps-in-c/)
article. If you are still having trouble, you can
[get in contact](http://www.transmissionzero.co.uk/contact/).

## Changelog

1. 2014-11-09: Version 1.0
- First release.

Transmission Zero
2016-08-27
19 changes: 19 additions & 0 deletions Resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef RESOURCE_H
#define RESOURCE_H

#define IDI_APPICON 101
#define IDR_MAINMENU 102
#define IDR_ACCELERATOR 103
#define IDD_ABOUTDIALOG 104
#define ID_FILE_EXIT 40001
#define ID_HELP_ABOUT 40002

#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif

#ifndef DS_MODALFRAME
#define DS_MODALFRAME 0x80L
#endif

#endif
35 changes: 35 additions & 0 deletions Resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <windows.h>
#include "resource.h"

/* Win16 application icon */
IDI_APPICON ICON DISCARDABLE "App.ico"

/* Our main menu */
IDR_MAINMENU MENU DISCARDABLE
BEGIN
POPUP "File"
BEGIN
MENUITEM "Exit", ID_FILE_EXIT
END
POPUP "Help"
BEGIN
MENUITEM "About", ID_HELP_ABOUT
END
END

/* Our "about" dialog */
IDD_ABOUTDIALOG DIALOG DISCARDABLE 0, 0, 160, 67
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
BEGIN
ICON IDI_APPICON,IDC_STATIC,7,7,20,20
LTEXT "Windows 1 Example application.",IDC_STATIC,34,7,125,8
LTEXT "�2014 Transmission Zero",IDC_STATIC,34,17,100,8
DEFPUSHBUTTON "OK",IDOK,103,46,50,14,WS_GROUP
END

/* Our accelerators */
IDR_ACCELERATOR ACCELERATORS DISCARDABLE
BEGIN
0x41, ID_HELP_ABOUT, VIRTKEY, CONTROL, NOINVERT
END
Loading

0 comments on commit 7308e61

Please sign in to comment.