| 1 | /* $Id: winicon.cpp,v 1.2 1999-11-03 19:51:44 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Win32 Icon Code for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 | #include <os2win.h>
|
|---|
| 13 | #include <winicon.h>
|
|---|
| 14 |
|
|---|
| 15 | //******************************************************************************
|
|---|
| 16 | //******************************************************************************
|
|---|
| 17 | HICON WIN32API CreateIcon( HINSTANCE arg1, INT arg2, INT arg3, BYTE arg4, BYTE arg5, LPCVOID arg6, LPCVOID arg7)
|
|---|
| 18 | {
|
|---|
| 19 | #ifdef DEBUG
|
|---|
| 20 | WriteLog("USER32: CreateIcon\n");
|
|---|
| 21 | #endif
|
|---|
| 22 | return O32_CreateIcon(arg1, arg2, arg3, arg4, arg5, (const BYTE *)arg6, (const BYTE *)arg7);
|
|---|
| 23 | }
|
|---|
| 24 | //******************************************************************************
|
|---|
| 25 | //ASSERT dwVer == win31 (ok according to SDK docs)
|
|---|
| 26 | //******************************************************************************
|
|---|
| 27 | HICON WIN32API CreateIconFromResource(PBYTE presbits, UINT dwResSize,
|
|---|
| 28 | BOOL fIcon, DWORD dwVer)
|
|---|
| 29 | {
|
|---|
| 30 | HICON hicon;
|
|---|
| 31 | DWORD OS2ResSize = 0;
|
|---|
| 32 | PBYTE OS2Icon = ConvertWin32Icon(presbits, dwResSize, &OS2ResSize);
|
|---|
| 33 |
|
|---|
| 34 | hicon = O32_CreateIconFromResource(OS2Icon, OS2ResSize, fIcon, dwVer);
|
|---|
| 35 | #ifdef DEBUG
|
|---|
| 36 | WriteLog("USER32: CreateIconFromResource returned %X (%X)\n", hicon, GetLastError());
|
|---|
| 37 | #endif
|
|---|
| 38 | if(OS2Icon)
|
|---|
| 39 | FreeIcon(OS2Icon);
|
|---|
| 40 |
|
|---|
| 41 | return(hicon);
|
|---|
| 42 | }
|
|---|
| 43 | //******************************************************************************
|
|---|
| 44 | //******************************************************************************
|
|---|
| 45 | HICON WIN32API CreateIconFromResourceEx(PBYTE presbits, UINT dwResSize,
|
|---|
| 46 | BOOL fIcon, DWORD dwVer,
|
|---|
| 47 | int cxDesired, int cyDesired,
|
|---|
| 48 | UINT Flags)
|
|---|
| 49 | {
|
|---|
| 50 | #ifdef DEBUG
|
|---|
| 51 | WriteLog("USER32: CreateIconFromResourceEx %X %d %d %X %d %d %X, not completely supported!\n", presbits, dwResSize, fIcon, dwVer, cxDesired, cyDesired, Flags);
|
|---|
| 52 | #endif
|
|---|
| 53 | return CreateIconFromResource(presbits, dwResSize, fIcon, dwVer);
|
|---|
| 54 | }
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | HICON WIN32API CreateIconIndirect(LPICONINFO pIcon)
|
|---|
| 58 | {
|
|---|
| 59 | HICON hIcon;
|
|---|
| 60 | HDC hdcSrc, hdcDst;
|
|---|
| 61 |
|
|---|
| 62 | dprintf(("USER32: CreateIconIndirect\n"));
|
|---|
| 63 | if(pIcon->hbmMask && pIcon->hbmColor)
|
|---|
| 64 | {
|
|---|
| 65 | ICONINFO iconinfo;
|
|---|
| 66 | SIZE bmpsize;
|
|---|
| 67 |
|
|---|
| 68 | iconinfo = *pIcon;
|
|---|
| 69 | if(GetBitmapDimensionEx(pIcon->hbmColor, &bmpsize) == FALSE) {
|
|---|
| 70 | return 0;
|
|---|
| 71 | }
|
|---|
| 72 | //if there's a color bitmap, the mask bitmap contains only the AND bits
|
|---|
| 73 | //Open32 calls WinCreatePointerIndirect which expects AND & XOR bits
|
|---|
| 74 | //To solve this we create a bitmap that's 2x height of the mask, copy
|
|---|
| 75 | //the AND bits and set the XOR bits to 0
|
|---|
| 76 | hdcSrc = CreateCompatibleDC(0);
|
|---|
| 77 | hdcDst = CreateCompatibleDC(0);
|
|---|
| 78 |
|
|---|
| 79 | iconinfo.hbmMask = CreateCompatibleBitmap (hdcDst, bmpsize.cx, bmpsize.cy*2);
|
|---|
| 80 | SelectObject (hdcDst, iconinfo.hbmMask);
|
|---|
| 81 | SelectObject (hdcSrc, pIcon->hbmMask);
|
|---|
| 82 | BitBlt (hdcDst, 0, 0, bmpsize.cx, bmpsize.cy,
|
|---|
| 83 | hdcSrc, bmpsize.cx, 0, SRCCOPY);
|
|---|
| 84 | PatBlt (hdcDst, bmpsize.cx, bmpsize.cy, bmpsize.cx, bmpsize.cy, BLACKNESS);
|
|---|
| 85 |
|
|---|
| 86 | hIcon = O32_CreateIconIndirect(&iconinfo);
|
|---|
| 87 |
|
|---|
| 88 | DeleteObject(iconinfo.hbmMask);
|
|---|
| 89 | DeleteDC(hdcSrc);
|
|---|
| 90 | DeleteDC(hdcDst);
|
|---|
| 91 |
|
|---|
| 92 | return hIcon;
|
|---|
| 93 | }
|
|---|
| 94 | hIcon = O32_CreateIconIndirect(pIcon);
|
|---|
| 95 | if(hIcon == 0) {
|
|---|
| 96 | dprintf(("CreateIconIndirect %d (%d,%d) %x %x failed with %x", pIcon->fIcon, pIcon->xHotspot, pIcon->yHotspot, pIcon->hbmMask, pIcon->hbmColor, GetLastError()));
|
|---|
| 97 | }
|
|---|
| 98 | return hIcon;
|
|---|
| 99 | }
|
|---|
| 100 | //******************************************************************************
|
|---|
| 101 | //******************************************************************************
|
|---|
| 102 | BOOL WIN32API DestroyIcon( HICON arg1)
|
|---|
| 103 | {
|
|---|
| 104 | #ifdef DEBUG
|
|---|
| 105 | WriteLog("USER32: DestroyIcon\n");
|
|---|
| 106 | #endif
|
|---|
| 107 | return O32_DestroyIcon(arg1);
|
|---|
| 108 | }
|
|---|
| 109 | //******************************************************************************
|
|---|
| 110 | //******************************************************************************
|
|---|
| 111 | HICON WIN32API CopyIcon( HICON arg1)
|
|---|
| 112 | {
|
|---|
| 113 | #ifdef DEBUG
|
|---|
| 114 | WriteLog("USER32: CopyIcon\n");
|
|---|
| 115 | #endif
|
|---|
| 116 | return O32_CopyIcon(arg1);
|
|---|
| 117 | }
|
|---|
| 118 | //******************************************************************************
|
|---|
| 119 | //******************************************************************************
|
|---|
| 120 | BOOL WIN32API GetIconInfo( HICON arg1, LPICONINFO arg2)
|
|---|
| 121 | {
|
|---|
| 122 | #ifdef DEBUG
|
|---|
| 123 | WriteLog("USER32: GetIconInfo\n");
|
|---|
| 124 | #endif
|
|---|
| 125 | return O32_GetIconInfo(arg1, arg2);
|
|---|
| 126 | }
|
|---|
| 127 | //******************************************************************************
|
|---|
| 128 | //******************************************************************************
|
|---|