Author Topic: Resizing background picture in MDI client ?  (Read 12864 times)

K_F

  • Member
  • *****
  • Posts: 1483
  • Anybody out there?
Resizing background picture in MDI client ?
« on: December 28, 2013, 07:22:30 PM »
This is in the MDI WinMain proc.. where I pick up any size changes in the main window, then attempt to change/stretch the background picture.
This little sequence fails to resize (SetWidth and SetHeight) the bmp (resource) picture.
I'd assume the hBmp handle is valid ?

Is this the right way to do it (easycode) or, does one have to go the DC method route

Quote
   .elseif uMsg == WM_SIZE

      xor      eax, eax
      LoWord   lParam
      mov      iWidth, eax
      xor      eax, eax
      HiWord   lParam
      mov      iHeight, eax


      invoke   GetMDIClient, hWnd
      mov      hClient, eax
      .if   eax != NULL

         invoke   GetPicture, hClient
         .if   eax != NULL
            mov      hBmp, eax

            invoke   SetWidth, hBmp, iWidth
            .if   eax == FALSE
               mov      eax, iWidth
               invoke   dwtoa, eax, ADDR sz_DW1
               Invoke MessageBox, hWnd, ADDR sz_DW1, TextAddr("SetWidth Fail"), MB_OK
            .endif

            invoke   SetHeight, hBmp, iHeight
            .if   eax == FALSE
               mov      eax, iHeight
               invoke   dwtoa, eax, ADDR sz_DW1
               Invoke MessageBox, hWnd, ADDR sz_DW1, TextAddr("SetHeight FAIL"), MB_OK
            .endif

         .else
            invoke   dwtoa, eax, ADDR sz_DW1
            Invoke MessageBox, hWnd, ADDR sz_DW1, TextAddr("GetPicture Fail"), MB_OK
         .endif
      .else
            invoke   dwtoa, eax, ADDR sz_DW1
            Invoke MessageBox, hWnd, ADDR sz_DW1, TextAddr("GetMDIClient Fail"), MB_OK
      .endif

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #1 on: December 28, 2013, 10:44:35 PM »
i wouldn't change the size of anything   :P

1) during WM_SIZE, store width and height into a _SIZE structure
    you only need to update the structure if wParam is either SIZE_MAXIMIZED or SIZE_RESTORED
2) during WM_PAINT, StretchBlt the working image into a memory DC that is sized the same as the frame window client
    BitBlt from the memory DC to the window DC, only that portion that is requested by the RECT in PAINTSTRUCT

because you are always painting the entire client, use a NULL_BRUSH in the frame class background color

voila - no flicker

K_F

  • Member
  • *****
  • Posts: 1483
  • Anybody out there?
Re: Resizing background picture in MDI client ?
« Reply #2 on: December 29, 2013, 03:08:05 AM »
ah Ok :)
I tried 2) but with no results... maybe I'm not doing it right..

I'll carry on pluggin...
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #3 on: December 29, 2013, 04:41:57 AM »
it's been a while, but i think there are 3 "tiers" in the MDI hierarchy, Frame, Client, Child
i think the Frame window is the one you want
let me see what i can do   :P

rsala

  • Moderator
  • Member
  • *****
  • Posts: 296
    • Easy Code
Re: Resizing background picture in MDI client ?
« Reply #4 on: December 29, 2013, 07:01:05 AM »
Hi,

The SetWidth and SetHeight methods are for resizing windows and child controls. You can not resize a bitmap with them.

First of all, intercept the WM_ERASEBKGND and just return TRUE for no further processing:

.ElseIf uMsg == WM_ERASEBKGND
    Mov Eax, TRUE
    Ret


Then intercept the WM_PAINT message and draw any picture you like following the dendave instructions. Finally, also return TRUE for no further processing:

.ElseIf uMsg == WM_PAINT
    ; Draw the picture
    Mov Eax, TRUE
    Ret



EC coder

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #5 on: December 29, 2013, 08:11:11 AM »
what is the color-depth (bits per pixel) of your BMP image ?

K_F

  • Member
  • *****
  • Posts: 1483
  • Anybody out there?
Re: Resizing background picture in MDI client ?
« Reply #6 on: December 29, 2013, 05:31:24 PM »
Hi, The SetWidth and SetHeight methods are for resizing windows and child controls. You can not resize a bitmap with them.
I thought it could as I was playing with the MDI picture property/object.. which is a bitmap ? Can I put a JPG (or other pic format) file there then ?

Easycode help file on SetWidth/SetHeight
Quote
REMARKS: The lHeight value is intepreted as pixels or twips units depending on the ScaleMode property. For Window, MDIWindow and Picture objects it depends on its own ScaleMode property, while for any other object it depends on the ScaleMode property of its parent (if its parent is a Window, MDIWindow or Picture), or its first ascendant having the ScaleMode property.

@Dave.. 8Bits at the moment..

 :t

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #7 on: December 29, 2013, 06:53:18 PM »
ok - i see where the issue is - lol

as i mentioned earlier, the MDI hierarchy looks like this
Code: [Select]
Frame
----MDIClient
    ----MDIChild
    ----MDIChild

the MDIClient is a predefined system class
the background brush color is always COLOR_APPWORKSPACE

in other words, whatever you paint into the client area of the Frame window is overdrawn by the MDIClient window

now, if we just wanted to change the color, we could probably do it with SetClassLong
but i think to paint an image, we have to subclass the MDIClient window

i hate subclassing system classes   :lol:
you're always leaving yourself vulnerable to changes in different versions of windows (especially win7 AeroGlass theme)
in fact, i have an app where i wanted special buttons
rather than subclassing the (damned) button class, i wrote my own "DaveButton" class/window procedure - lol
i don't want to get into that for the MDIClient, although it could be done
so, we'll try subclassing and test it on different OS versions   :(

TWell

  • Member
  • ****
  • Posts: 748
Re: Resizing background picture in MDI client ?
« Reply #8 on: December 29, 2013, 08:35:47 PM »
After downloading that MDI example, nothing to say to this topic :icon_confused:
« Last Edit: December 30, 2013, 12:00:05 AM by TWell »

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #9 on: December 29, 2013, 09:21:00 PM »
that doesn't seem to work like i think it ought to   :P

K_F

  • Member
  • *****
  • Posts: 1483
  • Anybody out there?
Re: Resizing background picture in MDI client ?
« Reply #10 on: December 30, 2013, 05:56:17 AM »
I've reverted back to a simple visual window and have it working...
The Zip file (easycode project) is a bit large as I'm using a 800KB bmp file

I made a mistake in not using the hInstance on the LoadBitMap, and used hWnd instead  :icon_eek:
I also had to Invalidate the Client area as it was not BLT'ing to the whole area.
I'll now work backwards towards the MDI client background...
 :biggrin: :lol:

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #11 on: December 30, 2013, 06:32:17 AM »
it's big because it's a 24-bit image   :P

but - CPU usage is almost 50%
you may be replying to WM_PAINT without validating the rectangle (happens if BeginPaint/EndPaint aren't used)

K_F

  • Member
  • *****
  • Posts: 1483
  • Anybody out there?
Re: Resizing background picture in MDI client ?
« Reply #12 on: December 30, 2013, 06:44:00 AM »
Thanks.. I'll look at that
:)
Mine's sitting at 13%.. that's a bit high isn't it ??
What normal CPU usage for an idling application... ?
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Resizing background picture in MDI client ?
« Reply #13 on: December 30, 2013, 07:19:45 AM »
once the picture has been painted, it should go to near 0

there are a couple ways to deal with it
in the WM_PAINT code, call BeginPaint/EndPaint (if needed)
if those aren't needed, you can call ValidateRect with NULL as lpRect
another way is to pass to default proc after painting - it validates the rectangle, also

K_F

  • Member
  • *****
  • Posts: 1483
  • Anybody out there?
Re: Resizing background picture in MDI client ?
« Reply #14 on: December 30, 2013, 07:28:49 AM »
Found it..

It's this...
invoke   InvalidateRect ,hWnd, NULL, TRUE   ;Redraw the whole client area, instead of a portion


but without this, the background is not drawn properly !!
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'