What am I doing wrong? (Gadgets over graphic in a window)

Just starting out? Need help? Post your questions and find answers here.
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

What am I doing wrong? (Gadgets over graphic in a window)

Post by Seymour Clufley »

I've made a dialogue box. A graphically more glitzy version of an inputbox.

The graphic shows, and then the caption can be successfully drawn over it, but as soon as a gadget is added (whether it's the stringgadget or a button), the whole window turns grey!

I've split it up with delays so you can see it "in action":

"mmb" is the handle of the parent app (NOT written in PB)

Code: Select all

  caption$="Please type in some text:"
  defaulttext$="HERE"
  title$="Malfunctioning inputbox"
  
  font=LoadFont(#PB_Any,"Courier New",12,#PB_Font_Bold)
  SetGadgetFont(#PB_Default,FontID(font))
  
  winBox=OpenWindow(#PB_Any,0,0,500,125,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess);,mmb)
  EnableWindow_(mmb,#False)
  dialogue=WindowID(winBox)
  
  BGImage=ImageID(LoadImage(#PB_Any,"inputbox.bmp"))
  StartDrawing(WindowOutput(winBox))
  DrawImage(BGImage,0,0,500,125)
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(font))
  DrawText(5,2,title$,RGB(255,255,255))
  DrawText(5,28,caption$,RGB(255,255,255))
  StopDrawing()
  
  Delay(2000)
  MessageBeep_(#MB_ICONINFORMATION)
  
  CreateGadgetList(dialogue)
  
  string = StringGadget(#PB_Any,17,54,366,15,defaulttext$,#PB_String_BorderLess)
  okay=ImageID(LoadImage(#PB_Any,"ok button.bmp"))
  OK = ButtonImageGadget(#PB_Any,220,82,78,24,okay)
  cancel=ImageID(LoadImage(#PB_Any,"cancel button.bmp"))
  Cancel = ButtonImageGadget(#PB_Any,309,82,78,24,cancel)
  
  Delay(2000)
  
  GetAsyncKeyState_(#VK_RETURN) : GetAsyncKeyState_(#VK_ESCAPE) : StickyWindow(winBox,#True) : SetForegroundWindow_(dialogue)
  MessageBeep_(#MB_ICONWARNING)
  Repeat
      ev=WaitWindowEvent(1) : id=EventGadget() : ret=GetAsyncKeyState_(#VK_RETURN) : esc=GetAsyncKeyState_(#VK_ESCAPE)
      a=GetForegroundWindow_()
      
      press = WaitWindowEvent()
      
      If press = #PB_Event_Gadget
      
          Select EventGadget()
              Case OK
                  status=1
              Case Cancel
                  status=0
          EndSelect
          
      EndIf
      
  Until press=#PB_Event_CloseWindow Or EventGadget()=OK Or EventGadget()=Cancel
  
  ProcedureReturn=GetGadgetText(string)
  
  CloseWindow(winBox)
  EnableWindow_(mmb,#True)
Thanks for any help. I'm sure it must be something glaringly obvious.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

For Windows only...Try this:

1.) Create a brush...

Code: Select all

BGImage=ImageID(LoadImage(#PB_Any,"inputbox.bmp")) 
hBrush = CreatePatternBrush_(BGImage)
2.) Assign the brush to your window

Code: Select all

SetClassLong_(WindowID(winBox), #GCL_HBRBACKGROUND, hBrush)
3.) Delete the brush when you close the window

Code: Select all

DeleteObject_(hBrush)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Thanks, Sparkie.

Does the brush need to remain until the window is closed because Windows refreshes windows?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You are welcome...and yes, you are correct Seymour Clufley :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Also if you place a disabled imagegadget on your window you can put gadgets on it and they'll work fine. It's a crossplatform alternative to a background brush.
BERESHEIT
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Thanks for the tip. I had experimented with an imagegadget before for another purpose (the need to resize a window after adding gadgets, whilst preserving the background image) but it froze all the gadgets "above" it. I didn't know it was possible to disable the imagegadget - obviously that's what was wrong.
User avatar
Blue
Addict
Addict
Posts: 972
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post by Blue »

netmaestro wrote:Also if you place a disabled imagegadget on your window you can put gadgets on it and they'll work fine. It's a crossplatform alternative to a background brush.
I just happened on this answer by chance. It was an eye-opener....
Thanks for a great tip (at least, i think so: now I have to try it!!)

-- Just tried it: Fabulous. Works like a charm, and allows for a simple way to add background decoration to windows using only PB code.

some demo code available here: http://www.purebasic.fr/english/viewtop ... 208#213208

... but, still, I see the obvious need to learn Windows API calls to be able to code without a hand tied behind your back.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply