Page 1 of 1

EditorGadget problems with AnimateWindow

Posted: Thu Oct 02, 2008 11:54 am
by PB
If you run this, the window animates but the EditorGadget background is not
green and the text isn't seen. If you select the text you can see it, but only
one line of the EditorGadget becomes green. Also, shouldn't it be green
while animating?

Code: Select all

If OpenWindow(0,300,300,470,120,"EditorGadget is not green",#PB_Window_Invisible|#PB_Window_SystemMenu)
  EditorGadget(0,10,10,450,100)
    SetGadgetColor(0,#PB_Gadget_BackColor,#Green)
    SetGadgetText(0,"You can't see this until you select it.")
  AnimateWindow_(WindowID(0),250,#AW_CENTER)
  SetForegroundWindow_(WindowID(0))
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf

Posted: Thu Oct 02, 2008 12:26 pm
by Fluid Byte
This is a "bug" related to AnimateWindow_(), not PureBasic.

Try this:

Code: Select all

If OpenWindow(0,300,300,470,120,"EditorGadget is not green",#PB_Window_Invisible|#PB_Window_SystemMenu)
  EditorGadget(0,10,10,450,100)
    SetGadgetColor(0,#PB_Gadget_BackColor,#Green)
    SetGadgetText(0,"You can't see this until you select it.")
  AnimateWindow_(WindowID(0),250,#AW_CENTER)
  SetForegroundWindow_(WindowID(0))
  InvalidateRect_(WindowID(0),0,0)
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf 

Posted: Thu Oct 02, 2008 12:40 pm
by PB
I thought that might be the case, but StringGadgets work fine with the same
code, and EditorGadgets are supposed to be superior to StringGadgets.

Posted: Thu Oct 02, 2008 12:47 pm
by Fred
Unfortunately, EditorGadget() uses "RichEdit" class which is more complex than the "Edit" class and doesn't seems to support the WM_PRINT message properly.

Posted: Thu Oct 02, 2008 1:25 pm
by PB
Thanks for the explanation. (And thanks for fixing #AW_BLEND too). ;)

Posted: Thu Oct 02, 2008 2:35 pm
by Fluid Byte
PB wrote:I thought that might be the case, but StringGadgets work fine with the same
code, and EditorGadgets are supposed to be superior to StringGadgets.
Just like a said, an issue with AnimateWindow(), not PB. But I don't see the problem, just put an

Code: Select all

InvalidateRect_(WindowID(0),0,0) 
after calling AnimateWindow() and it behaves exactly as wanted.

PS: Not need for SetForegroundWindow_(), just add the #AW_ACTIVATE flag.

Posted: Thu Oct 02, 2008 10:26 pm
by PB
The problem is cosmetic: with a slow delay (500ms or more) you can easily
see that the EditorGadget is not green while it's animating. But no biggie,
I'll make it animate at 250ms and use #WM_ACTIVATE and it won't be so
bad. :)

Posted: Fri Oct 03, 2008 12:04 am
by Fluid Byte
That's right, just noticed that too. But you are not alone here. I searched the web a little and seems to be a common problem no mater what the language is. Unfortuneatly there is no proper fix I'd know of at the moment.

So I was thinking about writing my own AnimateWindow() procedure but first I need to find a way to capture a RichEdit control in it's correctly updated state. Seems to be a tuff nut since I tried serveral techniques yet and none of them worked. But don't worry, I still have an ace up my sleeve. :wink:

Posted: Mon Oct 06, 2008 2:58 am
by Sparkie
Two ways I can think of that will work. They are cheats but the user will never know. ;)

Both snippets tested on XP only.

1. Use a StringGadget during Animation then swap it out in favor of the EditorGadget afterwards.

Code: Select all

If OpenWindow(0, -65000, -65000, 470, 120, "Animate Test", #PB_Window_SystemMenu) 
  ShowWindow_(WindowID(0), #SW_HIDE)
  ResizeWindow(0, 100, 100, #PB_Ignore, #PB_Ignore)
  EditorGadget(0, 10, 10, 450, 100) 
  HideGadget(0, 1)
  SetGadgetColor(0, #PB_Gadget_BackColor, #Green) 
  SetGadgetText(0, "You can see this while Animation is in progress.") 
  StringGadget(1, 10, 10, 450, 100, "You can see this while Animation is in progress.")
  SetGadgetColor(1, #PB_Gadget_BackColor, #Green) 
  AnimateWindow_(WindowID(0), 1000, #AW_CENTER | #AW_ACTIVATE)
  FreeGadget(1)
  HideGadget(0, 0)
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow 
EndIf 
2. If you need the extra formatting options that come with the EditorGadget, then use PrintWindow API (Win 2k and later only). You then grab just the EditorGadget bits and place it in an ImageGadget which will animate as you desire. When animation is complete you swap out the ImageGadget for your EditorGadget.

Code: Select all

If OSVersion() < #PB_OS_Windows_2000
  End
Else
  Prototype.l pPrintWindow(hwnd.l, hdc.l, lFlags.l) 
  hLib = OpenLibrary(#PB_Any , "user32.dll") 
  Global _PrintWindow.pPrintWindow = GetFunction(hLib , "PrintWindow") 
EndIf

Procedure DoAnimation(hwnd)
  GetWindowRect_(WindowID(0), @winRc.RECT)
  x = GadgetX(0) + GetSystemMetrics_(#SM_CXFIXEDFRAME)
  y = GadgetY(0) + GetSystemMetrics_(#SM_CYCAPTION) + GetSystemMetrics_(#SM_CXFIXEDFRAME)
  w = winRc\right - winRc\left
  h = winRc\bottom - winRc\top
  If w > 0 And h > 0
    dummyImg = CreateImage(#PB_Any, w, h)
    destDC = StartDrawing(ImageOutput(dummyImg))
    _PrintWindow(hwnd, destDC, 0)
    StopDrawing()
    CreateImage(#PB_Any, w, h)
    clientImg = GrabImage(dummyImg, #PB_Any, x, y, w, h)
    HideGadget(0, 1)
    dummy = ImageGadget(#PB_Any, 10, 10, 450, 100, ImageID(clientImg))
  EndIf
  ShowWindow_(WindowID(0), #SW_HIDE)
  ResizeWindow(0, 30, 30, 470, 120)
  AnimateWindow_(WindowID(0), 1000, #AW_CENTER | #AW_ACTIVATE) 
  HideGadget(0, 0)
  FreeGadget(dummy)
EndProcedure
  
If OpenWindow(0, -65000, -65000, 470, 120, "Animate Test", #PB_Window_SystemMenu) 
  EditorGadget(0, 10, 10, 450, 100) 
  SetGadgetColor(0, #PB_Gadget_BackColor, #Green) 
  SetGadgetText(0, "You can see this while Animation is in progress.") 
  cf.CHARFORMAT
  cf\cbSize = SizeOf(cf)
  cf\dwMask = #CFM_SIZE
  cf\yHeight = 400
  SendMessage_(GadgetID(0), #EM_SETSEL, 23, 32)
  SendMessage_(GadgetID(0), #EM_SETCHARFORMAT, #SCF_SELECTION, cf)
  SendMessage_(GadgetID(0), #EM_SETSEL, -1, 0)
  DoAnimation(WindowID(0))
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow 
EndIf 

Posted: Mon Oct 06, 2008 3:15 am
by PB
> Use a StringGadget during Animation then swap it out in favor of the EditorGadget afterwards

I like, I like! :D Good thinking, Sparkie.

Posted: Mon Oct 06, 2008 8:20 pm
by Fluid Byte
Nice cheat Sparkie, nice indeed! :o