Skip to content

Commit

Permalink
Prepare for version 1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPayne committed Nov 9, 2014
1 parent 1cbea49 commit a301ab0
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 319 deletions.
43 changes: 43 additions & 0 deletions AboutDlg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "aboutdlg.h"
#include "resource.h"
#include "globals.h"

/* Dialog procedure for our "about" dialog */
BOOL CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM 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(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);
}
12 changes: 12 additions & 0 deletions AboutDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef ABOUTDLG_H
#define ABOUTDLG_H

#include <windows.h>

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

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

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

#include <windows.h>

/* Global instance handle */
extern HINSTANCE g_hInstance;

#endif
116 changes: 116 additions & 0 deletions MainWnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "mainwnd.h"
#include "aboutdlg.h"
#include "resource.h"
#include "globals.h"

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

/* Window procedure for our main window */
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM 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 = {0};

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 = CreateWindowEx(0, 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);
InsertMenu(hSysMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
InsertMenu(hSysMenu, 6, MF_BYPOSITION, (UINT) ID_HELP_ABOUT, "About");
}

return hWnd;
}
15 changes: 15 additions & 0 deletions MainWnd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef MAINWND_H
#define MAINWND_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();

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

#endif
36 changes: 20 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# This Makefile will build the Win16 test application.
# This Makefile will build the Win16 Example application

HEADERS = Resource.h Callback.h
OBJS = WinMain.obj Callback.obj
RES = Resource.res

CC = cl16.exe
CC = cl
CFLAGS = /nologo /c /D NDEBUG /D WINVER=0x0300 /G3swf /Os /W3 /Zp /FPi87
LINK = link16.exe
RC = rc16.exe
EXE = Win16App.exe
DEF = Win16App.def
LINK = link
RC = rc

OBJS = WinMain.obj MainWnd.obj AboutDlg.obj

# Rules
all: Win16App.exe

Win16App.exe: $(OBJS) $(RES) $(DEF)
$(LINK) /nologo /align:16 $(OBJS),$(EXE),,libw.lib slibcew.lib,$(DEF)
$(RC) /nologo /30 $(RES) $(EXE)
Win16App.exe:
$(LINK) /nologo /align:16 $(OBJS),Win16App.exe,,libw.lib slibcew.lib,Win16App.def
$(RC) /nologo /30 Resource.res Win16App.exe

clean:
del $(OBJS) $(RES) $(EXE) Win16App.map
@del *.obj *.res *.map Win16App.exe 2> NUL

%.obj: %.c $(HEADERS)
%.obj:
$(CC) $(CFLAGS) $<

Resource.res:
$(RC) /nologo /r Resource.rc

# Dependencies
Win16App.exe: $(OBJS) Resource.res Win16App.def
AboutDlg.obj: AboutDlg.c AboutDlg.h Resource.h Globals.h
MainWnd.obj: MainWnd.c MainWnd.h AboutDlg.h Resource.h Globals.h
WinMain.obj: WinMain.c MainWnd.h Resource.h Globals.h
Resource.res: Resource.rc App.ico Resource.h
$(RC) /nologo /r resource.rc
48 changes: 35 additions & 13 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
Win16 Test Application
Win16 Example Application

This application is an example 16�bit Windows application written in C. It
accompanies an article from my web site, located at
http://www.transmissionzero.co.uk/computing/win16-apps-in-c/.

To build the application with Microsoft�s Visual C++ compilers, simply open a
command prompt, change to the directory containing the Makefile, and run
�nmake�. Note that you will need the 16�bit C compiler, linker, and resource
compiler�it won�t work with 32�bit compilers! Also note that the Makefile may
require some small modifications if you use a make utility other than �nmake�.
To build the application with Microsoft�s Visual C++ compilers, open a command
prompt, change to the directory containing the Makefile, and run �nmake�. Note
that you will need the 16�bit C compiler, linker, and resource compiler�it won�t
work with 32�bit compilers! Also note that the Makefile may require some small
modifications if you use a make utility other than �nmake�.

To build the application in Open Watcom, simply open the project up in the IDE,
and choose the �Make� option from the �Targets� menu.
To build the application with the Microsoft Visual C++ GUI, open the
�Win16App.mak� file and build the application. You will need a version of Visual
C++ which supports building Win16 apps, for example Visual C++ 1.52 (available
from MSDN if you have a subscription).

To build the application in Open Watcom, open the project up in the IDE, and
choose the �Make� option from the �Targets� menu.


Disclaimer
Expand All @@ -33,16 +38,33 @@ entirely up to you. Of course, you must still comply with the licensing
conditions of the tools you are using to build the application.


Problems?
Known Problems

If you try to launch this application while the Windows 1 version of the
application is already running, you get a second instance of the Windows 1
application instead! I can�t find any reason why this would happen, but I�ve
tested the application on Windows 3.0 to Windows 8.1, and it behaves the same
across all of them.

If you have any problems or questions, please get in contact via
The Open Watcom build of the application doesn�t work correctly under Windows
3.0 when running in real mode. The application will start but the menu is
missing and the about dialog won�t display. I�ve found Open Watcom to be a bit
hit and miss, where certain seemingly harmless changes of compiler option result
in an application which crashes, so it may be possible to fix this by changing
the compiler options.

If you have any other problems or questions, please get in contact via
http://www.transmissionzero.co.uk/contact/. Please ensure that you read the
article at http://www.transmissionzero.co.uk/computing/win16-apps-in-c/ before
sending any questions.


Changelog

2014-11-09: Version 1.3
� Added a Makefile project for use with the Visual C++ GUI.
� Refactored some of the code to split the source code files by functionality.

2013�09-07: Version 1.2

� Removed superfluous LOWORD() macros which had been applied to WPARAMs.
Expand All @@ -52,11 +74,11 @@ Changelog
� Added a VERSIONINFO resource to the executable, so that version information
can be viewed in File Manager or Windows Explorer.
� Open Watcom build now runs in Windows 3.0 (but not in real mode).
� Ensured all source files are 8.3 characters long.
� Ensured all source files are no more than 8.3 characters long.

2011�07�06: Version 1.0

� First release.

Martin Payne
2013�09-07
Transmission Zero
2014-11-09
15 changes: 15 additions & 0 deletions Resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#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

#endif
Loading

0 comments on commit a301ab0

Please sign in to comment.