SWAGOLX.EXE (c) 1993 GDSOFT ALL RIGHTS RESERVED 00007 WINDOWS & OS2 STUFF 1 05-28-9314:10ALL GREG ESTABROOKS DETCWIN.PAS IMPORT 13 KxO { GREG ESTABROOKS }ππProgram Win3XInf; { Simple Detection routines For Windows 3.X }π { Last Updated March 3/93, Greg Estabrooks }πUsesπ Crt,π Dos;ππVarπ Regs : Registers; { to hold register info }ππFunction Win3X : Boolean;π{ Routine to determine if Windows is currently running }πbeginπ Regs.AX := $4680; { Win 3.x Standard check }π Intr($2F, Regs); { Call Int 2F }π if Regs.AX <> 0 then { if AX = 0 Win in Real mode }π begin { else check For enhanced mode }π Regs.AX := $1600; { Win 3.x Enhanced check }π Intr($2F, Regs); { Call Int 2F }π if Regs.AL in [$00,$80,$01,$FF] then { Check returned value }π Win3X := False { Nope not installed }π elseπ Win3X := True; { Ya it is }π endπ elseπ Win3X := True; { Return True }πend;πππFunction WinVer :Word;π{ Returns a Word containing the version of Win Running }π{ Should only be used after checking For Win installed }π{ Or value returned will be meaningless }πbeginπ Regs.AX := $1600; { Enhanced mode check }π Intr($2F, Regs); { Call Int 2F }π WinVer := Regs.AX; { Return proper value }πend;πππbeginπ ClrScr;π if Win3X thenπ beginπ Writeln('Windows is Running! '); { Display version }π Writeln('Version Running is : ', Lo(WinVer), '.', Hi(WinVer));π endπ elseπ Writeln('Windows is not Running!');πend.π 2 05-28-9314:10ALL GREGORY P. SMITH OS2CHECK.PAS IMPORT 34 Kx»π {πAuthor : GREGORY P. SMITHππ> Is there any way to detect OS/2 (in a Dos box) sessions and Windowsπ> Sessions? I'd like to throw in support For these multitaskers so I canπ> run an idlekey Program.ππActual code is always the best example For me.. Look at this Unit (and useπit, I think you'll like it). Check With someone else if you want toπspecifically detect winslows. This Unit will, however, give up time to anyπmultitasker.π}ππ(* Public Domain Unit by Gregory P. Smith, No Rights Reserved *)π(* ... This also means no guarantees ... *)ππUnit OS_Test; { DESQview, OS/2, & 386 v86 machine Interfaces }ππ{$X+,S-,R-,F-,O-,D-,G-} { extended syntax, nothing else }ππInterfaceππConstπ In_DV : Boolean = False; { are we in DESQview? }π In_VM : Boolean = False; { are we in a 386+ virtual machine? }π In_OS2 : Boolean = False; { are we in OS/2? }ππFunction OS2_GetVersion: Word; { Get OS/2 version # }πFunction DV_GetVersion: Word; { update In_DV and get version # }πFunction DV_Get_Video_Buffer(vseg:Word): Word; { get the alt video buffer }πProcedure DV_Pause; { give up time slice }πProcedure MT_Pause; Inline($cd/$28); { give up time in most multitaskers }πProcedure KillTime; { Release time in any situation }πProcedure DV_begin_Critical; { don't slice away }π Inline($b8/$1b/$10/$cd/$15);πProcedure DV_end_Critical; { allow slicing again }π Inline($b8/$1c/$10/$cd/$15);πProcedure DV_Sound(freq,dur:Integer); { Create a Sound in the Bkg }ππImplementationππFunction OS2_GetVersion: Word; Assembler;πAsmπ MOV AH, 30h { Dos Get Version Call }π INT 21h { AL = major version * 10, AH = minor version }π MOV BH, AH { save minor version }π xor AH, AHπ MOV CL, 10π div CL { divide by 10 to get the major version }π MOV AH, BH { restore minor version }π XCHG AH, AL { AH = major, AL = minor }πend;ππFunction DV_GetVersion: Word; Assembler;πAsmπ MOV CX,'DE' { CX+DX to 'DESQ' (invalid date) }π MOV DX,'SQ'π MOV AX,02B01H { Dos' set date funct. }π INT 21H { call Dos }π CMP AL,0FFH { Was it invalid? }π JE @No_dv { yep, no dv }π MOV AX,BX { AH=major AL=minor }π MOV In_DV,1 { Set In_DV flag }π JMP @DvGv_x { other routines }π @No_dv:π xor AX,AX { Return 0 or no DV }π @DvGv_x:πend; { DV_GetVersion }ππFunction DV_Get_Video_Buffer(vseg:Word): Word; Assembler;πAsm { Modified by Scott Samet April 1992 }π CALL DV_GetVersion { Returns AX=0 if not in DV }π MOV ES,vseg { Put current segment into ES }π TEST AX,AX { In DV? }π JZ @DVGVB_X { Jump if not }π MOV AH,0FEH { DV's get video buffer Function }π INT 10H { Returns ES:DI of alt buffer }π @DVGVB_X:π MOV AX,ES { Return video buffer }πend; { DV_Get_Video_Buffer }ππProcedure DV_Pause;πbeginπ if In_DV thenπ Asmπ MOV AX, 1000h { pause Function }π INT 15hπ end;πend; { DV_Pause }ππProcedure KillTime;πbeginπ if In_VM thenπ Asmπ MOV AX, 1680h { give up VM time slice }π INT 2Fhπ endπ elseπ if In_DV thenπ Asmπ MOV AX, 1000h { DV pause call }π INT 15hπ endπ elseπ MT_Pause; { Dos Idle call }πend;ππ(* Procedure DV_begin_Critical; Assembler;πAsmπ MOV AX,$101B { DV begin critical Function }π INT 15hπend; { DV_begin_Critical }ππProcedure DV_end_Critical; Assembler;πAsmπ MOV AX,$101C { DV end critical Function }π INT 15hπend; { DV_end_Critical } *)ππProcedure DV_Sound(freq,dur:Integer); Assembler; { Sound a tone }πAsmπ MOV AX,1019Hπ MOV BX,freq { frequency above 20 Hz }π MOV CX,dur { duration in clock ticks }π INT 15Hπend;ππ{ ** -- initalization -- ** }ππbeginπ DV_GetVersion; { discard answer. Just update In_DV }π Asmπ MOV AX, 1680hπ INT 2Fh { Gives up time slice in most 386+ virtual machines }π not AL { AL = 00h if supported, remains 80h if not }π MOV CL, 7π SHR AL, CL { move bit 7 to bit 0 For a Boolean }π MOV In_VM, AL { update the flag }π end;π In_OS2 := (OS2_GetVersion >= $0100); { version 1.0 or greater }πend.ππ 3 05-28-9314:10ALL SWAG SUPPORT TEAM WINCHECK.PAS IMPORT 6 Kxτn {π>How can I check from my Dos Program that Windows are running inπ>the background?π}ππUnit Chk4Win;ππInterfaceππTypeπ Win3ModeType = (NoWin, RealStd, Enhanced);ππFunction CheckForWin3 : Win3ModeType;ππImplementationππFunction CheckForWin3 : Win3ModeType; Assembler;πAsmπ mov ax,1600hπ int 2Fhπ cmp al,1π jbe @@CheckRealStdπ cmp al,80hπ jae @@CheckRealStdπ mov al,2π jmp @@ExitPointπ@@CheckRealStd:π mov ax,4680hπ int 2Fhπ or ax,axπ jnz @@notWinπ mov al,1π jmp @@ExitPointπ@@notWin:π xor al,alπ@@ExitPoint:πend;ππend.π 4 05-28-9314:10ALL SWAG SUPPORT TEAM WINICONS.PAS IMPORT 24 Kx£ {π I am writing a Dos based Program in Turbo Pascal 6.0 that Uses aπ GUI Interface. My problem is that I would like to be able to importπ Windows or OS/2 icons to use instead of making my own. Does anyoneπ know the File Format For either of these Files or better yet haveπ source code For displaying them. Any help would be greatly appreciated.ππThe following code is a Unit I wrote to handle Windows icon Files. Iπdon't have the code yet For OS/2 icon Files, although I believe they areπquite similar. As Far as displaying the icons, just pass a Pointerπto the icon to your Graphics routines and let them decode and displayπthe structures. You should also be able to use a subset of theπstructures to decode icons embedded in Windows .EXE Files.ππAt offset $24 in the "new executable" header For Windows and OS/2 .EXEπFiles is a Word Variable that specifies an additional offset to theπresource table.π}ππUnit WinIcons;ππ(********************************)Interface(*********************************)ππTypeπ tBMPInfoHdr = Recordπ vHdrSize, (* Always 40 For Windows icons *)π vPixelWidth,π vPixelHeight : LongInt;π vColorPlanes, (* Should always be 1 *)π vBitCount : Word;π vCompression,π vImageSize,π vXPelsPerMeter,π vYPelsPerMeter,π vClrUsed,π vClrImportant : LongInt;π end;ππ tWinIconColor = Recordπ vBlue,π vGreen,π vRed,π vUnused : Byte;π end;ππ tRGBTable = Array[0..15] of tWinIconColor;ππ txorMask = Array[0..511] of Byte;ππ tandMask = Array[0..127] of Byte;ππ tWinIcon = Record (* The icon itself *)π vBMPInfoHdr : tBMPInfoHdr;π vRGBTable : tRGBTable;π vxorMask : txorMask;π vandMask : tandMask;π end;ππ tWinIconDirEntry = Record (* Icon File directory entry. *)π vIconWidth, (* 1 For each icon in the File *)π vIconHeight,π vColorCount,π vReserved : Byte;π vPlanes,π vBitCount : Word;π vBytesInRes,π vImageoffset : LongInt;π end;ππ (* The following two Arrays have to be sized at run-time as they can *)π (* hold up to 65,535 entries. The actual number of entries is set by *)π (* vIdCount. When reading an icon File, read in the vIdCount Variable *)π (* and then use GetMem to allocate the correct amount of heap. *)ππ tDirListPtr = ^tDirList;π tDirList = Array[1..1] of tWinIconDirEntry;ππ tIconListPtr = ^tIconList;π tIconList = Array[1..1] of tWinIcon;ππ tWinIconFileRec = Recordπ vIdReserved,π vIdType,π vIdCount : Word;π vDirList : tDirListPtr;π vIconList : tIconListPtr;π end;πππ tWinIconFile = File of tWinIconFileRec;ππVarπ vWinIconFile : tWinIconFile; (* Hook to access icon Files *)ππ(******************************)Implementation(******************************)ππend.π 5 08-27-9321:43ALL MICHAEL VINCZE Window painting IMPORT 24 Kx {πmichael a vinczeππBelow I have re-written your Paint method. It is commented where I made theπchanges. Get in touch with me if you have any questions.π}ππprocedure TNumConWindow.Paint(PaintDC : HDC; var PaintInfo : TPaintStruct);πvarπ X, Y : Integer;π WRect : TRect;π DeltaX,π DeltaY,π XSize,π YSize : Integer;π Perc : Real;π Str : string;π PC : PChar;π PCP : Integer;π SaveBK : LongInt;π ThePen : HPen;π TheBrush: HBrush;π TheRect : TRect;ππconstπ CP = 1;π NumLic = 64;π MaxCount = 6;π Count : array [1..MaxCount] of Integer = (2, 4, 8, 16, 32, 64);π OutStr : string = 'Hello Allen E. Stoner ';ππbeginπ GetClientRect(HWindow, WRect);π XSize := WRect.Right - WRect.Left;π YSize := WRect.Bottom - WRect.Top - 40;ππ Perc := YSize / (NumLic * 1.05);π DeltaY := Round(Perc * 10);ππ { Draw fat line at bottom of graph. The color is the system default. }π MoveTo(PaintDC, 0, YSize);π LineTo(PaintDC, XSize, YSize);π MoveTo(PaintDC, 0, YSize + 1);π LineTo(PaintDC, XSize, YSize + 1);π MoveTo(PaintDC, 0, YSize + 2);π LineTo(PaintDC, XSize, YSize + 2);ππ { Draw horizontal lines. The color is the system default. }π Y := YSize;π while Y > 0 doπ beginπ Rectangle(PaintDC, 0, Y, XSize, Y - DeltaY);π Y := Y - (DeltaY * 2);π end;ππ { Fill in rectangle at bottom yellow. This is the same size as WRectπ except the top is at YSize + 3. }π TheBrush := CreateSolidBrush(RGB($FF, $FF, $00));π CopyRect(TheRect, WRect);π TheRect.Top := YSize + 3;π FillRect(PaintDC, TheRect, TheBrush);ππ { Draw vertical lines red. If you wanted to, you could draw rectanglesπ instead of lines. Notice how I've selected a width of 4 for ThePen.π You could also have a different color for each "bar" by having X indexπ into an array of TColorRefs and changing ThePen for each new value of X.}π ThePen := CreatePen(PS_SOLID, 4, RGB($FF, $00, $00));π SelectObject(PaintDC, ThePen);π for X := 1 to MaxCount doπ beginπ MoveTo(PaintDC, X * 10, YSize);π LineTo(PaintDC, X * 10, Round(YSize - (Count[X] * Perc)));π end;ππ if CP = 1 thenπ PCP := 300π elseπ PCP := CP - 1;π PC := @OutStr[1];ππ { Set the color of the text. Note GetSysColor is used merely as an example.π Don't forget that the background of the text must also be colored. Thisπ color should be yellow, as in TheBrush, however a different color wasπ selected for illustration purposes. Alternatively SetBkMode() couldπ be used }π SetTextColor(PaintDC, GetSysColor(COLOR_HIGHLIGHT));π SetBkColor(PaintDC, RGB($00, $FF, $FF));π { Use SetBkMode () instead of SetBkColor () to see what happens.π SetBkMode (PaintDC, TRANSPARENT); }ππ TextOut(PaintDC, 10, YSize+15, PC, Length(OutStr)-1);ππ { Don't forget to delete the selected objects. }π DeleteObject(ThePen);π DeleteObject(TheBrush);πend;π 6 08-27-9322:10ALL MICHAEL VINCZE Window Fonts IMPORT 19 Kx {πMICHAEL A VINCZEππBelow is an example I whipped up that shows how to vary the font in an edit control.πThe method can be extended to other controls as well. Two methods are presented:πusing a stock object to get a fixed font, and using a created font.ππI have not figured out how to get the colors to change though.π}ππprogram Font_Ctl;ππusesπ Win31, WinTypes, WinProcs,π Objects, OWindows, ODialogs;ππconstπ ApplicationName : PChar = 'Font_Ctl';ππ id_Edit1 = 201;π id_Edit2 = 202;π id_Edit3 = 203;ππtypeπ TFont_CtlApplication = object (TApplication)π procedure InitMainWindow; virtual;π end;ππ PFont_CtlWindow = ^TFont_CtlWindow;π TFont_CtlWindow = object (TWindow)π EditBox : PEdit;π VarFont : HFont;π FixFont : THandle;ππ constructor Init(AParent : PWindowsObject; ATitle : PChar);π procedure SetupWindow; virtual;π destructor Done; virtual;π end;ππprocedure TFont_CtlApplication.InitMainWindow;πbeginπ MainWindow := New(PFont_CtlWindow, Init(nil, ApplicationName));πend;ππconstructor TFont_CtlWindow.Init(AParent : PWindowsObject; ATitle : PChar);πbeginπ inherited Init(AParent, ATitle);π EditBox := New(PEdit, Init (@Self, id_Edit1, 'EditBox 1 (normal)',π 10, 10, 500, 30, $FF, False));π EditBox := New(PEdit, Init (@Self, id_Edit2, 'EditBox 2 (fixed font)',π 10, 50, 500, 30, $FF, False));π EditBox := New(PEdit, Init (@Self, id_Edit3, 'EditBox 3 (variable font)',π 10, 90, 500, 30, $FF, False));π FixFont := GetStockObject (System_Fixed_Font);ππ VarFont := CreateFont(20, 20, 0, 0, fw_DontCare, 0, 0, 0,π Default_CharSet, Out_Default_Precis,π Clip_Default_Precis, Default_Quality,π Variable_Pitch or ff_DontCare, nil);πend;ππdestructor TFont_CtlWindow.Done;πbeginπ inherited Done;π DeleteObject(VarFont);πend;ππprocedure TFont_CtlWindow.SetupWindow;πbeginπ inherited SetupWindow;π SendMessage(GetDlgItem (HWindow, id_Edit2), wm_SetFont, FixFont, 1);π SendMessage(GetDlgItem (HWindow, id_Edit3), wm_SetFont, VarFont, 1);πend;ππvarπ Application : TFont_CtlApplication;ππbeginπ Application.Init (ApplicationName);π Application.Run;π Application.Done;πend.π 7 08-27-9322:10ALL SCOTT SAMET "About" box in Windows IMPORT 15 Kx {πSCOTT SAMETππ> I have a program that is always an icon, but I want to add an "about"π> command to it, to display a dialog box with info on the author andπ> the program. Anyone know how to do this or where info on it can be found?ππAll system menu commands, even those you add, are returned as wm_SysCommandπmessages. You need to check wParam to see if it's one of yours, and if not,πpass it to DefWndProc.π}ππUsesπ OWindows, WinProcs, WinTypes;ππConstπ cm_About = 100;ππTypeπ TMyApp = Object(TApplication)π Procedure InitMainWindow; Virtual;π end;ππ PMyWin = ^TMyWin;π TMyWin = Object(TWindow)π Procedure SetupWindow; Virtual;π Procedure wmSysCommand(Var Msg : TMessage);π virtual wm_First + wm_SysCommand;π Procedure wmQueryOpen(Var Msg : TMessage);π virtual wm_First + wm_QueryOpen;π end;ππProcedure TMyApp.InitMainWindow;πBeginπ MainWindow := New(PMyWin, Init (Nil, 'Test Window'));π { This gives the window a system menu with Move, Switch and Close }π PWindow(MainWindow)^.Attr.Style := ws_Overlapped or ws_Sysmenu;πend;ππProcedure TMyWin.SetupWindow;πVarπ SysMenu: hMenu;πBeginπ SysMenu := GetSystemMenu(hWindow, False);π AppendMenu(SysMenu, mf_Separator, 0, Nil);π AppendMenu(SysMenu, mf_String, cm_About, '&About');πend;ππProcedure TMyWin.wmQueryOpen(Var Msg : TMessage);πBeginπ { This keeps the window an icon at all times }π Msg.Result := 0;πend;ππProcedure TMyWin.wmSysCommand(Var Msg : TMessage);πBeginπ Case Msg.wParam ofπ cm_About :π MessageBox(hWindow, 'About Text', 'About Box', mb_ok)π Elseπ DefWndProc (Msg);π end;πend;ππVarπ App: TMyApp;πBeginπ CmdShow := sw_ShowMinimized;π App.Init ('Test');π App.Run;π App.Done;πend.π