Announcement

Collapse
No announcement yet.

Background paintiing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Background paintiing

    Code:
    --Global
    User32Library = Library.Load("user32.dll");
    Gdi32Library = Library.Load("Gdi32.dll");
    BOOL = INT
    HDC = INT
    RECT = MemoryEx.DefineStruct{
    	LONG 		"left";
    	LONG 		"top";
    	LONG 		"right";
        LONG 		"bottom";
    };
    PAINTSTRUCT = MemoryEx.DefineStruct{
      HDC  "hdc";
      BOOL "fErase";
      RECT "rcPaint";
      BOOL "fRestore";
      BOOL "fIncUpdate";
      BYTE "rgbReserved";
    }
    HostWindow = {}
    HostWindow.CreateHost = function(x,y,w,h)
      local WS_EX_CLIENTEDGE = 0x00000200;
      local hWnd = Application.GetWndHandle();
      local WS_CHILD = 0x40000000;
      local WS_VISIBLE = 0x10000000;
      local nstyle = WS_CHILD + WS_VISIBLE;
      local bhdl = User32Library.CreateWindowExA(WS_EX_CLIENTEDGE,32770,"",nstyle,x,y,w,h,hWnd,0,0,0)
      if bhdl and (type(bhdl) ~= "number") then
       return false, "Can't create container"
      end
      HostWindow.HostHandle = bhdl
      local s = Subclass.Create(HostWindow.HostHandle, function(hWnd, uMsg, wParam, lParam)
       if(uMsg == 0x0014)then--WM_ERASEBKGND
         local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(PAINTSTRUCT) + 100);
         if not lpBuff then
          return 0
         end
         local hStruct = MemoryEx.AssignStruct(lpBuff + 50, PAINTSTRUCT);
          if not hStruct then
          return 0
         end
         local x = User32Library.BeginPaint(hWnd,hStruct:GetPointer())
         if (x ~= nil and x > 0) then
          local x = User32Library.FillRect(wParam,hStruct.rcPaint:GetPointer(),HostWindow.BrushHandle)
          User32Library.EndPaint(hWnd,hStruct:GetPointer())
          hStruct:Close();
          MemoryEx.Free(lpBuff);
          return 0
         else
          hStruct:Close();
          MemoryEx.Free(lpBuff);
          return 0
         end
       end
      return Subclass.OldWinProc(hWnd, uMsg, wParam, lParam);
      end)
      local x,y = HostWindow.CreateBrush()
      if not x then
       return false, "Can't create brush"
      else
       HostWindow.BrushHandle = y
      end
       HostWindow.BringToTop(HostWindow.HostHandle)
      return true, "OK"
    end;
    HostWindow.BringToTop = function(SWnd)
      if tonumber(User32Library.BringWindowToTop(SWnd)) == 0 then
       return false, "Can't bring to top"
      else
       return true, "OK"
      end
    end;
    HostWindow.CreateBrush = function()
     local hBrush = Gdi32Library.CreateSolidBrush(16777215)
     if hBrush and (type(hBrush) ~= "number") then
      return false, "Can't create brush"
     else
      return true, hBrush
     end
    end;
    
    --Button / On Show
    
    HostWindow.CreateHost(10,10,400,300)
    
    --Maximize then window shows window mirror, minimize then restore and background works
    Anyone have any idea why this is not working as planed? its supposed to simply paint the window background colour white but it fails to update without the main window being re-sized but if you maximize then it draws an image of the main window within the created window yet if you minimize then restore it looks like it works as it should do.

  • #2
    Hi

    WM_ERASEBKGND is not right event to do drawing
    you should use WM_PAINT

    WM_ERASEBKGND means that the window's background is being erased/redrawed
    this event expects a brush to use to draw background , in general you will not need to handle this event , Windows will use default theme color to draw window background

    you should use WM_PAINT to draw content over this
    amsplugins.com Is Closed.

    Facebook Page

    Comment


    • #3
      Cheers, WM_PAINT kind of does the trick but occasionally the background becomes the default window colour again on resizing or on creation, what I'm trying to do is create a host window for a combo-box and a couple of inputs without using the shape plugin as a background, 32770 is the dialog class window that seems to be the best type for the job as there is no carrot but by default the background color is grey and I want white lol

      Comment


      • #4
        InvalidateRect() function should be called in some cases WM_SIZE event gets called whenever window size changes
        so you should call that function in WM_SIZE event , and after window is created

        you can use NULL as lpRect parameter

        in addition , use STATIC as window class when you will use it as a dummy window

        STATIC class is recomended for host windows or custom controls
        amsplugins.com Is Closed.

        Facebook Page

        Comment


        • #5
          Cheers mate, WM_SIZE seems to have caught the odd occasion t would not paint.

          Comment


          • #6
            in addition , if you are going to follow my advise and will use STATIC then
            you should also handle WM_GETTEXTLENGTH and invalidate client area

            otherwise , you might find yourself while asking 'where did my drawings go again'
            amsplugins.com Is Closed.

            Facebook Page

            Comment


            • #7
              I did indeed swap it to static, you know AMS makes things real easy as a simple thing like this is a mission

              Comment

              Working...
              X