Skip to content

Commit a301ab0

Browse files
committed
Prepare for version 1.3.
1 parent 1cbea49 commit a301ab0

20 files changed

Lines changed: 650 additions & 319 deletions

AboutDlg.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "aboutdlg.h"
2+
#include "resource.h"
3+
#include "globals.h"
4+
5+
/* Dialog procedure for our "about" dialog */
6+
BOOL CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
7+
{
8+
switch (uMsg)
9+
{
10+
case WM_COMMAND:
11+
{
12+
WORD id = wParam;
13+
14+
switch (id)
15+
{
16+
case IDOK:
17+
case IDCANCEL:
18+
{
19+
EndDialog(hwndDlg, id);
20+
return TRUE;
21+
}
22+
}
23+
break;
24+
}
25+
26+
case WM_INITDIALOG:
27+
return TRUE;
28+
}
29+
30+
return FALSE;
31+
}
32+
33+
/* Show our "about" dialog */
34+
void ShowAboutDialog(HWND owner)
35+
{
36+
/* Create dialog callback thunk */
37+
FARPROC aboutProc = MakeProcInstance(&AboutDialogProc, g_hInstance);
38+
39+
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), owner, aboutProc);
40+
41+
/* Free dialog callback thunk */
42+
FreeProcInstance(aboutProc);
43+
}

AboutDlg.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef ABOUTDLG_H
2+
#define ABOUTDLG_H
3+
4+
#include <windows.h>
5+
6+
/* Dialog procedure for our "about" dialog */
7+
BOOL CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
8+
9+
/* Show our "about" dialog */
10+
void ShowAboutDialog(HWND owner);
11+
12+
#endif

Globals.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef GLOBALS_H
2+
#define GLOBALS_H
3+
4+
#include <windows.h>
5+
6+
/* Global instance handle */
7+
extern HINSTANCE g_hInstance;
8+
9+
#endif

MainWnd.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include "mainwnd.h"
2+
#include "aboutdlg.h"
3+
#include "resource.h"
4+
#include "globals.h"
5+
6+
/* Main window class and title */
7+
static const char MainWndClass[] = "Win16 Example Application";
8+
9+
/* Window procedure for our main window */
10+
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
11+
{
12+
switch (msg)
13+
{
14+
case WM_COMMAND:
15+
{
16+
WORD id = wParam;
17+
18+
switch (id)
19+
{
20+
case ID_HELP_ABOUT:
21+
{
22+
ShowAboutDialog(hWnd);
23+
break;
24+
}
25+
26+
case ID_FILE_EXIT:
27+
{
28+
DestroyWindow(hWnd);
29+
break;
30+
}
31+
32+
default:
33+
return DefWindowProc(hWnd, msg, wParam, lParam);
34+
}
35+
36+
break;
37+
}
38+
39+
case WM_GETMINMAXINFO:
40+
{
41+
/* Prevent our window from being sized too small */
42+
MINMAXINFO *minMax = (MINMAXINFO*) lParam;
43+
minMax->ptMinTrackSize.x = 220;
44+
minMax->ptMinTrackSize.y = 110;
45+
46+
break;
47+
}
48+
49+
/* Item from system menu has been invoked */
50+
case WM_SYSCOMMAND:
51+
{
52+
WORD id = wParam;
53+
54+
switch (id)
55+
{
56+
case ID_HELP_ABOUT:
57+
{
58+
ShowAboutDialog(hWnd);
59+
break;
60+
}
61+
62+
default:
63+
return DefWindowProc(hWnd, msg, wParam, lParam);
64+
}
65+
66+
break;
67+
}
68+
69+
case WM_DESTROY:
70+
{
71+
PostQuitMessage(0);
72+
break;
73+
}
74+
75+
default:
76+
return DefWindowProc(hWnd, msg, wParam, lParam);
77+
}
78+
79+
return 0;
80+
}
81+
82+
/* Register a class for our main window */
83+
BOOL RegisterMainWindowClass()
84+
{
85+
WNDCLASS wc = {0};
86+
87+
wc.lpfnWndProc = &MainWndProc;
88+
wc.hInstance = g_hInstance;
89+
wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APPICON));
90+
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
91+
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
92+
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
93+
wc.lpszClassName = MainWndClass;
94+
95+
return (RegisterClass(&wc)) ? TRUE : FALSE;
96+
}
97+
98+
/* Create an instance of our main window */
99+
HWND CreateMainWindow()
100+
{
101+
HWND hWnd;
102+
HMENU hSysMenu;
103+
104+
hWnd = CreateWindowEx(0, MainWndClass, MainWndClass, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
105+
320, 200, NULL, NULL, g_hInstance, NULL);
106+
107+
if (hWnd)
108+
{
109+
/* Add "about" to the system menu */
110+
hSysMenu = GetSystemMenu(hWnd, FALSE);
111+
InsertMenu(hSysMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
112+
InsertMenu(hSysMenu, 6, MF_BYPOSITION, (UINT) ID_HELP_ABOUT, "About");
113+
}
114+
115+
return hWnd;
116+
}

MainWnd.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef MAINWND_H
2+
#define MAINWND_H
3+
4+
#include <windows.h>
5+
6+
/* Window procedure for our main window */
7+
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
8+
9+
/* Register a class for our main window */
10+
BOOL RegisterMainWindowClass();
11+
12+
/* Create an instance of our main window */
13+
HWND CreateMainWindow();
14+
15+
#endif

Makefile

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
# This Makefile will build the Win16 test application.
1+
# This Makefile will build the Win16 Example application
22

3-
HEADERS = Resource.h Callback.h
4-
OBJS = WinMain.obj Callback.obj
5-
RES = Resource.res
6-
7-
CC = cl16.exe
3+
CC = cl
84
CFLAGS = /nologo /c /D NDEBUG /D WINVER=0x0300 /G3swf /Os /W3 /Zp /FPi87
9-
LINK = link16.exe
10-
RC = rc16.exe
11-
EXE = Win16App.exe
12-
DEF = Win16App.def
5+
LINK = link
6+
RC = rc
7+
8+
OBJS = WinMain.obj MainWnd.obj AboutDlg.obj
139

10+
# Rules
1411
all: Win16App.exe
1512

16-
Win16App.exe: $(OBJS) $(RES) $(DEF)
17-
$(LINK) /nologo /align:16 $(OBJS),$(EXE),,libw.lib slibcew.lib,$(DEF)
18-
$(RC) /nologo /30 $(RES) $(EXE)
13+
Win16App.exe:
14+
$(LINK) /nologo /align:16 $(OBJS),Win16App.exe,,libw.lib slibcew.lib,Win16App.def
15+
$(RC) /nologo /30 Resource.res Win16App.exe
1916

2017
clean:
21-
del $(OBJS) $(RES) $(EXE) Win16App.map
18+
@del *.obj *.res *.map Win16App.exe 2> NUL
2219

23-
%.obj: %.c $(HEADERS)
20+
%.obj:
2421
$(CC) $(CFLAGS) $<
2522

23+
Resource.res:
24+
$(RC) /nologo /r Resource.rc
25+
26+
# Dependencies
27+
Win16App.exe: $(OBJS) Resource.res Win16App.def
28+
AboutDlg.obj: AboutDlg.c AboutDlg.h Resource.h Globals.h
29+
MainWnd.obj: MainWnd.c MainWnd.h AboutDlg.h Resource.h Globals.h
30+
WinMain.obj: WinMain.c MainWnd.h Resource.h Globals.h
2631
Resource.res: Resource.rc App.ico Resource.h
27-
$(RC) /nologo /r resource.rc

Readme.txt

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
Win16 Test Application
1+
Win16 Example Application
22

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

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

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

1621

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

3540

36-
Problems?
41+
Known Problems
42+
43+
If you try to launch this application while the Windows 1 version of the
44+
application is already running, you get a second instance of the Windows 1
45+
application instead! I can�t find any reason why this would happen, but I�ve
46+
tested the application on Windows 3.0 to Windows 8.1, and it behaves the same
47+
across all of them.
3748

38-
If you have any problems or questions, please get in contact via
49+
The Open Watcom build of the application doesn�t work correctly under Windows
50+
3.0 when running in real mode. The application will start but the menu is
51+
missing and the about dialog won�t display. I�ve found Open Watcom to be a bit
52+
hit and miss, where certain seemingly harmless changes of compiler option result
53+
in an application which crashes, so it may be possible to fix this by changing
54+
the compiler options.
55+
56+
If you have any other problems or questions, please get in contact via
3957
http://www.transmissionzero.co.uk/contact/. Please ensure that you read the
4058
article at http://www.transmissionzero.co.uk/computing/win16-apps-in-c/ before
4159
sending any questions.
4260

4361

4462
Changelog
4563

64+
2014-11-09: Version 1.3
65+
� Added a Makefile project for use with the Visual C++ GUI.
66+
� Refactored some of the code to split the source code files by functionality.
67+
4668
2013�09-07: Version 1.2
4769

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

5779
2011�07�06: Version 1.0
5880

5981
� First release.
6082

61-
Martin Payne
62-
2013�09-07
83+
Transmission Zero
84+
2014-11-09

Resource.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef RESOURCE_H
2+
#define RESOURCE_H
3+
4+
#define IDI_APPICON 101
5+
#define IDR_MAINMENU 102
6+
#define IDR_ACCELERATOR 103
7+
#define IDD_ABOUTDIALOG 104
8+
#define ID_FILE_EXIT 40001
9+
#define ID_HELP_ABOUT 40002
10+
11+
#ifndef IDC_STATIC
12+
#define IDC_STATIC -1
13+
#endif
14+
15+
#endif

0 commit comments

Comments
 (0)