Article View: comp.os.ms-windows.programmer.tools
Article #324comp.os.ms-windows.programmer FAQ (Frequently Asked Questions)
From: Tom Haapanen
Date: Thu, 27 Aug 1992 12:53
Date: Thu, 27 Aug 1992 12:53
964 lines
40303 bytes
40303 bytes
Archive-name: ms-winprog-faq
Last-modified: 1992-06-19
Related-archives: ms-windows-faq
COPYRIGHT
This article is copyright 1990-1992 by Tom Haapanen. It may be freely
copied and/or distributed in its entirety as long as this copyright
notice is not removed. It may not be sold for profit or incorporated
into commercial products without the author's written permission.
TABLE OF CONTENTS
0. Index
>> 1. Windows newsgroups
2. Windows development tools
3. Windows linkers
4. Windows debuggers
5. Windows RTF word processors
6. Windows SQL products
7. Windows C++ class libraries
8. Windows extended memory handling
9. Windows screen prints
10. Device driver development
11. Hiding dialog box controls
12. Adding controls to a non-dialog box window
13. Using floating-point in Windows
14. Changing button colors
15. Programming using large model
16. Linking .FON files
17. Window background colors
18. Subclassing control windows
19. Changing the color palette in 16-color mode
20. Allocating global memory in a DLL
21. Determining the amount of physical memory
22. Aligning columns in a listbox
23. Keeping an application iconized or in a fixed-size window
24. Modifying a right-justified menu entry
25. What does 'new()' really do?
26. Changing directories in a Windows application
27. Is it possible to pass a structure back to Visual Basic from a DLL?
28. How can I find out how many instances of my application are running?
29. Is it possible to create an initially invisible MDI child window?
30. Why am I getting NULL dialog box handles with BC++?
31. How do I track down resources that I'm forgetting to free?
32. Can I get TDW TP/Win to work with Windows 3.1?
33. Why can't I print floating-point numbers with wsprintf()?
35. Drag-and-drop printing using File Manager and Print Manage
36. Generalized drag-and-drop
37. Automatically exiting a dialog box on timeout
38. Enumerating the icons in a Windows EXE or DLL
40. Interpreting Dr. Watson logs
41. Why does the Minimize button do strange things in a modal dialog?
99. Windows programmer's bibliography
*** A companion posting can be found in comp.windows.ms **
----------------------------------------------------------------------
1. What are the newsgroups for windows?
>> There are a total of eight newsgroups:
comp.os.ms-windows.advocacy
Adversarial discussions, arguments and comparisons to other systems.
comp.os.ms-windows.announce
A low-volume moderated group with announcements only, no discussions.
comp.os.ms-windows.apps
Discussions about the selection and use of Windows applications.
comp.os.ms-windows.setup
Questions and discussions about Windows setup, drivers and hardware.
comp.os.ms-windows.misc
All other discussions about Windows.
comp.os.ms-windows.programmer.tools
Discussions about the selection and use of Windows development tools.
comp.os.ms-windows.programmer.win32
Discussions about the Win32 (Windows NT/Win32s) programming interface.
comp.os.ms-windows.programmer.misc
All other discussions about Windows software development.
The following groups have been replaced by those shown above:
comp.windows.ms
comp.windows.ms.programmer
The following groups are NOT for Microsoft Windows!
comp.windows.misc
comp.windows.news
--------------------
2. What tools can I use to develop software for Windows?
>> There are a number of options, which are summarized below:
1. Use the Microsoft Windows SDK (Software Development Kit). This is
a necessity for heavy-duty application development. The SDK is
designed for Microsoft C/C++ 5.1/6.0/7.0 and Microsoft Macro
Assembler 5.1/6.0, but it is possible to use it with other compilers,
such as Zortech C++ (but not including some Borland compilers). If
you plan to use a non-Microsoft compiler, call Microsoft Technical
Support to obtain the free Supplemental Compiler Utilities disk.
The following compilers are currently known to work:
Compiler Earliest Current Notes (see below)
------------------------------- -------- ------- -----------------
- Borland C++ 2.0 3.1 SDK+D3, 3.1, QW
- Metaware High C 2.4 32-bit
- Microsoft C/C++ 5.1 7.0 SDK+D1, 3.1, QW
- Microsoft QuickC 2.0 2.0
- Microsoft QuickC for Windows 1.0 1.0 SDK+D2, QW
- Microway C # 32-bit
- Topspeed C #
- Turbo C++ for Windows 3.0 3.0 SDK+D2
- Watcom C 8.0 9.0 SDK+D
- Watcom C/386 8.0 9.0 32-bit, SDK+D
- Zortech C++ 2.06 3.0 32-bit, SDK+D
- Borland C++ 2.0 3.1 SDK+D3, 3.1, QW
- Glockenspiel C++ #
- Microsoft C/C++ 7.0 7.0 SDK+D1, 3.1, QW
- Topspeed C++ #
- Turbo C++ for Windows 3.0 3.0 SDK+D2
- Zortech C++ 2.06 3.0 32-bit, SDK+D, QW
- GFA Basic 1.0 1.0
- Microsoft Visual Basic 1.0 1.0 SDK+D4, 3.1, QW
- Realizer 1.0 1.0
- Microsoft Fortran 5.1 5.1 QW
- Watcom Fortran 8.1 9.0 QW
- Watcom Fortran/386 8.1 9.0 32-bit, QW
- Microsoft MASM 5.0 6.0
- Microsoft Pascal 4.0 4.0
- Topspeed Pascal #
- Turbo Pascal for Windows 1.0 1.0 SDK+D2, QW
- Logitech Modula-2 4.0
- Stonybrook Modula-2 2.0
- Topspeed Modula-2 2.01
- PDC Prolog 3.3
- Prolog/2 #
- Microsoft COBOL 4.5 4.5 SDK, QW
- MicroFocus COBOL 2.4
Notes:
32-bit Full 32-bit compiler with flat address space
3.1 API access includes new Windows 3.1 functionality
SDK Includes full access to Windows API
SDK+D As 'SDK', with full SDK manuals
SDK+D1 As 'SDK', with full SDK manuals (not with upgrade)
SDK+D2 As 'SDK', with limited SDK manuals
SDK+D3 As 'SDK', with limited SDK manuals (only with AF)
SDK+D4 As 'SDK', with limited SDK manuals (only with Prof. TK)
QW Includes libraries for easy porting of DOS applications
Most 'SDK' denoted products include online SDK documentation.
Applications written using Borland C++ may not run in Windows
3.0 Real Mode (due to linker restrictions).
Some of the languages that will *NOT* work are:
- Microsoft QuickPascal, Basic, QuickBasic
- Borland Turbo C, Turbo C++, Turbo Pascal, Turbo Basic
- Watcom Basic, Pascal
2. Use an integrated development environment. There are a number of
these systems available; the following summarizes the known ones:
a. Actor. $240 list ($500 for Actor Professional), free runtime.
An object-oriented programming environment, with C-like syntax.
It allows quick development of programs and/or prototypes, and
compiles into an "image" file (which can be combined into a
standalone executable .EXE file).
b. Smalltalk/V for Windows. $499 list, free runtime
An object-oriented programming environment, portable to OS/2 and
Macintosh.
c. Objectworks\Smalltalk for Windows. $3500 list, $? runtime.
An object-oriented programming environment, portable to Macintosh,
Open Look and Motif. Runtime license fees depend on quantity
required; prices range from $375 for one to below $100 for large
quantities. Educational discounts available.
d. KnowledgePro for Windows. $249 list, $? runtime.
e. Borland ObjectVision. $395 list.
A form-oriented environment. Lacks a "true" programming language.
Runtime package allows unlimited runtime distribution.
f. Asymetrix ToolBook. $395 list, $495 unlimited runtime.
A HyperCard-like environment, including hypertext capabilities.
Current version is quite slow. Includes a conversion utility
to create ToolBook books from HyperCard stacks. Author's
Resource Kit includes tools plus a runtime distribution license.
g. Spinnaker PLUS. $495 list, $495 runtime.
A Windows version of HyperCard, compatible with the Mac original.
At last report PLUS was incredibly slow on any normal system.
h. Windowcraft. $295 list, $? runtime.
A graphical object-oriented application generator, compatible
with Hypercard stacks.
i. Golden Common Lisp Developer. $1995 list, $200 (or less) runtime.
A Common Lisp-based object-oriented environment. Full access
to the Windows API.
j. ObjectView. $899 list, $? runtime.
Object-oriented system with graphics editor and SQL database
connectivity.
k. Liana. $495 list (professional), $125 list (personal).
Integrated object-oriented system with classes and inheritance.
More C-like language than Actor. Produces EXE files, but
requires DLL to be present for runtime.
3. Use W:CASE, WindowsMAKER, VZ Programmer, Winpro/3 or ProtoGen, all
of which generate C code for Windows. This will still require the
use of the SDK (or, in some cases, the use of BC++). There is also
available a shareware code generator UCB/WordPlan ,available on
ftp.cica.indiana.edu, but it's considerably more limited in functio-
nality than the commercial products. No runtime license fees.
5. Use EASEL/Windows. This is an MIS-oriented package intended for
development of client-server or cooperative processing applications.
3270 connectivity, SQL, DDE, and Windows --- all for mere $7500.
3. What linkers can be used for Windows programs?
>> You can use link 5.10 (or greater), included on the Microsoft C 5.1/6.0
compiler disks, and available separately with the Supplemental Compiler
Utilities diskette (free) from Microsoft. Other linkers that work for
Windows development are Optilink/Windows, Borland's tlink (with the
Borland-format object files) and Watcom's wlink.
4. What debuggers can I use for Windows development?
>> First of all, if you use an integrated package such as Actor, Smalltalk,
ToolBook or Visual Basic, you're limited to the debugging tools built
into those packages. If you are using C, C++ or another conventional
language with Windows SDK, you have several choices.
1. In real mode, you are limited to SYMDEB, which is pretty basic. It
also requires the use of a second monitor (monochrome for most
machines, 8514/A for MCA machines) or a serial terminal. SYMDEB
is included with the Windows SDK.
2. In standard mode, you can also use Codeview for Windows (CVW), which
is included with Windows SDK. The CVW, which is similar to the DOS
version of Codeview, included with the SDK requires a secondary
monitor; a serial terminal can not be used (a single-monitor version,
CVW 3.05, is included with Microsoft C 6.0ax and later, and is also
available separately from Microsoft). CVW is also included with
QuickC for Windows and Microsoft Fortran 5.1.
Microsoft C/C++ 7.0 includes CVW/1 (from Nu-Mega Technologies) which
allows CVW to run in a window. It is also available separately
(list price: $149) from Nu-Mega.
3. If you have a 386, you have an additional option of using WDEB386,
which provides some further debugging features over CVW, at the
expense of an antiquated user interface. WDEB386, which is included
with the SDK, will work either with a secondary monitor or a serial
terminal.
4. If you are using Borland C++, you can use TDW. TDW can do single-
screen debugging (not windowed, but screen-swapping), dual-monitor
debugging and remote (serial or NetBIOS) debugging.
You can also use TDW with Microsoft-compatible compilers if you
use Borland'(supplied) s tools to convert the symbolic information
to the Borland format first.
TDW's video support (when using single-screen debugging) is limited
to the following adapters and/or display modes:
CGA 640x200
Hercules 720x348
EGA 640x350
VGA 640x480
ATI VGA Wonder 640x480, 800x600
Tseng ET3000 640x480, 800x600, 1024x768
Tseng ET4000 640x480, 800x600, 1024x768
5. If you are using Zortech C++, you can use ZDBW. ZDBW can do single-
screen debugging (not windowed, but screen-swapping) with most display
drivers, and can also do dual-monitor debugging.
6. Metaware C includes MDB, another Windows-based debugger.
7. Watcom compilers include their own WVideoW debugger.
8. Logitech's MultiScope (list: $500) is a fully graphical debugger
available for both OS/2 and Windows.
9. Nu-Mega's Soft-ICE (list: $386) provides advanced debugging features,
and works with both standard and Borland-format symbolic information.
10. Periscope for Windows (list: $595) provides hardware debugging support for device driver development. It requires the use of a remote computer for debugging.
5. What word processor can I use to create RTF files for the Windows SDK
Help Compiler?
>> The following will create RTF files:
Ami Professional
JustWrite
Microsoft Works
Professional Write Plus
txt2rtf [shareware conversion tool]
Word for DOS
Word for Macintosh [Mac]
Word for Windows
Word for Windows, Working Model [limited file size]
WordPerfect for Windows
Wordstar for Windows
Wordstar Legacy
WriteNow [Mac, NeXT]
Xantippe [shareware hypertext tool]
You can also create them manually, as the RTF format is plain ASCII,
but this will very quickly get very awkward and very tedious. There
is a description of the RTF format on ftp.cica.indiana.edu (Xantippe
can also be found on cica).
Some conversion programs (including Doc-to-Doc) will also create RTF
files from other native word processor formats.
NOTE: RTF files created with Word for Windows are not always 100%
compatible with the SDK help compiler. Use the 3.0B help compiler
update (available at ftp.cica as hc30b.zip) to avoid these problems.
It is not yet known whether the 3.1 SDK has problem with Word for
Windows 2.0 RTF files.
7. What tools are available for SQL development under Windows?
>> The following products provide SQL interfaces:
ADI SQL for Windows [announced, not shipping]
db_VISTA III [read-only]
Gupta SQL
Novell Netware SQL [announced, not shipping]
Ocelot SQL for Windows [one-time $500 distribution royalty]
Paradox [requires Paradox SQL Link]
Progress [integrated package, portable, runtime fee]
Q+E [read-only]
Smalltalk\SQL [for Objectworks\Smalltalk]
SQL Server [includes DLL for Visual Basic]
XDB SQL C SDK
7. What C++ class libraries are available for Windows programming?
>> The following products provide C++ class libraries for Windows:
Product Company Compiler support
--------------------- --------------------- -------------------------
Commonview Glockenspiel Ltd. Borland, Zortech
C++/Views CNS, Inc. Borland, Zortech
JTW JT Software Zortech
MS Foundation Classes Microsoft Microsoft
ObjectGraphics WhiteWater Group Borland
ObjectWindows Borland Borland
Tier 1 Sturmer Hauss Corp. Borland, Zortech
Win++ Blaise Computing Borland
XVT++ XVT Inc. Borland, Zortech, Microsoft
The XVT++ library requires the use of the XVT toolkit. The Foundation
Classes are included with Microsoft C/C++ 7.0, and the ObjectWindows
Library is optional with the purchase of Borland C++ 3.0.
--------------------
8. What does Windows do with my extended memory? After I run Windows,
Norton SI reports that I don't have any extended memory. Is this
a bug?
>> No, it's not a bug. Windows requires applications to access extended
memory using a mechanism known as "XMS". This mechanism is implemented
in himem.sys. If you have device=himem.sys in your config.sys, the
first XMS call (by Windows or SmartDrive, for example) will transfer
control of the extended memory to himem.sys, and thus make it in-
accessible to non-XMS applications.
9. How can I take a snapshot of my Windows screen?
>> Simple -- just pres PrtScr, and Windows will copy the image to the
clipboard, from where you can paste it into your favourite application.
Using Alt-PrtScr will take a snapshot of only your current window.
--------------------
10. What do I need to develop device drivers for Windows?
>> You need to purchase the Windows Device Driver Kit (DDK). It's available
direct from Microsoft, and costs $500.
--------------------
11. How can I hide dialog box controls?
>> EnableWindow(GetDlgItem(hDlg, IDD_CONTROLTOHIDE), FALSE);
ShowWindow(GetDlgItem(hDlg, IDD_CONTROLTOHIDE), SW_HIDE);
UpdateWindow(GetDlgItem(hDlg, IDD_CONTROLTOHIDE));
12. How can I add pushbuttons and edit controls to a "normal" window which
is not a dialog box?
>> You can do this by simply calling CreateWindow() with one of the pre-
defined child window control class names (see table 4.2 in the SDK
reference manual).
13. Why does compiling a Windows application with emulator floating-point
cause corrupted code segments when running on a non-87 machine? And
should I use emulator or alternate floating-point math?
>> The emulated floating point tries to used the coprocessor. When it does
not find one on startup, it patches the code to use the software floating
point. Patching does however not adapt the code-segment checksum, thus
the windows debugging version chokes when it horridly founds that some-
thing terrible must have happened to the code. [This problem affects
only Real mode, and Windows 2.x.]
Get rid of it by setting 'EnableSegmentChecksum=0' in the [debug]
section of WIN.INI; the problem only affects debugging versions of
Windows.
The alternate math package is faster on non-x87 machines, but slower on
those equipped with a math chip. Depending on your application, you
might want to ship either, or both. Borland C++ does not support the
alternate math package, but it does have a "fast floats" option.
--------------------
14. How do I change the button colors?
>> In Windows 3.0, the button face is defined by two colors. The grey
(white if ega) face and a dark grey (grey if ega) shadow. The colors
also change when the button goes from a normal to pushed in state. The
WM_CTLCOLOR message only allows you to change one color at a time so to
which of the button face colors should this apply? (Windows 2 button
faces had only one color so it made sense.)
Maybe something tricky could have been done by using the background
color for the shadow and foreground color for the face and perhaps
doing something strange to get the text color in another way... And how
do you return 2 brushes (you now need a foreground and a background
brush)? Or maybe even better, make colors a property of the window and
some windows could have multiple color properties...
Anyway, Windows doesn't look at the WM_CTLCOLOR message for buttons and
thus doesn't allow you to change the button colors. Try it with a
listbox instead... The only way to change button colors is to specify
ButtonColor=, ButtonShadow= and ButtonText= in the [Colors] section of
your win.ini file.
15. Why should I not use large model in my Windows application? Can I do
it anyway?
>> Yes, you can do it. There are several problems with using large model,
though:
i. Your program's data memory will be fixed in real mode. Effectively,
your application will cripple any real-mode Windows system. [Of
course, this problem doesn't exist with Windows 3.1!]
ii. Your application will run more slowly, since all your data must be
accessed through far pointers.
iii.You may only be able to have one instance of your application
active at any one time. This restriction is imposed by Windows on
applications with multiple static data segements: in large model,
that means most applications generated with C or C++. Borland
C++ 3.0+ and Microsoft C/C++ 7.0 will attempt to keep your static
and global data in a single segment, so as long as that data does
not exceed 64K, you could run multiple instances of a large-model
application created using those compilers.
You should consider very carefully before you decide that large model
is the only way to go; the preferred method is to use medium model, and
to allocate far data as required.
Another alternative is to use Watcom C/386 or Zortech C++ for develop-
ment; this will let you use a single 4GB segment, and 32-bit registers,
increasing your applications performace substantially (but limiting it
to running in 386 enhanced mode).
Win32 (Windows NT and Win32s) will use the flat 32-bit programming model
exclusively for native applications.
16. I get errors linking fonts into a .FON file? What's the problem?
>> The linker provided with the Windows 3.0 SDK will produce the following
error when linking fonts:
Link Error L2049 no segments defined
The above LINK error is a bug in link. The fix is to run exehdr /r on the
.exe file, and then run rc on it. The Win3 SDK linker incorrectly detects
an error, and marks the resulting .exe file with some kind of error bit,
even though the rest of the exe file is ok. Exehdr /r will reset this
"error bit", after which rc will work just fine.
An alternate fix is to use link4 from Windows 2.x SDK.
17. Should I use GetStockObject( GCW_WHITEBRUSH ) for my window background?
>> Not unless you insist on a white background. It is preferable to use
the Control Panel-defined window background color instead:
WinClass.hbrBackground = COLOR_WINDOW + 1;
18. The SDK Guide to Programming says that I shouldn't subclass standard
edit controls. Why is this?
>> That's not strictly true. You can *subclass* them by having your own
window procedure handle the messages for the windows you create (using
SetWindowLong()). What is definitely a bad idea is modify the *class
procedure* of a standard control (using SetClassLong()) and changing the
window procedure for *all* such windows, as this will affect all edit
controls in all applications currently running in the Windows session.
19. Is it possible to change the palette entries for a VGA running in
16 color mode?
>> If you are using a standard driver, you will need to bypass Windows
to do it. Microsoft will tell you to buy the DDK, but there is
another way. Now, the Windows system palette maps onto the VGA
16-color palette as follows:
VGAPAL SYSPAL VGAPAL SYSPAL
00 00 08 07
01 01 09 13
02 02 10 14
03 03 11 15
04 04 12 16
05 05 13 17
06 06 14 18
07 12 15 19
#define syspal(n) (n<7 ? n : (n>8 ? n+4 : (n=7 ? 12 : 7)))
#define vgapal(n) (n<7 ? n : (n>12 ? n-4 : (n=7 ? 8 : 7)))
When you get a WM_SETFOCUS event, save the current state of the
hardware colormap and installs the one you want. When you get a
WM_KILLFOCUS event, restore the original palette. Don't use the
pallette registers directly, though, just modify the color registers
that they point to.
20. How can I allocate global memory that's owned by a DLL?
>> Basically, if you use GlobalAlloc in a DLL, the application that
called the DLL will own the object. There is a way around this,
though: allocate the memory using the GMEM_DDESHARE flag; this
will make the allocating code segment (rather than the current task)
own the memory.
21. How do I determine how much physical memory is installed, in order
not to cause swapping in 386 Enhanced mode?
You need to make a DPMI call to obtain that piece of information. DPMI
call 0500h with ES:DI pointing to a 30h byte buffer returns the `Free
Memory Information':
Offset Description
00h Largest available free block in bytes
04h Maximum unlocked page allocation
08h Maximum locked page allocation
0Ch Linear address space size in pages
10h Total number of unlocked pages
14h Number of free pages
18h Total number of physical pages
1Ch Free linear address space in pages
20h Size of paging file/partition in pages
24h-2Fh Reserved
The size of one page in bytes can be determined by function 0604h, which
returns the page size in bytes in BX:CX. To call a DPMI function, invoke
the interrupt 31h. Carry bit will be clear if call was successful.
The complete DPMI 0.9 specification is available free(!) at Intel Lite-
rature JP26, Santa Clara. It's also available on ftp.cica.indiana.edu.
22. How do I align columns in a listbox? The proportional font causes the
columns to be badly misaligned.
>> In the resource file make sure the list box has the LBS_USETABSTOPS style.
When you add the items to the listbox, separate the fields with tabs.
You can either use the default tab stops, or set your own by sending the
LBS_SETTABSTOPS message to the listbox. For more information, see SDK
Reference vol.1, page 6-44, and SDK Reference vol.2, page 8-43. It is
also possible to use a fixed font, but the tabstop solution usually
ends up looking much better.
23. How can I force a window to stay iconic? or to make it non-resizable?
>> In order to make your app stay as an icon, you must process the
WM_QUERYOPEN message. If you always return 0 for this message, you
indicate that the icon can not be opened into a ordinary window.
To retain a fixed size, you must process the WM_GETMINMAXINFO message.
When you get it, modify the info pointed to by lParam:
LPPOINT lpSize = (LPPOINT)lParam;
lpSize[3].x = lpSize[4].x = theRightWidth;
lpSize[3].y = lpSize[4].y = theRightHeight;
If you don't want the window to be maximized or iconized, create it
with the ~WS_MAXIMIZEBOX and/or ~WS_MINIMIZEBOX styles, and disable
those items from the system menu, if there is one. Also, you can
alternately disable resizing by creating the windows with ~WS_THICKFRAME,
and disabling the Size... item on the system menu.
24. How can I use \a to right-justify a menu entry at runtime?
>> It's undocumented, but what you need is a 0x08 in the menu string.
The easiest way to do this is to place a \b in the string before the
right-justified part (either the text of the accelerator key).
Incidentally, the Windows 3.0 CUA guidelines no longer call for right-
justifying the Help menu on the menu bar.
25. What does 'new()' really end up doing in C++?
>> In Borland C++ 2.0, and in 3.0's medium model, new() ends up calling
LocalAlloc(), allocating memory from your near 64K segment. In 3.0's
large and compact models, however, it will make one GlobalAlloc and do
subsegment allocations to allow you access to the full memory without
making excessive demands on the system limit of 4096 (8192 in 386 enhan-
ced mode) global memory handles.
26. How do you change directories under Windows ?
>> The easy way is to use DlgDirList(). You can specify zero for the
two ID fields. You can use the current window ID for the dialog handle
field. The standard C library function chdir() can also be used.
27. Is it possible to pass a structure back to Visual Basic from a DLL?
>> The following description is courtesy of Todd Ogasawara, 1991 (reachable
at todd@pinhead.pegasus.com). The code fragments were developed and
tested using Borland C++ 2.0 and Microsoft Visual Basic.
1. Define a type that is a pointer to a structure.
typedef struct {
long fsize; // file size in bytes
char ftime[25]; // last file access time string
} * fileStruct;
2. Sample function prototype declaration.
int FAR pascal FileInfo(char filename[], fileStruct);
3. Sample DLL C function that receives a filename in a char array from
Visual Basic and passes back file size (long) and file modification
date (char array) in a structure.
// Get file info (access time & size)
int FAR pascal
FileInfo(char filename[], fileStruct far fileinfo)
{
struct stat statbuf;
FILE *stream;
if (!(stream = fopen(filename, "r"))) {
return(-1); // ERROR: cannot find named file
} else {
fstat(fileno(stream), &statbuf);
fclose(stream);
}
fileinfo->fsize = statbuf.st_size; /* file size */
strcpy(fileinfo->ftime,ctime(&statbuf.st_ctime)); /* access time */
return(0);
}
4. Declare a Visual BASIC "user-defined type" (i.e., a "structure") that
matches the structure declared in the DLL C code. See pages 260-261
of the Microsoft Visual BASIC Programmer's Guide for more information
about user-defined types.
' type (structure) definition in GLOBAL.BAS
Type FileStruct
Fsize As Long
Ftime As String * 25
End Type
5. Declare the function in your GLOBAL.BAS (or whatever you named the file
you keep global information in). In this example a function is declared
since the DLL C function returns a -1 to indicate an error and a 0 to
indicate success. Note that the filename is passed from Visual BASIC
to the DLL C function by value (ByVal) while the data in the DLL C
structure is passed to Visual BASIC by reference (As). See pages 379-387
of the Microsoft Visual BASIC Programmer's Guide for more information
about declaring and calling DLL routines.
' declaration in GLOBAL.BAS
Declare Function FileInfo Lib "dosdll.dll" (ByVal FileName$,
FileInf As FileStruct) As Integer
6. Example of using the DLL function 'FileInfo' in Visual BASIC.
If (Myfile.Filename = "") Then
Exit Sub
Else
ThisFileName$ = UCase$(Myfile.Filename)
End If
FileStatus% = FileInfo(ThisFileName$, FileStat)
ThisFileSize$ = Format$(FileStat.Fsize, "###,###,###") + " bytes"
ThisFileStat$ = Left$(FileStat.Ftime, 24)
28. How can I find out how many instances of my application are running?
>>> nNumInsts = GetModuleUsage(hInstance);
29. Is it possible to create an initially invisible MDI child window?
>>> Before creating the child window,
SendMessage( hClientWindow, WM_SETREDRAW, 0, 0L);
Then, in your child window WM_CREATE processing,
ShowWindow( hChildWindow, SW_HIDE).
SendMessage( hClientWindow, WM_SETREDRAW, 1, 0L);
30. Why do I keep getting null dialog handles with Borland C++ unless I have
Turbo C++ running?
>>> Your dialog is probably of the "BorDlg" class, which requires code in
BWCC.DLL. However, you have probably not done anything to force BWCC.DLL
to be loaded with your application, so the dialog manager cannot find the
necessary routines to draw the dialog. The easiest way to force BWCC.DLL
to be loaded is to call BWCCGetVersion() at the very beginning of your
application, and to link in BWCC.LIB. Alternaly, you can do a
WinExec( "loadbwcc.exe" );
when you start up your application.
31. Does there exist a utility that will allow me to track down the resources
I am failing to free?
>>> There are several utilities available on ftp.cica.indiana.edu which will
monitor the heap and memory usage. Look for files ma.zip and ha.zip in
/pub/pc/win3/utils.
The Windows 3.1 debug kernel (included with the SDK) also checks for
unfreed resources when an application exits.
32. Can I get TDW (Turbo Debugger for Windows) to work with Windows 3.1?
What about Turbo Pascal for Windows?
>>> TDWIN31.ZIP and TPWN31.ZIP are now on wuarchive.wustl.edu in the directory
/mirrors/msdos/borland. The former includes a WINDEBUG.DLL for running
TDW in Windows 3.1, and the latter contains updates to TPW to take
advantage of the new Windows 3.1 features.
Borland expects to have full C++ and Turbo Pascal updates for Windows 3.1
available in the next few months.
33. Why can't I print floating-point numbers with wsprintf()?
>>> Because it was designed not to print them. To print floating-point,
you must use sprintf(). Remember, though, that all strings passed
to wsprintf() should be cast to FAR!
35. How do I implement drag-and-drop printing using File Manager and Print
Manager?
>> You will need to register your application in the registration database.
You can do this either using the Registration Editor, or the Reg* API
in Windows 3.1 SDK. One of the simplest mechanisms is that used by
several Windows 3.1 applets -- print a file is the parameters are
"/p filename". See the registration database for examples.
36. But what about generalized drag-and-drop?
>> You'll need SHELL.DLL, shipped with Windows 3.1.
- Either do DragAccept() or create the window as WS_EX_DROPFILES (0x10L)
- Wait for the WM_DROPFILES message (0x0233), which passes a handle to
something in wParam
- You can then issue
WORD DragQueryFile(hDrop, 0xffff, NULL, 0)
to get the file count, and then
WORD DragQueryFile(HANDLE hDrop, WORD nFile, LPSTR sDest, WORD max)
for each of the dropped files
- Once you have finished call
DragFinish( hDrop )
For Visual Basic, get the file DD.ZIP from CompuServe's MBASIC forum,
which lets you implement drag-and-drop from VB. This file may also be
available at ftp.cica.indiana.edu.
37. How can I automatically exit a dialog box if the user doesn't do anything?
>> Start a timer in WM_INITDIALOG. If your dialog box receives the WM_TIMER
message, kill the timer and post yourself a WM_COMMAND messgae with
wParam == IDOK. If the user presses any button, restart the timer.
38. How can you enumerate the icons in a Windows EXE or DLL if you don't
already know their names?
>> In Windows 3.1, this is easy. SHELL.DLL exports
HICON ExtractIcon(hInst, lpszExeName, nIcon)
This function returns a handle to the specified icon (where 0 is the
default icon displayed by Program Manager), or the number of icons in the
file if you pass in an index of -1.
Better yet, SHELL.DLL also exports the function:
FindExecutable(lpszFile, lpszDir, lpszResult)
which will give you the executable associated with a given document file.
You can then extract the appropriate icon from that file.
40. How do I extract useful information from an end user's Dr. Watson log
file?
>> The Dr. Watson log shows the contents of the registers when you appli-
cation crashed. Even if you can't use it to determine contents of the
variables, you can pinpoint the location of the crash.
Make sure you keep a copy of the .map file generated by the linker for
the version shipped to your customers; you can then look up the crash
location manually from this file when you receive a Dr. Watson log. If
you linked a version with /CO /LI, the .map file will also contain
line number information, allowing you to pinpoint the line in your
program.
41. Why does the Minimize button appear to move when I click it in a
modal dialog?
>> It's a bug in Windows 3.1. To duplicate this, create a modal dialog
with the styles CAPTION, MODAL FRAME, MINIMIZE-BOX, activate the dialog,
press the Minimze button -- and watch it move to the top right corner,
on top of the modal frame! The workaround: don't use a Minimize box
on a modal dialog...
--------------------
99. What books are there that I should be using for Windows programming?
>> First of all, if you don't have an SDK, you'll want the SDK docs:
Windows 3.1 SDK
---------------
Windows Programmer's Reference, Volume 1: Overview
Microsoft Press, 1992
Windows Programmer's Reference, Volume 2: Functions
Microsoft Press, 1992
Windows Programmer's Reference, Volume 3: Messages and structures
Microsoft Press, 1992
Windows Programmer's Reference, Volume 4: Resources
Microsoft Press, 1992
Windows Guide to Programming
Microsoft Press, 1992
Windows Programming Tools
Microsoft Press, 1992
Windows User Interface Guidelines
Microsoft Press, 1992
Windows Multimedia Programmer's Guide
Microsoft Press, 1992
Windows Multimedia Programmer's Reference
Microsoft Press, 1992
Windows for Pen Computing Programmer's Reference
Microsoft Press, 1992
Windows Setup Toolkit
Microsoft Press, 1992
Windows 3.0 SDK
---------------
SDK Reference, Volume 1: Functions and messages
Microsoft Press, 1990, part no. 06856
SDK Reference, Volume 2: Resource scripts and file formats
Microsoft Press, 1990, part no. 06857
SDK Guide to Programming
Microsoft Press, 1990, part no. 06854
SDK Tools
Microsoft Press, 1990, part no. 06854
SAA CUA Advanced Interface Design Guide
IBM, 1989, part no. SC26-4582-0
Win32 (Windows NT) API
----------------------
Win32 API: An Overview
Microsoft Press, 1992
Win32 Programmer's Reference, Volume 1: Overview, functions (A-O)
Microsoft Press, 1992
Win32 Programmer's Reference, Volume 2: Functions (P-Z)
Microsoft Press, 1992
User Interface Guidelines
-------------------------
Windows User Interface Guidelines [Windows 3.1, Windows NT]
Microsoft Press, 1992
SAA CUA Advanced Interface Design Guide [Windows 3.0, OS/2 1.x]
IBM, 1989, part no. SC26-4582-0
SAA CUA'91 Design Guide [OS/2 2.0]
IBM, 1991, part no. SC34-4289, $10.00
SAA CUA'91 Reference [OS/2 2.0]
IBM, 1991, part no. SC34-4290, $18.25
Third-party Books
-----------------
Charles Petzold: Programming Windows, 2e
Microsoft Press, 1990, ISBN 1-55615-264-7
Jeffrey M. Richter: Windows 3: A Developer's Guide
M&T Books, 1991, ISBN 1-55851-164-4
Daniel A. Norton: Writing Windows Device Drivers
Addison-Wesley, 1991, ISBN ?, $29.95
Peter Norton and Paul Yao: Windows 3.0 Power Programming Techniques
Bantam Books, 1991, ISBN ?, $29.95
Richard Wilton: Microsoft Windows 3 Developer's Workshop
Microsoft Press, 1991, ISBN ?, $24.95
--------------------
[ \tom haapanen "i don't even know what street canada is on" -- al capone ]
[ tomh@wes.on.ca "trust the programmer" -- ansi c standard ]
[ waterloo engineering software "to thine own self be true" -- hamlet ]
Technical Details
Message-ID:
<1992Aug27.125328.29945@wes.on.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watserv1!wes.on.ca!wes.on.ca!tomhShow Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.tools,comp.os.ms-windows.programmer.misc,comp.windows.ms.programmer,news.answers Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watserv1!wes.on.ca!wes.on.ca!tomh From: tomh@wes.on.ca (Tom Haapanen) Subject: comp.os.ms-windows.programmer FAQ (Frequently Asked Questions) Reply-To: tomh@wes.on.ca (Tom Haapanen) Organization: Waterloo Engineering Software Date: Thu, 27 Aug 1992 12:53:28 GMT Approved: news-answers-request@MIT.Edu Message-ID: <1992Aug27.125328.29945@wes.on.ca> Followup-To: comp.windows.ms.programmer Sender: tomh@wes.on.ca (Tom Haapanen) Lines: 964