Ignore:
Timestamp:
Nov 9, 1999, 6:07:23 PM (26 years ago)
Author:
cbratschi
Message:

MoveTo, system resource handling fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/loadres.cpp

    r1612 r1667  
    1 /* $Id: loadres.cpp,v 1.14 1999-11-05 12:54:10 sandervl Exp $ */
     1/* $Id: loadres.cpp,v 1.15 1999-11-09 17:07:21 cbratschi Exp $ */
    22
    33/*
     
    2323#include <win\virtual.h>
    2424#include "dib.h"
     25#include "initterm.h"
    2526
    2627//******************************************************************************
     
    3334
    3435    if (buffer && buflen)
    35         buffer2 = (LPWSTR)HeapAlloc( GetProcessHeap(), 0, buflen * 2 );
     36        buffer2 = (LPWSTR)HeapAlloc( GetProcessHeap(), 0, buflen * 2 );
    3637
    3738    retval = LoadStringW(instance,resource_id,buffer2,buflen);
     
    3940    if (buffer2)
    4041    {
    41         if (retval) {
    42             lstrcpynWtoA( buffer, buffer2, buflen );
    43             retval = lstrlenA( buffer );
    44         }
    45         else
    46             *buffer = 0;
    47         HeapFree( GetProcessHeap(), 0, buffer2 );
     42        if (retval) {
     43            lstrcpynWtoA( buffer, buffer2, buflen );
     44            retval = lstrlenA( buffer );
     45        }
     46        else
     47            *buffer = 0;
     48        HeapFree( GetProcessHeap(), 0, buffer2 );
    4849    }
    4950    return retval;
     
    5859 int i = 0;
    5960
    60     /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out 
     61    /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out
    6162     * 20 - 31. */
    6263    winres = (Win32Resource *)FindResourceW(hinst, (LPWSTR)(((wID>>4)&0xffff)+1), RT_STRINGW);
     
    6970    p = (LPWSTR)winres->lockResource();
    7071    if(p) {
    71         string_num = wID & 0x000f;
    72         for (i = 0; i < string_num; i++)
    73                 p += *p + 1;
    74      
    75         if (lpBuffer == NULL) return *p;
    76         i = min(cchBuffer - 1, *p);
    77         if (i > 0) {
    78                 memcpy(lpBuffer, p + 1, i * sizeof (WCHAR));
    79                 lpBuffer[i] = (WCHAR) 0;
    80         }
    81         else {
    82                 if (cchBuffer > 1) {
    83                         lpBuffer[0] = (WCHAR) 0;
    84                         return 0;
    85                 }
    86         }
     72        string_num = wID & 0x000f;
     73        for (i = 0; i < string_num; i++)
     74                p += *p + 1;
     75
     76        if (lpBuffer == NULL) return *p;
     77        i = min(cchBuffer - 1, *p);
     78        if (i > 0) {
     79                memcpy(lpBuffer, p + 1, i * sizeof (WCHAR));
     80                lpBuffer[i] = (WCHAR) 0;
     81        }
     82        else {
     83                if (cchBuffer > 1) {
     84                        lpBuffer[0] = (WCHAR) 0;
     85                        return 0;
     86                }
     87        }
    8788    }
    8889    delete winres;
     
    9899 HICON          hIcon;
    99100
    100     hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon);
    101     if(hIcon == 0) {//not a system icon
     101    if (!hinst)
     102    {
     103      winres = (Win32Resource*)FindResourceA(hInstanceUser32,lpszIcon,RT_ICONA);
     104      if (!winres) winres = (Win32Resource*)FindResourceA(hInstanceUser32,lpszIcon,RT_GROUP_ICONA);
     105      if (winres)
     106      {
     107        hIcon = OSLibWinCreateIcon(winres->lockOS2Resource());
     108        delete winres;
     109      } else hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON));
     110    } else
     111    { //not a system icon
    102112        winres = (Win32Resource *)FindResourceA(hinst, lpszIcon, RT_ICONA);
    103113        if(winres == 0) {
     
    107117                hIcon = OSLibWinCreateIcon(winres->lockOS2Resource());
    108118                delete winres;
    109         }
     119        } else hIcon = 0;
    110120    }
    111121    dprintf(("LoadIconA (%X) returned %x\n", hinst, hIcon));
     
    120130 HICON          hIcon;
    121131
    122     hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon);
    123     if(hIcon == 0) {//not a system icon
     132    if (!hinst)
     133    {
     134      winres = (Win32Resource*)FindResourceW(hInstanceUser32,lpszIcon,RT_ICONW);
     135      if (!winres) winres = (Win32Resource*)FindResourceW(hInstanceUser32,lpszIcon,RT_GROUP_ICONW);
     136      if (winres)
     137      {
     138        hIcon = OSLibWinCreateIcon(winres->lockOS2Resource());
     139        delete winres;
     140      } else hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON));
     141    } else
     142    {//not a system icon
    124143        winres = (Win32Resource *)FindResourceW(hinst, lpszIcon, RT_ICONW);
    125144        if(winres == 0) {
     
    129148                hIcon = OSLibWinCreateIcon(winres->lockOS2Resource());
    130149                delete winres;
    131         }
     150        } else hIcon = 0;
    132151    }
    133152    dprintf(("LoadIconW (%X) returned %x\n", hinst, hIcon));
     
    142161 HCURSOR        hCursor;
    143162
    144     hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor);
    145     if(hCursor == 0) {//not a system pointer
     163    if (!hinst)
     164    {
     165      winres = (Win32Resource*)FindResourceA(hInstanceUser32,lpszCursor,RT_CURSORA);
     166      if (!winres) winres = (Win32Resource*)FindResourceA(hInstanceUser32,lpszCursor,RT_GROUP_CURSORA);
     167      if (winres)
     168      {
     169        hCursor = OSLibWinCreatePointer(winres->lockOS2Resource());
     170        delete winres;
     171      } else hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor,GetSystemMetrics(SM_CXCURSOR),GetSystemMetrics(SM_CYCURSOR));
     172    } else
     173    {//not a system pointer
    146174        winres = (Win32Resource *)FindResourceA(hinst, lpszCursor, RT_CURSORA);
    147175        if(winres == 0) {
     
    151179                hCursor = OSLibWinCreatePointer(winres->lockOS2Resource());
    152180                delete winres;
    153         }
     181        } else hCursor = 0;
    154182    }
    155183    if(HIWORD(lpszCursor)) {
     
    167195 HCURSOR        hCursor;
    168196
    169     hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor);
    170     if(hCursor == 0) {//not a system pointer
     197    if (!hinst)
     198    {
     199      winres = (Win32Resource*)FindResourceW(hInstanceUser32,lpszCursor,RT_CURSORW);
     200      if (!winres) winres = (Win32Resource*)FindResourceW(hInstanceUser32,lpszCursor,RT_GROUP_CURSORW);
     201      if (winres)
     202      {
     203        hCursor = OSLibWinCreatePointer(winres->lockOS2Resource());
     204        delete winres;
     205      } else hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor,GetSystemMetrics(SM_CXCURSOR),GetSystemMetrics(SM_CYCURSOR));
     206    } else
     207    {//not a system pointer
    171208        winres = (Win32Resource *)FindResourceW(hinst, lpszCursor, RT_CURSORW);
    172209        if(winres == 0) {
     
    176213                hCursor = OSLibWinCreatePointer(winres->lockOS2Resource());
    177214                delete winres;
    178         }
     215        } else hCursor = 0;
    179216    }
    180217    dprintf(("LoadCursorW (%X) returned %x\n", hinst, hCursor));
     
    341378 HBITMAP hBitmap = 0;
    342379
    343   if(IsSystemBitmap((ULONG *)&lpszBitmap)) {
    344         hBitmap = O32_LoadBitmap(hinst, lpszBitmap);
     380  if (!hinst)
     381  {
     382    if(IsSystemBitmap((ULONG *)&lpszBitmap))
     383    {
     384      hBitmap = O32_LoadBitmap(hInstanceUser32,lpszBitmap);
     385      if (!hBitmap) hBitmap = O32_LoadBitmap(hinst,lpszBitmap);
     386    } else hBitmap = 0;
     387  } else hBitmap = LoadBitmapA(hinst, lpszBitmap, 0, 0, 0);
     388  dprintf(("LoadBitmapA returned %08xh\n", hBitmap));
     389
     390  return(hBitmap);
     391}
     392//******************************************************************************
     393//TODO: No support for RT_NEWBITMAP
     394//******************************************************************************
     395HBITMAP WIN32API LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszBitmap)
     396{
     397 HBITMAP hBitmap = 0;
     398
     399  if (!hinst)
     400  {
     401    if(IsSystemBitmap((ULONG *)&lpszBitmap))
     402    {
     403      hBitmap = O32_LoadBitmap(hInstanceUser32,(LPCSTR)lpszBitmap);
     404      if (!hBitmap) hBitmap = O32_LoadBitmap(hinst,(LPCSTR)lpszBitmap);
     405    } else hBitmap = 0;
     406  } else
     407  {
     408    if(HIWORD(lpszBitmap) != 0)
     409      lpszBitmap = (LPWSTR)UnicodeToAsciiString((LPWSTR)lpszBitmap);
     410
     411    hBitmap = LoadBitmapA(hinst, (LPSTR)lpszBitmap, 0, 0, 0);
     412
     413    if(HIWORD(lpszBitmap) != 0)
     414      FreeAsciiString((LPSTR)lpszBitmap);
    345415  }
    346   if(!hBitmap) {
    347         hBitmap = LoadBitmapA(hinst, lpszBitmap, 0, 0, 0);
    348   }
    349   dprintf(("LoadBitmapA returned %08xh\n", hBitmap));
    350 
    351   return(hBitmap);
    352 }
    353 //******************************************************************************
    354 //TODO: No support for RT_NEWBITMAP
    355 //******************************************************************************
    356 HBITMAP WIN32API LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszBitmap)
    357 {
    358  HBITMAP hBitmap = 0;
    359 
    360   if(IsSystemBitmap((ULONG *)&lpszBitmap)) {
    361         hBitmap = O32_LoadBitmap(hinst, (LPCSTR)lpszBitmap);
    362   }
    363   if(!hBitmap) {
    364         if(HIWORD(lpszBitmap) != 0) {
    365                  lpszBitmap = (LPWSTR)UnicodeToAsciiString((LPWSTR)lpszBitmap);
    366         }
    367         hBitmap = LoadBitmapA(hinst, (LPSTR)lpszBitmap, 0, 0, 0);
    368   }
    369 
    370   if(HIWORD(lpszBitmap) != 0)
    371         FreeAsciiString((LPSTR)lpszBitmap);
    372416
    373417  dprintf(("LoadBitmapW returned %08xh\n", hBitmap));
     
    385429
    386430  if(HIWORD(lpszName)) {
    387         dprintf(("LoadImageA NOT COMPLETE %x %s %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
     431        dprintf(("LoadImageA NOT COMPLETE %x %s %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
    388432  }
    389   else  dprintf(("LoadImageA NOT COMPLETE %x %x %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
     433  else  dprintf(("LoadImageA NOT COMPLETE %x %x %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
    390434
    391435  if (fuLoad & LR_DEFAULTSIZE) {
     
    482526    switch (type)
    483527    {
    484 //      case IMAGE_BITMAP:
    485 //              return BITMAP_CopyBitmap(hnd);
    486         case IMAGE_ICON:
    487                 return CopyIcon(hnd);
    488         case IMAGE_CURSOR:
    489                 return CopyCursor(hnd);
    490         default:
    491                 dprintf(("CopyImage: Unsupported type"));
     528//      case IMAGE_BITMAP:
     529//              return BITMAP_CopyBitmap(hnd);
     530        case IMAGE_ICON:
     531                return CopyIcon(hnd);
     532        case IMAGE_CURSOR:
     533                return CopyCursor(hnd);
     534        default:
     535                dprintf(("CopyImage: Unsupported type"));
    492536    }
    493537    return 0;
Note: See TracChangeset for help on using the changeset viewer.