Exemplo n.º 1
0
        public void LoadResourceMenu(IntPtr hWnd)
        {
            if (_menuID.IsNull)
            {
                return;
            }

            var res = _module.NeFile.GetResourceStream(Win16.ResourceType.RT_MENU.ToString(), _menuID.ToString());

            if (res != null)
            {
                var menu = Resources.LoadMenu(res);
                User.SetMenu(hWnd, menu);
            }
        }
Exemplo n.º 2
0
        public ushort FindResource(ushort hInstance, StringOrId ridName, StringOrId ridType)
        {
            if (ridType.Name == null)
            {
                if (ridType.ID >= 1 && ridType.ID <= 23)
                {
                    ridType = new StringOrId(((Win16.ResourceType)ridType.ID).ToString());
                }
            }

            // Crack params
            var module = hInstance == 0 ? _machine.ProcessModule : _machine.ModuleManager.GetModule(hInstance) as Module16;

            if (module == null)
            {
                return(0);
            }

            // Find the resource
            var resourceEntry = module.NeFile.FindResource(ridType.ToString(), ridName.ToString());

            // hRsrc already allocated?
            ResourceInfo resInfo;

            if (_resourceEntryMap.TryGetValue(resourceEntry, out resInfo))
            {
                return(resInfo.hRsrc);
            }

            // Create a HRSRC
            while (_hrsrcMap.ContainsKey(_nextHRSRC) && _nextHRSRC < 0x100)
            {
                _nextHRSRC++;
            }

            // Create resinfo
            resInfo = new ResourceInfo()
            {
                hRsrc         = _nextHRSRC++,
                module        = module,
                refCount      = 0,
                resourceEntry = resourceEntry,
                ridName       = ridName.ToString(),
                ridType       = ridType.ToString(),
                hData         = 0,
            };

            // Add to map
            _resourceEntryMap.Add(resourceEntry, resInfo);
            _hrsrcMap.Add(resInfo.hRsrc, resInfo);

            // Return pseudo handle
            return(resInfo.hRsrc);

            /*
             * // Look for already loaded resource
             * var existing = _hrsrcInfo.FirstOrDefault(x => x.Value.resourceEntry == resourceEntry);
             * if (existing.HasVa)
             * {
             *  return existing.hInstance;
             * }
             *
             * // Load the data
             * var data = module.NeFile.LoadResource(ridType.ToString(), ridName.ToString());
             * if (data == null)
             *  return 0;
             *
             * // Map it into address space
             * string heapName = string.Format("Module '{0}' (0x{1:X4}) Resource {2} {3}", module.GetModuleName(), hInstance, ridType.ToString(), ridName.ToString());
             * hrsrc = _machine.GlobalHeap.Alloc(heapName, 0, (uint)data.Length);
             * if (hrsrc == 0)
             *  return 0;
             *
             * Buffer.BlockCopy(data, 0, _machine.GlobalHeap.GetBuffer(hrsrc, true), 0, data.Length);
             *
             * // Cache it
             * _loadedResources.Add(key, hrsrc);
             *
             * // Cache the params used to find it so that
             * _hrsrcInfo[hrsrc] = new CResourceInfo()
             * {
             *  hInstance = hInstance,
             *  ridType = ridType,
             *  ridName = ridName,
             * };
             *
             * var re = module.NeFile.FindResource(ridType.ToString(), ridName.ToString());
             * _machine.GlobalHeap.SetFileSource(hrsrc, module.NeFile.FileName, (uint)re.offset);
             *
             * // Done
             * return hrsrc;
             */
        }