<font face="verdana,sans-serif">Hi guys,<br><br>When I close my application, it raises a  exception. Debugger stops on line 491 of Win32WSButtons.pp. I Don´t know how to debug it as it happens only when application terminate. If I make my code does not show any window, the exception doesn´t raises. Could someone help?<br>

<br>Code fragmentation is:<br><br><span style="font-family:courier new,monospace">function BitBtnWndProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;<br>    LParam: Windows.LParam): LResult; stdcall;<br>var<br>  Info: PWin32WindowInfo;<br>

  Control: TWinControl;<br>  ButtonImageList: BUTTON_IMAGELIST;<br>  ImageList: HIMAGELIST;<br>  LMessage: TLMessage;<br>begin<br>  Info := GetWin32WindowInfo(Window);<br>  if (Info = nil) or (Info^.WinControl = nil) then<br>

  begin<br>    Result := CallDefaultWindowProc(Window, Msg, WParam, LParam);<br>    Exit;<br>  end<br>  else<br>    Control := Info^.WinControl;<br><br>  case Msg of<br>    WM_DESTROY:<br>      begin<br>        if ThemeServices.ThemesAvailable and     // <<---------------------- S<font face="verdana,sans-serif">tops on this line....</font><br>

           (Windows.SendMessage(Window, BCM_GETIMAGELIST, 0, Windows.LPARAM(@ButtonImageList)) <> 0) then<br>        begin<br>          // delete and destroy button imagelist<br>          if ButtonImageList.himl <> 0 then<br>

          begin<br>            ImageList:=ButtonImageList.himl;<br>            ButtonImageList.himl:=0;<br>            Windows.SendMessage(Window, BCM_SETIMAGELIST, 0, Windows.LPARAM(@ButtonImageList));<br>            ImageList_Destroy(ImageList);<br>

          end;<br>        end;<br>        Result := WindowProc(Window, Msg, WParam, LParam);<br>      end;<br>    WM_GETFONT:<br>      begin<br>        Result := LResult(Control.Font.Reference.Handle);<br>      end;<br>    WM_UPDATEUISTATE:<br>

      begin<br>        Result := WindowProc(Window, Msg, WParam, LParam);<br>        DrawBitBtnImage(TBitBtn(Control), TBitBtn(Control).Caption);<br>      end;<br>    WM_PAINT,<br>    WM_ERASEBKGND:<br>      begin<br>        if not Control.DoubleBuffered then<br>

        begin<br>          LMessage.msg := Msg;<br>          LMessage.wParam := WParam;<br>          LMessage.lParam := LParam;<br>          LMessage.Result := 0;<br>          Result := DeliverMessage(Control, LMessage);<br>

        end<br>        else<br>          Result := WindowProc(Window, Msg, WParam, LParam);<br>      end;<br>    WM_PRINTCLIENT:<br>      Result := CallDefaultWindowProc(Window, Msg, WParam, LParam);<br>    else<br>      Result := WindowProc(Window, Msg, WParam, LParam);<br>

  end;<br>end; </span><br clear="all"></font>  <br>-- <br><font face="verdana, sans-serif">________________________________<br>William de Oliveira Ferreira<br></font>