Any help greatly appreciated:
Code: Select all
ReplaceCursor(re, CurFile, cursorID)
{
f := FileOpen(CurFile, "r")
if !IsObject(f)
return false
VarSetCapacity(igh, 8), f.RawRead(igh, 6)
if NumGet(igh, 0, "UShort") != 0 || NumGet(igh, 2, "UShort") != 2 ;2 for cursor
return false
wCount := NumGet(igh, 4, "UShort")
, VarSetCapacity(rsrcCursorGroup, rsrcCursorGroupSize := 6 + wCount*14)
, NumPut(NumGet(igh, "Int64"), rsrcCursorGroup, "Int64") ; fast copy
, ige := &rsrcCursorGroup + 6
Loop, %wCount%
{
thisID := (cursorID-1) + A_Index
, f.RawRead(ige+0, 12) ; read all but the offset
, NumPut(thisID, ige+12, "UShort")
, imgOffset := f.ReadUInt()
, oldPos := f.Pos
, f.Pos := imgOffset
, VarSetCapacity(cursorData, cursorDataSize := NumGet(ige+8, "UInt"))
, f.RawRead(cursorData, cursorDataSize)
, f.Pos := oldPos
, DllCall("UpdateResource", "ptr", re, "ptr", 1, "ptr", thisID, "ushort", 0x409, "ptr", &cursorData, "uint", cursorDataSize, "uint") ; 1 for RT_CURSOR
, ige += 14
} ; 12 for RT_GOUP_CURSOR
return thisID + 1, DllCall("UpdateResource", "ptr", re, "ptr", 12, "ptr", cursorID, "ushort", 0x409, "ptr", &rsrcCursorGroup, "uint", rsrcCursorGroupSize, "uint")
}
Code: Select all
module := DllCall("BeginUpdateResource", "str", ExeName, "uint", 0, "ptr")
Loop, Cursors\*.cur
{
SplitPath, A_LoopFileFullPath,,,,CursorName
ReplaceCursor(module, A_LoopFileFullPath, CursorName)
}
DllCall("EndUpdateResource", "ptr", module, "uint", 0)
Thanks in advance
- gwarble
Edit: the changes from working function for icons include RT_CURSOR = 1, RT_GROUP_CURSOR = 12, the second byte checked for 2 for cursor instead of 1 for icon... What i can't figure out is there are 4 bytes ahead of the BITMAPINFOHEADER that are the X and Y hotspots of the cursor i need to compensate for...
Edit: some details here: http://www.skynet.ie/~caolan/publink/wi ... resfmt.txt
Cursor resources are very much like icon resources. They are formed
in groups with the components preceding the header. This header also
employs a fixed-length component index that allows random access of
the individual components. The structure of the cursor header is as
follows:
[Resource header (type = 12)]
struct CursorHeader {
WORD wReserved; // Currently zero
WORD wType; // 2 for cursors
WORD cwCount; // Number of components
WORD padding; // filler for DWORD alignment
};
The next portion is repeated for each component resource, and starts
on a DWORD boundary.
struct ResourceDirectory {
WORD wWidth;
WORD wHeight;
WORD wPlanes;
WORD wBitCount;
DWORD lBytesInRes;
WORD wNameOrdinal; // Points to component
WORD padding; // filler for DWORD alignment
};
Each cursor component is also similar to each icon component. There
is, however, one significant difference between the two: cursors
have the concept of a `hotspot' where icons do not. Here is the
component structure:
[Resource header (Type = 1)]
struct CursorComponent {
short xHotspot;
short yHotspot;
}
[Monochrome XOR mask]
[Monochrome AND mask]
These masks are bitmaps copied from the .CUR file. The main
difference from icons in this regard is that cursors do not have
color DIBs used for XOR masks like cursors. Although the bitmaps are
monochrome and do not have DIB headers or color tables, the bits are
still in DIB format with respect to alignment and direction. See the
SDK Reference for more information on DIB formats.