Code:
typedef struct { int iBitmap; int idCommand; BYTE fsState; BYTE fsStyle; #ifdef _WIN64 BYTE bReserved[6]; #else #if defined(_WIN32) BYTE bReserved[2]; #endif #endif DWORD_PTR dwData; INT_PTR iString; } TBBUTTON, *PTBBUTTON, *LPTBBUTTON;
Code:
DWORD_PTR = DWORD; INT_PTR = INT; TBBUTTON = MemoryEx.DefineStruct{ INT "iBitmap"; INT "idCommand"; BYTE "fsState"; BYTE "fsStyle"; BYTE "bReserved"; DWORD_PTR "dwData"; INT_PTR "iString"; }
Code:
AToolBar.AddButtonEx = function(ID,Txt,Img,Typ) local TB_ADDBUTTONS = 0x414; local TBSTATE_ENABLED = 4; local TBSTYLE_BUTTON = 0; local TBSTYLE_SEP = 1; local BTNS_WHOLEDROPDOWN = 0x0080; local BTNS_SHOWTEXT = 0x0040; local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(TBBUTTON) + 100); if(lpBuff)then local hStruct = MemoryEx.AssignStruct(lpBuff + 50, TBBUTTON); if(hStruct)then hStruct.iBitmap = Img; hStruct.idCommand = ID; hStruct.fsState = TBSTATE_ENABLED; if Typ == 1 then hStruct.fsStyle = TBSTYLE_BUTTON; elseif Typ == 2 then hStruct.fsStyle = TBSTYLE_SEP; elseif Typ == 3 then hStruct.fsStyle = BTNS_WHOLEDROPDOWN; end hStruct.bReserved = 0; hStruct.dwData = 0; local n = String.Length(Txt) + 1 local m = MemoryEx.Allocate(n) MemoryEx.String(m,-1,MEMEX_ASCII,Txt) hStruct.iString = m local poi = hStruct:GetPointer() if tonumber(User32Library.SendMessageA(AToolBar.Handle,TB_ADDBUTTONS,1,poi)) == 0 then MemoryEx.Free(lpBuff); MemoryEx.Free(m); hStruct:Close(); return false, "Can't add button" else MemoryEx.Free(lpBuff); MemoryEx.Free(m); hStruct:Close(); return true, "OK" end else MemoryEx.Free(lpBuff); return false, "Can't assign structure" end else return false, "Can't create buffer" end end;
Second question about this structure is you can define more than one button at a time with it so is shown in C++
Code:
TBBUTTON tbButtons[numButtons] = { { MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" }, { MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"}, { MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"} };
Comment