wpi_win.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 473 行 · 第 1/2 页

C
473
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <stdlib.h>

#include "windows.h"
#include "wpi.h"

void _wpi_getbitmapdim( HBITMAP bmp, int *pwidth, int *pheight )
/**********************************************************************/
{
    BITMAP              bmp_info;

    GetObject( bmp, sizeof( BITMAP ), (LPSTR)&bmp_info );
    *pwidth = bmp_info.bmWidth;
    *pheight = bmp_info.bmHeight;
} /* _wpi_getbitmapdim */

void _wpi_getpaintrect( PAINTSTRUCT *ps, WPI_RECT *rect )
/**********************************************************************/
{
    rect->left = ps->rcPaint.left;
    rect->top = ps->rcPaint.top;
    rect->right = ps->rcPaint.right;
    rect->bottom = ps->rcPaint.bottom;
} /* _wpi_getpaintrect */

void _wpi_preparemono( WPI_PRES hdc, WPI_COLOUR colour, WPI_COLOUR back_colour )
/**********************************************************************/
/* This is necessary for bltting a monochrome bitmap.  The colour     */
/* parameter should be the colour of the 0's on the bitmap (normally  */
/* black).  The back_colour parameter should be the colour of the 1's */
/* on the bitmap (normally white)                                     */
{
    SetBkColor( hdc, back_colour );
    SetTextColor( hdc, colour );
} /* _wpi_preparemono */

void _wpi_setpoint( WPI_POINT *pt, int x, int y )
/**********************************************************************/
{
    pt->x = (LONG)x;
    pt->y = (LONG)y;
} /* _wpi_setpoint */

WPI_PROC _wpi_subclasswindow( HWND hwnd, WPI_PROC new )
{
    WPI_PROC    old;
    old = ( WPI_PROC ) _wpi_getwindowlong( hwnd, GWL_WNDPROC );
    _wpi_setwindowlong( hwnd, GWL_WNDPROC, (LONG)new );
    return( old );
}

BOOL _wpi_insertmenu( HMENU hmenu, unsigned pos, unsigned menu_flags,
                      unsigned attr_flags, unsigned id,
                      HMENU popup, char *text, BOOL by_position )
{
    if( !hmenu ) {
        return( FALSE );
    }

    menu_flags |= ( by_position ? MF_BYPOSITION : MF_BYCOMMAND );

    return( InsertMenu( hmenu, pos, menu_flags | attr_flags,
                        ( (menu_flags & MF_POPUP) ? (UINT)popup : (UINT)id ),
                        text ) );
}

BOOL _wpi_appendmenu( HMENU hmenu, unsigned menu_flags,
                      unsigned attr_flags, unsigned id,
                      HMENU popup, char *text )
{
    return( AppendMenu( hmenu, menu_flags | attr_flags | MF_BYPOSITION,
                        ( (menu_flags & MF_POPUP) ? (UINT)popup : (UINT)id ),
                        text ) );
}

BOOL _wpi_getmenustate( HMENU hmenu, unsigned id, WPI_MENUSTATE *state,
                        BOOL by_position )
{
    if( !hmenu || !state ) {
        return( FALSE );
    }
    *state = GetMenuState( hmenu, id, (by_position ? MF_BYPOSITION : MF_BYCOMMAND) );
    return( *state != (unsigned short)-1 );
}

void _wpi_getmenuflagsfromstate( WPI_MENUSTATE *state, unsigned *menu_flags,
                                 unsigned *attr_flags )
{
    *menu_flags = (unsigned)(*state);
    *attr_flags = 0;
}

BOOL _wpi_modifymenu( HMENU hmenu, unsigned pos, unsigned menu_flags,
                      unsigned attr_flags, unsigned new_id,
                      HMENU new_popup, char *new_text, BOOL by_position )
{
    if( !hmenu ) {
        return( FALSE );
    }

    menu_flags |= (by_position ? MF_BYPOSITION : MF_BYCOMMAND);

    return( ModifyMenu( hmenu, pos, menu_flags | attr_flags,
                        ( (menu_flags & MF_POPUP) ? (UINT)new_popup : (UINT)new_id ),
                        new_text ) );
}

BOOL _wpi_setmenutext( HMENU hmenu, unsigned id, char *text, BOOL by_position )
{
    WPI_MENUSTATE       state;
    HMENU               popup;

    if( !_wpi_getmenustate( hmenu, id, (WPI_MENUSTATE *)&state, by_position ) ) {
        return( FALSE );
    }
    popup = (HMENU)NULL;
    if( state & MF_POPUP ) {
        if( !by_position ) {
            return( FALSE );
        }
        popup = _wpi_getsubmenu( hmenu, id );
    }
    state = MF_STRING | ((by_position) ? MF_BYPOSITION : MF_BYCOMMAND);
    if( popup != (HMENU)NULL ) {
        state |= MF_POPUP;
    }
    return(
        ModifyMenu( hmenu, id, state,
                    (popup != (HMENU)NULL) ? (UINT)popup : (UINT)id,
                    text ) );
}

BOOL _wpi_getmenutext( HMENU hmenu, unsigned id, char *text, int ctext,
                       BOOL by_position )
{
    return( GetMenuString( hmenu, id, text, ctext, (by_position) ? MF_BYPOSITION : MF_BYCOMMAND ) );
}

BOOL _wpi_setmenu( HWND hwnd, HMENU hmenu )
{
    return( SetMenu( hwnd, hmenu ) );
}

WPI_PRES _wpi_createcompatiblepres( WPI_PRES pres, WPI_INST inst, HDC *hdc )
/**************************************************************************/
{
    HDC         memdc;

    inst = inst;                        // to eliminate compiler messages
    hdc = hdc;
    memdc = CreateCompatibleDC( pres );
    return( memdc );
} /* _wpi_createcompatiblepres */

void _wpi_getbitmapparms( HBITMAP bitmap, int *width, int *height, int *planes,
                                            int *widthbytes, int *bitspixel )
/******************************************************************/
/* Note that the 'bitcount' is the same as widthbytes.            */
{
    BITMAP                      bm;

    GetObject( bitmap, sizeof(BITMAP), &bm );

    if( width ) *width = bm.bmWidth;
    if( height ) *height = bm.bmHeight;
    if( planes ) *planes = (int)bm.bmPlanes;
    if( widthbytes ) *widthbytes = bm.bmWidthBytes;

    // This parameter is the bitcount in PM
    if( bitspixel ) *bitspixel = (int)bm.bmBitsPixel;
} /* _wpi_getbitmapparms */

void _wpi_setqmsgvalues( WPI_QMSG *qmsg, HWND hwnd, WPI_MSG wpi_msg,
                        WPI_PARAM1 wparam, WPI_PARAM2 lparam, ULONG wpi_time,
                        WPI_POINT pt )
/***************************************************************************/
{
    qmsg->hwnd = hwnd;
    qmsg->message = wpi_msg;
    qmsg->wParam = wparam;
    qmsg->lParam = lparam;
    qmsg->time = wpi_time;
    qmsg->pt.x = pt.x;
    qmsg->pt.y = pt.y;
} /* _wpi_setqmsgvalues */

void _wpi_getqmsgvalues( WPI_QMSG qmsg, HWND *hwnd, WPI_MSG *wpi_msg,
                        WPI_PARAM1 *wparam, WPI_PARAM2 *lparam, ULONG *wpi_time,
                        WPI_POINT *pt )
/***************************************************************************/
{
    if( hwnd ) {
        *hwnd = qmsg.hwnd;
    }
    if( wpi_msg ) {
        *wpi_msg = qmsg.message;
    }
    if( wparam ) {
        *wparam = qmsg.wParam;
    }
    if( lparam ) {
        *lparam = qmsg.lParam;
    }
    if( wpi_time ) {
        *wpi_time = qmsg.time;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?