News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Resizing background picture in MDI client ?

Started by K_F, December 28, 2013, 07:22:30 PM

Previous topic - Next topic

K_F

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

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

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

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

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

what is the color-depth (bits per pixel) of your BMP image ?

K_F

Quote from: rsala 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.
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
QuoteREMARKS: 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

ok - i see where the issue is - lol

as i mentioned earlier, the MDI hierarchy looks like this
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

#8
After downloading that MDI example, nothing to say to this topic :icon_confused:

dedndave

that doesn't seem to work like i think it ought to   :P

K_F

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

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

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

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

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....'