campo-sirio/al/cpp_ui.pm/pmutil.cpp
alex 714dd74636 Archive Library versione 2.00
git-svn-id: svn://10.65.10.50/trunk@5350 c028cbd2-c16b-5b4b-a496-9718f37d4682
1997-10-09 16:09:54 +00:00

348 lines
8.4 KiB
C++
Executable File

//
// PMUTIL.CPP
//
// Source file for ArchiveLib 2.0
//
// Copyright (c) Greenleaf Software, Inc. 1994-1996
// All Rights Reserved
//
// CONTENTS
//
// TrimSystemMenu()
// CenterWindow()
// SetupSlider()
//
// DESCRIPTION
//
// This file contains a few utility routines specifically designed to
// work with PM.
//
// REVISION HISTORY
//
// February 14, 1996 2.0A : New release
#include "arclib.h"
#if !defined( AL_IBM )
#pragma hdrstop
#endif
#include <os2.h>
//
// NAME
//
// TrimSystemMenu()
//
// PLATFORMS/ENVIRONMENTS
//
// PM
// C++ C
//
// SHORT DESCRIPTION
//
// Trim most of the options from the system menu.
//
// C++ SYNOPSIS
//
// #include "arclib.h"
// #include "pmutil.h"
//
// extern "C" void TrimSystemMenu( HWND hwnd );
//
// C SYNOPSIS
//
// #include "arclib.h"
// #include "ppmmon.h"
//
// void TrimSystemMenu( HWND hwnd );
//
// VB SYNOPSIS
//
// None, VB doesn't work under OS/2.
//
// DELPHI SYNOPSIS
//
// None, Delphi doesn't work under OS/2.
//
// ARGUMENTS
//
// hwnd : The handle of the window whose system menu needs to be trimmed.
//
// DESCRIPTION
//
// This is a handy function for removing some of the clutter from
// the system menu. I use this for "about" boxes. It removes all of
// the default entry menu items, except for the Close and Move options.
//
// RETURNS
//
// Nothing.
//
// EXAMPLE
//
// SEE ALSO
//
// REVISION HISTORY
//
// February 14, 1996 2.0A : New release
//
extern "C" AL_LINKAGE void AL_FUNCTION
TrimSystemMenu( HWND hwnd ) /* Tag public function */
{
HWND hwndSysMenu;
MENUITEM mi;
int MenuID;
SHORT PresentItem = 0;
INT NumberOfItems;
hwndSysMenu = WinWindowFromID( hwnd, FID_SYSMENU );
WinSendMsg( hwndSysMenu,
MM_QUERYITEM,
MPFROM2SHORT( SC_SYSMENU, FALSE ),
(MPARAM) &mi );
NumberOfItems = (INT) WinSendMsg( mi.hwndSubMenu,
MM_QUERYITEMCOUNT,
0,
0 );
while ( NumberOfItems-- ) {
MenuID = (int) WinSendMsg( mi.hwndSubMenu,
MM_ITEMIDFROMPOSITION,
MPFROM2SHORT( PresentItem, TRUE ),
0 );
switch ( MenuID ) {
case SC_CLOSE :
case SC_MOVE :
PresentItem++;
break;
default :
WinSendMsg( mi.hwndSubMenu,
MM_DELETEITEM,
MPFROM2SHORT( (short) MenuID, TRUE ),
0 );
}
}
}
//
// NAME
//
// CenterWindow()
//
// PLATFORMS/ENVIRONMENTS
//
// PM
// C++ C
//
// SHORT DESCRIPTION
//
// Center a window on the screen.
//
// C++ SYNOPSIS
//
// #include "arclib.h"
// #include "pmutil.h"
//
// extern "C" void CenterWindow( HWND hwnd );
//
// C SYNOPSIS
//
// #include "arclib.h"
// #include "ppmmon.h"
//
// void CenterWindow( HWND hwnd );
//
// VB SYNOPSIS
//
// None, VB doesn't work under OS/2.
//
// DELPHI SYNOPSIS
//
// None, Delphi doesn't work under OS/2.
//
// ARGUMENTS
//
// hwnd : The handle of the window to be centered.
//
// DESCRIPTION
//
// Want to center a Window on the screen under OS/2? This does it.
//
// RETURNS
//
// Nothing.
//
// EXAMPLE
//
// SEE ALSO
//
// REVISION HISTORY
//
// February 14, 1996 2.0A : New release
//
extern "C" AL_LINKAGE void AL_FUNCTION
CenterWindow( HWND hwnd ) /* Tag public function */
{
SWP swp;
int width = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
int height = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
WinQueryWindowPos( hwnd, &swp );
swp.x = ( width / 2 ) - ( swp.cx / 2 );
swp.y = ( height / 2 ) - ( swp.cy / 2 );
WinSetWindowPos( hwnd,
0,
swp.x,
swp.y,
swp.cx,
swp.cy,
SWP_SHOW | SWP_MOVE );
}
//
// NAME
//
// SetupSlider();
//
// PLATFORMS/ENVIRONMENTS
//
// PM
// C++ C
//
// SHORT DESCRIPTION
//
// Dink with a slider control to optimize it as a monitor.
//
// C++ SYNOPSIS
//
// #include "arclib.h"
// #include "pmutil.h"
//
// extern "C" int SetupSlider( HWND hDlg, int slider_id, int draw_ticks );
//
// C SYNOPSIS
//
// #include "arclib.h"
// #include "util.h"
//
// int SetupSlider( HWND hDlg, int slider_id, int draw_ticks );
//
// VB SYNOPSIS
//
// None, VB doesn't work under OS/2.
//
// DELPHI SYNOPSIS
//
// None, Delphi doesn't work under OS/2.
//
// ARGUMENTS
//
// hDlg : If slider_id is equal to -1, this argument is the
// window handle for the slider control. If slider_id
// is soemthing else, this is assumed to be a dialog
// box handle that contains the slider control.
//
// slider_id : The dialog ID of the slider control, or -1 if hDlg
// contains the actual handle of the slider control.
//
// draw_ticks : A boolean flag indicating whether or not this routine
// should draw tick marks on the slider control.
//
// DESCRIPTION
//
// If you are going to use a slider control as a monitor, this routine
// will do a few things that help make it look better. First, we modify
// the slider so it has 10 intervals. The progress meter will then tick
// along from 0 to 10 until the whole deal is done. Next, the shaft of
// the slider is widened to 20 pixels, up from the default of 5 (I think.)
//
// Finally, I draw a set of tick marks along the slider, if requested. Note
// that you really need to make the slider control wide to accomodate ticks.
// User your resource editor to look at the sliders in the OS/2 examples
// for an idea of how wide I mean. I also pin the shaft agains the bottom
// or right hand side of the slider, so there is room for tick marks in
// the upper or left hand side.
//
// RETURNS
//
// 1 if things went well, 0 if they didn't.
//
// EXAMPLE
//
// SEE ALSO
//
// REVISION HISTORY
//
// November 13, 1995 2.00A : First release.
//
extern "C" AL_LINKAGE int AL_FUNCTION
SetupSlider( HWND hDlg, int slider_id, int draw_ticks ) /* Tag public function */
{
HWND hwnd;
if ( slider_id == -1 )
hwnd = hDlg;
else
hwnd = WinWindowFromID( hDlg, slider_id );
if ( hwnd == 0 )
return 0;
WNDPARAMS wndp;
SLDCDATA sldc;
wndp.fsStatus = WPM_CTLDATA;
wndp.pCtlData = (PVOID) &sldc;
wndp.cbCtlData = sizeof( sldc );
MRESULT ret = WinSendMsg( hwnd, WM_QUERYWINDOWPARAMS, MPFROMP( &wndp ), MPFROMSHORT( 0 ) );
if ( ret == 0 )
return 0;
int pixels = ( sldc.usScale1Increments - 1 ) * sldc.usScale1Spacing;
sldc.usScale1Increments = 11;
sldc.usScale1Spacing = (USHORT)( pixels / 10 );
wndp.fsStatus = WPM_CTLDATA;
wndp.pCtlData = (PVOID) &sldc;
wndp.cbCtlData = sizeof( sldc );
ret = WinSendMsg( hwnd, WM_SETWINDOWPARAMS, MPFROMP( &wndp ), MPFROMSHORT( 0 ) );
if ( ret == 0 )
return 0;
WinSendMsg( hwnd,
SLM_SETSLIDERINFO,
MPFROM2SHORT( SMA_SHAFTDIMENSIONS, 0 ),
MPFROMSHORT( 20 ) );
if ( !draw_ticks )
return 1;
int j;
for ( j = 0 ; j < sldc.usScale1Increments ; j += 1 )
WinSendMsg( hwnd,
SLM_SETTICKSIZE,
MPFROM2SHORT( j, 5 ),
0 );
WinSendMsg( hwnd,
SLM_SETSCALETEXT,
MPFROMSHORT( 0 ),
MPFROMP( "0%" ) );
WinSendMsg( hwnd,
SLM_SETTICKSIZE,
MPFROM2SHORT( 0, 10 ),
0 );
WinSendMsg( hwnd,
SLM_SETSCALETEXT,
MPFROMSHORT( (j - 1) / 2 ),
MPFROMP( "50%" ) );
WinSendMsg( hwnd,
SLM_SETTICKSIZE,
MPFROM2SHORT( ( j - 1 ) / 2, 10 ),
0 );
WinSendMsg( hwnd,
SLM_SETSCALETEXT,
MPFROMSHORT( j - 1 ),
MPFROMP( "100%" ) );
WinSendMsg( hwnd,
SLM_SETTICKSIZE,
MPFROM2SHORT( j - 1, 10 ),
0 );
return 1;
}