EditorGadget problems with AnimateWindow

Windows specific forum
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

EditorGadget problems with AnimateWindow

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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 
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Fred
Administrator
Administrator
Posts: 18360
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks for the explanation. (And thanks for fixing #AW_BLEND too). ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Nice cheat Sparkie, nice indeed! :o
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply