Skip to content

Commit

Permalink
Prepare for version 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPayne committed Aug 15, 2017
0 parents commit dbe097d
Show file tree
Hide file tree
Showing 16 changed files with 955 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore compiled binaries
/bin/
/obj/
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>
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This Makefile will build the MinGW Win32 MDI Example application

# Object files to create for the executable
OBJS = obj/WinMain.o obj/MainWindow.o obj/MDIChildWindow.o obj/AboutDialog.o obj/Resource.o

# Warnings to be raised by the C compiler
WARNS = -Wall

# Names of tools to use when building
CC = gcc
RC = windres

# Compiler flags. Compile ANSI build only if CHARSET=ANSI.
ifeq (${CHARSET}, ANSI)
CFLAGS = -O2 -std=c99 -D _WIN32_IE=0x0500 -D WINVER=0x0500 ${WARNS} -Iinclude
else
CFLAGS = -O2 -std=c99 -D UNICODE -D _UNICODE -D _WIN32_IE=0x0500 -D WINVER=0x0500 ${WARNS} -Iinclude
endif

# Linker flags
LDFLAGS = -s -lcomctl32 -lcomdlg32 -Wl,--subsystem,windows

.PHONY: all clean

# Build executable by default
all: bin/Win32MDIApp.exe

# Delete all build output
clean:
if exist bin\* del /q bin\*
if exist obj\* del /q obj\*

# Create build output directories if they don't exist
bin obj:
@if not exist "$@" mkdir "$@"

# Compile object files for executable
obj/%.o: src/%.c | obj
${CC} ${CFLAGS} -c "$<" -o "$@"

# Build the resources
obj/Resource.o: res/Resource.rc res/Application.manifest res/Application.ico include/Resource.h | obj
${RC} -I./include -I./res -i "$<" -o "$@"

# Build the exectuable
bin/Win32MDIApp.exe: ${OBJS} | bin
${CC} -o "$@" ${OBJS} ${LDFLAGS}

# C header dependencies
obj/AboutDialog.o: include/AboutDialog.h include/Resource.h include/Globals.h
obj/MainWindow.o: include/MainWindow.h include/MDIChildWindow.h include/AboutDialog.h include/Resource.h include/Globals.h
obj/MDIChildWindow.o: include/MDIChildWindow.h include/MainWindow.h include/Resource.h include/Globals.h
obj/WinMain.o: include/MainWindow.h include/MDIChildWindow.h include/Resource.h include/Globals.h
51 changes: 51 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# MinGW Win32 MDI Application

## Table of Contents

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

## Introduction

This application is an example Windows MDI GUI application, written to demonstrate how this can be done using MinGW. It
accompanies the [Win32 Apps with MinGW](http://www.transmissionzero.co.uk/computing/win32-apps-with-mingw/) article on
[Transmission Zero](http://www.transmissionzero.co.uk/). The compiled application is a fully functional, with the
exception that opening and saving files does not read or write the files, and the MDI child windows do not have any code
to display documents. However, by adding this functionality you can quickly create a functioning MDI application.

To build the application on a Windows machine, open a command prompt, change to the directory containing the Makefile,
and type "mingw32-make". The application should be compiled, linked, and output as "bin\Win32MDIApp.exe".

To compile an ANSI build (i.e. if you want the application to run under Windows 9x), run "mingw32-make CHARSET=ANSI"
from the command prompt.

To build under another operating system, the Makefile will probably require some small changes. For example, under
Fedora the C compiler and resource compiler are named "i686-pc-mingw32-gcc" and "i686-pc-mingw32-windres". Also, your
version of the make utility may be named differently--please check the documentation which came with your MinGW
packages.

It should also be possible to build the application using any C or C++ compiler which supports targeting Windows, for
example Open Watcom. You will of course need to set the projects up for yourself if you do that. It can also be built
with Visual C++, however you are advised to use the
[MSVC Win32 MDI Application](https://github.com/TransmissionZero/MSVC-Win32-MDI-Application) because that's ready to use
with MSVC. No source code modifications are required if you want to build a 64 bit version of the application.

## 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
[Win32 Apps with MinGW](http://www.transmissionzero.co.uk/computing/win32-apps-with-mingw/) article. If you are still
having trouble, you can [get in contact](http://www.transmissionzero.co.uk/contact/).

## Changelog

1. 2017-08-14: Version 1.0
- Initial release.

Transmission Zero
2017-08-14
12 changes: 12 additions & 0 deletions include/AboutDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H

#include <windows.h>

/* Dialog procedure for our "about" dialog */
INT_PTR CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

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

#endif
15 changes: 15 additions & 0 deletions include/Globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef GLOBALS_H
#define GLOBALS_H

#include <windows.h>

/* Global instance handle */
extern HINSTANCE g_hInstance;

/* Global main window handle */
extern HWND g_hMainWindow;

/* Global MDI client window handle */
extern HWND g_hMDIClient;

#endif
31 changes: 31 additions & 0 deletions include/MDIChildWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef MDICHILDWINDOW_H
#define MDICHILDWINDOW_H

#include <windows.h>

/* Window procedure for our main window */
LRESULT CALLBACK MDIChildWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

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

/* Create a new MDI child window */
void MDIChildNew(HWND hMDIClient);

/* Open a document in a new MDI child window */
void MDIChildOpen(HWND hMDIClient);

/* Save a document in an MDI child window */
void MDIChildSave(HWND hMDIChild);

/* Save a document in an MDI child window with a filename */
void MDIChildSaveAS(HWND hMDIChild);

/* Instance data for the MDI child window */
typedef struct tagMdiChildData
{
/* Flag to determine whether this is a new document which hasn't been saved */
BOOL IsUnSaved;
} MdiChildData;

#endif
21 changes: 21 additions & 0 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <windows.h>

/* Window procedure for our main window */
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

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

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

/* Callback to close all child windows */
BOOL CALLBACK CloseAllProc(HWND hWnd, LPARAM lParam);

/* First ID Windows should use for menu items it attaches to the "Window" menu */
#define ID_MDI_FIRSTCHILD 50000

#endif
25 changes: 25 additions & 0 deletions include/Resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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_NEW 40001
#define ID_FILE_OPEN 40002
#define ID_FILE_SAVE 40003
#define ID_FILE_SAVEAS 40004
#define ID_FILE_CLOSE 40005
#define ID_FILE_CLOSEALL 40006
#define ID_FILE_EXIT 40007
#define ID_WINDOW_TILE 40008
#define ID_WINDOW_CASCADE 40009
#define ID_WINDOW_ARRANGE 40010
#define ID_HELP_ABOUT 40011
#define ID_MDI_FIRSTCHILD 50000

#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif

#endif
Binary file added res/Application.ico
Binary file not shown.
30 changes: 30 additions & 0 deletions res/Application.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Supports Windows Vista / Server 2008 -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Supports Windows 7 / Server 2008 R2 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Supports Windows 8 / Server 2012 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Supports Windows 8.1 / Server 2012 R2 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Supports Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
</assembly>
92 changes: 92 additions & 0 deletions res/Resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <windows.h>
#include "Resource.h"

/* Win32 application icon */
IDI_APPICON ICON "Application.ico"

/* Our main menu */
IDR_MAINMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New\tCtrl+N", ID_FILE_NEW
MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE, GRAYED
MENUITEM "&Save As...", ID_FILE_SAVEAS, GRAYED
MENUITEM SEPARATOR
MENUITEM "&Close\tCtrl+F4", ID_FILE_CLOSE, GRAYED
MENUITEM "&Close All", ID_FILE_CLOSEALL, GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Window" GRAYED
BEGIN
MENUITEM "&Tile\tShift+F5", ID_WINDOW_TILE
MENUITEM "&Cascade\tShift+F4", ID_WINDOW_CASCADE
MENUITEM "Arrange &Icons", ID_WINDOW_ARRANGE
END
POPUP "&Help"
BEGIN
MENUITEM "&About", ID_HELP_ABOUT
END
END

/* Application manifest */
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Application.manifest"

/* Executable version information */
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE
#else
FILEFLAGS 0
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "Transmission Zero"
VALUE "FileDescription", "Win32 MDI Example application"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "Win32MDIApp"
VALUE "LegalCopyright", "�2017 Transmission Zero"
VALUE "OriginalFilename", "Win32MDIApp.exe"
VALUE "ProductName", "Win32 MDI Example application"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

/* Our "about" dialog */
IDD_ABOUTDIALOG DIALOGEX 0, 0, 147, 67
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
ICON IDI_APPICON,IDC_STATIC,7,7,20,20
LTEXT "Win32 MDI Example application.",IDC_STATIC,34,7,98,8
LTEXT "�2017 Transmission Zero",IDC_STATIC,34,17,86,8
DEFPUSHBUTTON "OK",IDOK,90,46,50,14,WS_GROUP
END

/* Our accelerators */
IDR_ACCELERATOR ACCELERATORS
BEGIN
"A", ID_HELP_ABOUT, VIRTKEY, ALT, NOINVERT
"N", ID_FILE_NEW, VIRTKEY, CONTROL, NOINVERT
"O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
"S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
VK_F4, ID_WINDOW_CASCADE, VIRTKEY, SHIFT, NOINVERT
VK_F5, ID_WINDOW_TILE, VIRTKEY, SHIFT, NOINVERT
END
Loading

0 comments on commit dbe097d

Please sign in to comment.