Found something funny: It is possible to give the tooltip-rect negativ values (i think, this is a bug and should not work; but it work under win98se and winXP prof).
Code: Select all
Global XPStyle
#TitleButton_ChangeState=#WM_User
Structure Box
x.l
y.l
w.l
h.l
EndStructure
Structure TitleButton
WindowID.l
Flags.l
State.l
OldWndProc.l
Icon1.l
Icon2.l
Icon3.l
Icon4.l
ActivState.l
CurrentIcon.l
ToolTip.l
EndStructure
;XIncludeFile "test.pb.declare"
;Autogenerated -- start of section automatically generated from Test.pb
; with jaPBe 1.4.2.28
Declare UpdateIconToolTipRect(WindowID,ToolTip)
Declare CreateIconButtonToolTip(WindowID, text$); - Create a (Balloon) Toolkit
Declare CreateIcon(GadgetNb,ImageNb,StampNb,WindowID)
Declare SetPixelProzent(hDC,x,y,pro)
Declare TitleButtonCallback(WindowID, Message, wParam, lParam)
Declare TestInButton(WindowID,*pt.POINT)
Declare SetTitleButtonState(WindowID,State)
Declare GetTitleButtonState(WindowID)
Declare RemoveTitleButton(WindowID)
Declare AddTitleButton(WindowID,Icon1,Icon2,Icon3,Icon4,Flags,ToolTip$)
Declare Redraw_TitleBarIcon(WindowID)
Declare GetMetrics(WindowID,*box.Box)
Declare GetBitmapHeight(hBitmap)
Declare GetBitmapWidth(hBitmap)
Procedure GetBitmapWidth(hBitmap)
BmpInfo.BITMAP
If hBitmap = 0 : ProcedureReturn 0 : EndIf
If GetObjectType_(hBitmap) <> #OBJ_BITMAP : ProcedureReturn 0 : EndIf
If GetObject_(hBitmap, SizeOf(BITMAP), BmpInfo) = 0 : ProcedureReturn 0 : EndIf
ProcedureReturn BmpInfo\bmWidth
EndProcedure
Procedure GetBitmapHeight(hBitmap)
BmpInfo.BITMAP
If hBitmap = 0 : ProcedureReturn 0 : EndIf
If GetObjectType_(hBitmap) <> #OBJ_BITMAP : ProcedureReturn 0 : EndIf
If GetObject_(hBitmap, SizeOf(BITMAP), BmpInfo) = 0 : ProcedureReturn 0 : EndIf
ProcedureReturn BmpInfo\bmHeight
EndProcedure
Procedure GetMetrics(WindowID,*box.Box)
getclientrect_(WindowID,rect.RECT)
WindowWidth= rect\right
CaptionHeight = GetSystemMetrics_(#SM_CYCAPTION)
*box\w = GetSystemMetrics_(#SM_CXSIZE)-2
*box\h = GetSystemMetrics_(#SM_CYSIZE)-4
*box\x = WindowWidth-(*box\w*4)-GetSystemMetrics_(#SM_CXDLGFRAME)-GetSystemMetrics_(#SM_CXBORDER)
*box\y = ((CaptionHeight-*box\h)/2)+GetSystemMetrics_(#SM_CYDLGFRAME)
EndProcedure
NewList TitleButtons.TitleButton()
Procedure Redraw_TitleBarIcon(WindowID)
GetMetrics(WindowID,Box.Box)
hRegion = CreateRectRgn_(Box\x, Box\y, Box\x+Box\w, Box\y+Box\h)
SendMessage_(WindowID, #WM_NCPAINT, hRegion, 0)
DeleteObject_(hRegion)
EndProcedure
Procedure AddTitleButton(WindowID,Icon1,Icon2,Icon3,Icon4,Flags,ToolTip$)
AddElement(TitleButtons())
TitleButtons()\WindowID=WindowID
TitleButtons()\OldWndProc=GetWindowLong_(WindowID,#GWL_WNDPROC)
TitleButtons()\Flags=Flags
TitleButtons()\Icon1=Icon1
TitleButtons()\Icon2=Icon2
TitleButtons()\Icon3=Icon3
TitleButtons()\Icon4=Icon4
TitleButtons()\CurrentIcon=Icon1
SetWindowLong_(WindowID,#gwl_UserData,@TitleButtons())
SetWindowLong_(WindowID,#GWL_WNDPROC,@TitleButtonCallback())
Redraw_TitleBarIcon(WindowID)
TitleButtons()\ToolTip=CreateIconButtonToolTip(WindowID,ToolTip$)
EndProcedure
Procedure RemoveTitleButton(WindowID)
result=#False
ResetList(TitleButtons())
While NextElement(TitleButtons())
If TitleButtons()\WindowID=WindowID
SetWindowLong_(WindowID,#GWL_WNDPROC,TitleButtons()\OldWndProc)
SetWindowLong_(WindowID,#gwl_UserData,0)
DeleteElement(TitleButtons())
result=#True
Break
EndIf
Wend
ProcedureReturn result
EndProcedure
Procedure GetTitleButtonState(WindowID)
*TitleButton.TitleButton=GetWindowLong_(WindowID,#gwl_UserData)
If *TitleButton
ProcedureReturn *TitleButton\State
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure SetTitleButtonState(WindowID,State)
*TitleButton.TitleButton=GetWindowLong_(WindowID,#gwl_UserData)
If *TitleButton
*TitleButton\State=State
If *TitleButton\State=#False
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon1
Else
*TitleButton\CurrentIcon=*TitleButton\Icon3
EndIf
Else
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon2
Else
*TitleButton\CurrentIcon=*TitleButton\Icon4
EndIf
EndIf
Redraw_TitleBarIcon(WindowID)
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure TestInButton(WindowID,*pt.POINT)
ScreenToClient_(WindowID, *pt)
GetMetrics(WindowID,Box.Box)
xCur = *pt\x+GetSystemMetrics_(#SM_CXDLGFRAME)
yCur = *pt\y+GetSystemMetrics_(#SM_CYCAPTION)+GetSystemMetrics_(#SM_CYDLGFRAME)
If xCur>Box\x And xCur<(Box\x+Box\w) And yCur>Box\y And yCur<(Box\y+Box\h)
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure TitleButtonCallback(WindowID, Message, wParam, lParam)
*TitleButton.TitleButton=GetWindowLong_(WindowID,#gwl_UserData)
Select Message
Case #WM_NCACTIVATE
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
*TitleButton\ActivState=wParam
If *TitleButton\State=#False
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon1
Else
*TitleButton\CurrentIcon=*TitleButton\Icon3
EndIf
Else
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon2
Else
*TitleButton\CurrentIcon=*TitleButton\Icon4
EndIf
EndIf
Redraw_TitleBarIcon(WindowID)
Case #WM_NCPAINT
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
UpdateIconToolTipRect(*TitleButton\WindowID,*TitleButton\ToolTip)
GetMetrics(WindowID,Box.Box)
hDC = GetWindowDC_(WindowID)
hDCImage=CreateCompatibleDC_(hDC)
OldObject=SelectObject_(hDCImage,*TitleButton\CurrentIcon)
SetStretchBltMode_(hDC, #COLORONCOLOR)
If XPStyle
c1=GetPixel_(hDC,Box\x,Box\y)
c2=GetPixel_(hDC,Box\x+Box\w-1,Box\y)
c3=GetPixel_(hDC,Box\x+Box\w-1,Box\y+Box\h-1)
c4=GetPixel_(hDC,Box\x,Box\y+Box\h-1)
EndIf
StretchBlt_(hDC, Box\x, Box\y, Box\w,Box\h, hDCImage, 0, 0,GetBitmapWidth(*TitleButton\CurrentIcon),GetBitmapHeight(*TitleButton\CurrentIcon), #SRCCOPY)
If XPStyle
SetPixel_(hDC,Box\x,Box\y,c1)
SetPixel_(hDC,Box\x+Box\w-1,Box\y,c2)
SetPixel_(hDC,Box\x+Box\w-1,Box\y+Box\h-1,c3)
SetPixel_(hDC,Box\x,Box\y+Box\h-1,c4)
EndIf
SelectObject_(hDCImage,OldObject)
DeleteDC_(hDCImage)
ReleaseDC_(WindowID, hDC)
Case #wm_NCLBUTTONDBLCLK
If wParam=#HTCAPTION
pt.POINT
pt\x = lParam&$FFFF
pt\y = lParam>>16
If TestInButton(WindowID,pt)
SendMessage_(WindowID,#WM_NCLBUTTONDOWN,wParam,lParam)
EndIf
Else
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
EndIf
Case #WM_NCLBUTTONDOWN
If wParam=#HTCAPTION
pt.POINT
pt\x = lParam&$FFFF
pt\y = lParam>>16
If TestInButton(WindowID,pt)
*TitleButton\Flags&#PB_Button_Toggle
If *TitleButton\Flags&#PB_Button_Toggle;{Toogle
If *TitleButton\State
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon1
Else
*TitleButton\CurrentIcon=*TitleButton\Icon3
EndIf
*TitleButton\State=#False
Else
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon2
Else
*TitleButton\CurrentIcon=*TitleButton\Icon4
EndIf
*TitleButton\State=#True
EndIf
Redraw_TitleBarIcon(WindowID)
PostMessage_(WindowID,#TitleButton_ChangeState,*TitleButton\State,0)
;}
Else;{Button
While getasynckeystate_(#VK_LBUTTON)&$FF00
GetCursorPos_(pt)
If TestInButton(WindowID,pt)
If *TitleButton\State=#False
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon2
Else
*TitleButton\CurrentIcon=*TitleButton\Icon4
EndIf
*TitleButton\State=#True
Redraw_TitleBarIcon(WindowID)
EndIf
Else
If *TitleButton\State=#True
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon1
Else
*TitleButton\CurrentIcon=*TitleButton\Icon3
EndIf
*TitleButton\State=#False
Redraw_TitleBarIcon(WindowID)
EndIf
EndIf
Delay(1)
Wend
If *TitleButton\State=#True
If *TitleButton\ActivState
*TitleButton\CurrentIcon=*TitleButton\Icon1
Else
*TitleButton\CurrentIcon=*TitleButton\Icon3
EndIf
*TitleButton\State=#False
Redraw_TitleBarIcon(WindowID)
PostMessage_(WindowID,#TitleButton_ChangeState,#True,0)
EndIf
;}
EndIf
If *TitleButton\ActivState=#False
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
EndIf
Else
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
EndIf
Else
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
EndIf
Default
result = CallWindowProc_(*TitleButton\OldWndProc, WindowID, Message, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure
Procedure SetPixelProzent(hDC,x,y,pro)
col=GetPixel_(hDC,x,y)
r=Red(col)*pro/100:If r>255:r=255:EndIf
g=Green(col)*pro/100:If g>255:g=255:EndIf
b=Blue(col)*pro/100:If b>255:b=255:EndIf
SetPixel_(hDC,x,y,RGB(r,g,b))
EndProcedure
Procedure CreateIcon(GadgetNb,ImageNb,StampNb,WindowID)
GetMetrics(WindowID,Box.Box)
i1=CreateImage(ImageNb,Box\w,Box\h)
hDC = GetWindowDC_(GadgetID(GadgetNb))
hDCImage= CreateCompatibleDC_(hDC)
OldObject=SelectObject_(hDCImage,i1)
BitBlt_(hDCImage, 0,0, Box\w,Box\h, hDC, XPStyle, XPStyle, #SRCCOPY)
Ex=GetSystemMetrics_(#SM_CXEDGE)
Ey=GetSystemMetrics_(#SM_CyEDGE)
inW=Box\w-Ex*2-2
inH=Box\h-Ey*2-2
UseImage(StampNb)
outW=ImageWidth()
outH=ImageHeight()
StartDrawing(ImageOutput())
back=Point(0,0)
For x=0 To inW
xx=x*outW/(inW+1)
x2=(x+1)*outW/(inW+1)
If x2>xx:x2-1:EndIf
For y=0 To inH
yy=y*outH/(inH+1)
y2=(y+1)*outH/(inH+1)
If y2>yy:y2-1:EndIf
r=0:g=0:b=0:c=0
For dx=xx To x2
For dy=yy To y2
a=Point(dx,dy)
r+Red(a):g+Green(a):b+Blue(a)
c+1
Next
Next
If c>0
r/c:If r>255:r=255:EndIf
g/c:If g>255:g=255:EndIf
b/c:If b>255:b=255:EndIf
a=RGB(r,g,b)
Else
a=$FF00FF
EndIf
If a<>back
a=Red(a)*100/255
If XPStyle
a+30
EndIf
If a>100
a=100
EndIf
SetPixelProzent(hDCImage,Ex+x+1,Ex+y+1,a)
EndIf
Next
Next
StopDrawing()
SelectObject_(hDCImage,OldObject)
DeleteDC_(hDCImage)
ReleaseDC_(GadgetID(GadgetNb), hDC)
ProcedureReturn i1
EndProcedure
Procedure CreateIconButtonToolTip(WindowID, text$); - Create a (Balloon) Toolkit
Flag=#WS_POPUP | #TTS_NOPREFIX|#TTS_ALWAYSTIP
ToolTip=CreateWindowEx_(0,"ToolTips_Class32","",Flag,0,0,0,0,WindowID,0,GetModuleHandle_(0),0)
SendMessage_(ToolTip,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
SendMessage_(ToolTip,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
SendMessage_(ToolTip,#TTM_SETMAXTIPWIDTH,0,GetSystemMetrics_(#SM_CXFULLSCREEN))
Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
Balloon\uFlags= #TTF_SUBCLASS
Balloon\hwnd=WindowID
Balloon\uId=WindowID
getwindowrect_(WindowID,rect.RECT)
pt.POINT\x=0
pt.POINT\y=0
clienttoscreen_(WindowID,pt)
titlehight=pt\y-rect\top
leftoffset=GetSystemMetrics_(#SM_CXDLGFRAME)
GetMetrics(WindowID,Box.Box)
Balloon\rect\left=Box\x-leftoffset
Balloon\rect\top=Box\y-titlehight
Balloon\rect\right=Box\x+Box\w-leftoffset
Balloon\rect\bottom=Box\y+Box\h-titlehight
Balloon\lpszText=@text$
SendMessage_(ToolTip, #TTM_ADDTOOL, 0, Balloon)
ProcedureReturn ToolTip
EndProcedure
Procedure UpdateIconToolTipRect(WindowID,ToolTip)
If ToolTip
getwindowrect_(WindowID,rect.RECT)
pt.POINT\x=0
pt.POINT\y=0
clienttoscreen_(WindowID,pt)
titlehight=pt\y-rect\top
leftoffset=GetSystemMetrics_(#SM_CXDLGFRAME)
GetMetrics(WindowID,Box.Box)
Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
Balloon\uFlags= #TTF_SUBCLASS
Balloon\hwnd=WindowID
Balloon\uId=WindowID
Balloon\rect\left=Box\x-leftoffset
Balloon\rect\top=Box\y-titlehight
Balloon\rect\right=Box\x+Box\w-leftoffset
Balloon\rect\bottom=Box\y+Box\h-titlehight
SendMessage_(ToolTip, #TTM_NEWTOOLRECT, 0, Balloon)
EndIf
EndProcedure
;{Prepare icons
If OpenWindow(0,0,0,100,100,#PB_Window_ScreenCentered,"IconCreation!")
If CreateGadgetList(WindowID())
GetMetrics(WindowID(),Box.Box)
LoadImage(4,"ontop0.bmp");:ResizeImage(4,Box\w-GetSystemMetrics_(#SM_CXEDGE)*2,Box\h-GetSystemMetrics_(#SM_CyEDGE)*2)
LoadImage(5,"ontop1.bmp");:ResizeImage(5,Box\w-GetSystemMetrics_(#SM_CXEDGE)*2,Box\h-GetSystemMetrics_(#SM_CyEDGE)*2)
ButtonGadget(0, 0,0 ,Box\w,Box\h," ",#PB_Button_Toggle)
ButtonGadget(1,Box\w,0 ,Box\w,Box\h," ",#PB_Button_Toggle)
ButtonGadget(2, 0,Box\h,Box\w,Box\h," ",#PB_Button_Toggle)
ButtonGadget(3,Box\w,Box\h,Box\w,Box\h," ",#PB_Button_Toggle)
SetGadgetState(1,#True)
SetGadgetState(3,#True)
DisableGadget(2,#True)
DisableGadget(3,#True)
SendMessage_(GadgetID(0),#BM_SETIMAGE,#image_bitmap,i1)
SendMessage_(GadgetID(1),#BM_SETIMAGE,#image_icon,i2)
SendMessage_(GadgetID(3),#BM_SETIMAGE,#image_icon,i1)
SendMessage_(GadgetID(4),#BM_SETIMAGE,#image_icon,i2)
While WindowEvent():Wend
;{XP-Style?
hDC=GetWindowDC_(GadgetID(2))
c1=GetPixel_(hDC,0,0)
c2=GetPixel_(hDC,Box\w-1,0)
c3=GetPixel_(hDC,Box\w-1,Box\h-1)
c4=GetPixel_(hDC,0,Box\h-1)
If c1=c2 And c1=c3 And c1=c4
XPStyle=#True
ResizeGadget(0, 0,0 ,Box\w+2,Box\h+2)
ResizeGadget(1,Box\w+2,0 ,Box\w+2,Box\h+2)
ResizeGadget(2, 0,Box\h+2,Box\w+2,Box\h+2)
ResizeGadget(3,Box\w+2,Box\h+2,Box\w+2,Box\h+2)
While WindowEvent():Wend
Else
XPStyle=#False
EndIf
;}
Icon1=CreateIcon(0,0,4,WindowID())
Icon2=CreateIcon(1,1,5,WindowID())
Icon3=CreateIcon(2,2,4,WindowID())
Icon4=CreateIcon(3,3,5,WindowID())
;Repeat:WaitWindowEvent():ForEver
CloseWindow(0)
EndIf
EndIf
;}
If OpenWindow(1,0,0,200,200,#PB_Window_ScreenCentered|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SystemMenu|#PB_Window_SizeGadget,"Test 1")
AddTitleButton(WindowID(1),Icon1,Icon2,Icon3,Icon4,0,"Buttontest")
If OpenWindow(2,WindowX()+200,WindowY(),200,200,#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SystemMenu,"Test 2")
AddTitleButton(WindowID(2),Icon1,Icon2,Icon3,Icon4,#PB_Button_Toggle,"ToggleTest")
If CreateGadgetList(WindowID())
ButtonImageGadget(0,0,0,100,50,UseImage(4))
ButtonImageGadget(1,0,50,100,50,UseImage(5))
ButtonGadget(2,0,100,100,20,"Test",#PB_Button_Toggle)
EndIf
Repeat
event=WaitWindowEvent()
If event=#TitleButton_ChangeState
MessageRequester("Hallo","Window 'Test "+Str(EventWindowID())+"'"+Chr(10)+"ButtonState:"+Str(EventwParam()))
EndIf
Until event=#PB_Event_CloseWindow
EndIf
EndIf
The program need the pictures of the zip.