An Interesting Window

Share your advanced PureBasic knowledge/code with the community.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

An Interesting Window

Post by yrreti »

(Using XP Pro PB 4.51 and posting this before I go to work)
Have you ever wanted to change the Windows Title bar but couldn't because of it's limitations.
For instance, add a BMP image to it, or display a foreign language which it won't display normally?
What brought this project about, is that I needed to display a title in Korean, and all I could get is
??? ???? ???. Korean text worked fine both in the code text and compiled, but would not work in the Title.
This program basically uses two windows, with the one acting as a home made title bar for the main
window. It can be moved, minimized, and closed, like a normal window.
The only things I wish I could change, is that you have to use #PB_Window_BorderLess as it doesn't
look good with a border.
Other then that, if you more experienced ones can find a better way, please show us.

Enjoy:

Code: Select all

Enumeration
  #Window_Main
  #Window_TB        ;Title Bar
EndEnumeration

Enumeration
  #Button_1
  #Button_2
  #Button_3
  #Image_0
  #MainMenu
EndEnumeration

Global img0

*unpacked = AllocateMemory(23286)
UnpackMemory(?PicPaktbar_test, *unpacked)
img0 = CatchImage(#PB_Any, *unpacked, 23286)

DataSection
  PicPaktbar_test:
  Data.b $4A,$43,$F6,$5A,$00,$00,$D0,$F3,$C9,$6C,$BF,$A9,$D0,$20,$69,$14,$D1,$6A,$12,$CA
  Data.b $08,$B0,$8B,$50,$C0,$AF,$46,$0E,$08,$01,$C4,$80,$8F,$01,$82,$A9,$00,$13,$78,$F4
  Data.b $57,$45,$08,$57,$57,$81,$03,$0C,$10,$10,$FE,$41,$3C,$BF,$FF,$48,$10,$EB,$FC,$1B
  Data.b $30,$C9,$A8,$FA,$1F,$F1,$A2,$FB,$02,$F1,$45,$FC,$70,$E9,$69,$99,$75,$80,$7D,$88
  Data.b $5D,$7C,$1A,$55,$33,$E6,$85,$6D,$54,$97,$76,$C5,$69,$5C,$89,$51,$C5,$66,$F7,$5C
  Data.b $7C,$D9,$18,$DD,$61,$9B,$88,$E7,$F5,$05,$02,$6B,$54,$1F,$F3,$BE,$B1,$90,$AC,$18
  Data.b $0C,$0F,$1C,$15,$86,$49,$10,$96,$DD,$42,$57,$95,$58,$76,$70,$D6,$5D,$19,$D5,$A1
  Data.b $F9,$D9,$45,$15,$82,$67,$A7,$59,$5F,$BF,$F6,$2D,$46,$3F,$6F,$74,$91,$52,$F7,$89
  Data.b $59,$3F,$54,$DD,$20,$1E,$EC,$28,$3C,$A4,$51,$0F,$E2,$45,$62,$71,$4D,$C8,$D1,$5B
  Data.b $76,$55,$18,$F7,$89,$D1,$83,$78,$5E,$CD,$0F,$B0,$88,$5D,$BE,$CB,$E5,$F2,$3C,$BB
  Data.b $41,$3C,$41,$3C,$AE,$1D,$74,$14,$B1,$FE,$8F,$9A,$C1,$22,$C4,$F2,$7B,$10,$2E,$10
  Data.b $8F,$BB,$E3,$9A,$90,$A3,$32,$AB,$CA,$E0,$87,$B6,$A8,$12,$AA,$03,$F3,$B3,$2F,$FF
  Data.b $A0,$3C,$96,$E3,$3B,$20,$0F,$C4,$A3,$8A,$F3,$46,$A3,$FC,$8B,$EB,$1B,$C4,$60,$74
  Data.b $AD,$15,$5E,$0D,$E2,$F9,$D9,$35,$A8,$55,$60,$56,$05,$E2,$23,$50,$74,$15,$85,$46
  Data.b $15,$7D,$55,$05,$E2,$F1,$55,$80,$5E,$F1,$3C,$8C,$9D,$18,$4A,$BE,$F8,$40,$3A,$10
  Data.b $8F,$AF,$FB,$2A,$E6,$CB,$8B,$BE,$68,$2E,$9E,$F3,$2B,$56,$F4,$BD,$B8,$0B,$B8,$FB
  Data.b $37,$BE,$2A,$FB,$02,$F1,$6C,$A3,$1E,$81,$FA,$02,$CC,$7A,$11,$1F,$C4,$F3,$E2,$51
  Data.b $99,$78,$08,$29,$55,$07,$47,$00,$74,$AD,$81,$78,$1E,$0C,$9C,$2B,$A4,$54,$2A,$C0
  Data.b $FC,$8B,$AF,$BC,$AD,$FC,$E3,$9A,$9C,$2B,$38,$BE,$F0,$A8,$34,$2E,$AF,$CC,$E7,$FC
  Data.b $E2,$2E,$A8,$02,$F1,$B8,$B3,$6B,$60,$EF,$30,$BB,$29,$AC,$10,$8F,$EF,$0B,$62,$4F
  Data.b $11,$3B,$FF,$0B,$CC,$2F,$20,$F5,$63,$2C,$0D,$E6,$17,$91,$D4,$13,$F8,$C5,$5C,$D9
  Data.b $A3,$72,$B4,$1C,$D7,$78,$75,$84,$1C,$F5,$5F,$FE,$79,$98,$F3,$E5,$1F,$26,$88,$54
  Data.b $DE,$23,$7D,$EA,$74,$DC,$FC,$F3,$78,$1D,$7E,$54,$9B,$50,$E2,$51,$FD,$60,$88,$AE
  Data.b $7F,$07,$BD,$84,$61,$AC,$54,$47,$E2,$1D,$16,$F5,$70,$5E,$88,$67,$55,$8E,$41,$78
  Data.b $D1,$1F,$3F,$3A,$77,$FE,$F9,$07,$E6,$C7,$4A,$1D,$F5,$A4,$07,$E2,$D9,$8D,$4D,$E6
  Data.b $65,$55,$5F,$05,$E8,$95,$AE,$15,$90,$17,$8F,$2A,$CA,$8A,$E5,$E8,$0F,$CC,$63,$33
  Data.b $EF,$A6,$CA,$8B,$2E,$FA,$BF,$11,$FC,$A3,$EC,$56,$B1,$8B,$8E,$6B,$16,$FA,$BE,$F2
  Data.b $0A,$83,$03,$CC,$3A,$08,$06,$F3,$E3,$AA,$5E,$12,$16,$F1,$BE,$02,$F1,$26,$01,$7A
  Data.b $45,$D7,$65,$87,$4F,$51,$57,$FE,$81,$FA,$E0,$D1,$15,$85,$E5,$CA,$79,$2F,$57,$B3
  Data.b $7A,$51,$D9,$8D,$C7,$15,$97,$DD,$80,$5E,$78,$5C,$53,$5A,$D1,$97,$77,$83,$5E,$71
  Data.b $55,$01,$05,$E2,$F1,$7D,$57,$07,$18,$DD,$67,$4F,$6D,$1D,$57,$5E,$15,$2D,$EC,$65
  Data.b $37,$BB,$3A,$77,$FE,$A7,$51,$73,$59,$1F,$D7,$20,$1E,$D5,$66,$37,$A4,$1F,$DD,$59
  Data.b $7F,$01,$1C,$F5,$1D,$20,$7E,$65,$D7,$B4,$C7,$15,$F5,$84,$A0,$57,$74,$8F,$EC,$5E
  Data.b $F1,$1D,$3D,$3C,$E7,$57,$5F,$15,$88,$47,$5F,$7F,$01,$E6,$DD,$55,$20,$9E,$00,$03
  Data.b $04,$42,$E4,$29,$90,$FF,$9E,$06,$79,$12,$A9,$90,$27,$42,$0E,$79,$32,$E4,$E4,$09
  Data.b $D1,$8A,$9E,$14,$79,$4A,$89,$91,$A7,$45,$1C,$79,$6A,$E4,$B4,$A2,$47,$9E,$9E,$22
  Data.b $79,$82,$69,$92,$27,$49,$2A,$79,$A2,$E4,$92,$27,$4B,$9E,$9E,$30,$AD,$E8,$49,$93
  Data.b $A7,$4C,$38,$79,$DA,$E4,$93,$A7,$4E,$9E,$2B,$FA,$E4,$C9,$29,$94,$27,$50,$46,$79
  Data.b $12,$E5,$94,$27,$52,$9E,$79,$32,$E5,$A9,$09,$D5,$8A,$4E,$54,$79,$4A,$E5,$95,$A7
  Data.b $55,$9E,$79,$6A,$E5,$89,$A2,$57,$9E,$5C,$62,$79,$82,$B5,$96,$27,$59,$9E,$79,$A2
  Data.b $E5,$69,$27,$5B,$9E,$6A,$70,$AD,$E8,$96,$97,$A7,$5C,$9E,$79,$DA,$E5,$49,$A7,$5E
  Data.b $9E,$78,$41,$3C,$F2,$B5,$04,$9C,$A7,$DF,$E8,$C8,$A1,$08,$55,$0D,$18,$75,$26,$20
  Data.b $1E,$DF,$2A,$5A,$F9,$F2,$20,$12,$F1,$BE,$00,$00,$00,$00
  PicPaktbar_testend:
EndDataSection


Global mx,my

mx=450
my=200

Procedure IsLeftPressed()
  If GetSystemMetrics_(#SM_SWAPBUTTON)
    key=#VK_RBUTTON
  Else
    key=#VK_LBUTTON
  EndIf
  ProcedureReturn GetAsyncKeyState_(key)&$8000
EndProcedure


Procedure OpenWindow_Window_MAIN()
  If OpenWindow(#Window_Main, mx, my+22, 405, 427, "",#PB_Window_BorderLess)
    CreateMenu(#MainMenu, WindowID(#Window_Main))
    MenuTitle("&Edit")
    MenuItem(111, "Undo" + Chr(9 ) + "Ctrl+z")
    MenuBar()
    MenuItem(112, "Cut" + Chr(9 ) + "Ctrl+X")
    MenuItem(113, "C&opy" + Chr(9 ) + "Ctrl+C")
    MenuItem(114, "Paste" + Chr(9 ) + "Ctrl+V")
    MenuBar()
    MenuItem(115, "Select &All" + Chr(9 ) + "Ctrl+A")
    MenuBar()
    MenuItem(101, "Find && Replace" + Chr(9 ) + "Ctrl+F")
    MenuBar()
    MenuItem(102, "Save");
    MenuBar()
    MenuItem(104, "Quit" + Chr(9) + "Ctrl+Q")
    StickyWindow(#Window_MAIN,1)
  EndIf
  If OpenWindow(#Window_TB, mx, my, 405, 22, "",#PB_Window_BorderLess,WindowID(#Window_Main))
    ButtonGadget(#Button_1, 357, 3, 16, 18, "_")
    ButtonGadget(#Button_2, 386, 3, 16, 18, "X")
    ButtonGadget(#Button_3, 0, 0, 0, 0, ""); used to remove dashed line around a previously selected button.
    ImageGadget(#Image_0, 0, 0, 386, 22, ImageID(img0))
    StickyWindow(#Window_TB,1)
  EndIf
EndProcedure

OpenWindow_Window_MAIN()
ot=0

Repeat
  Select WaitWindowEvent(5)    
  Case #PB_Event_Gadget
    Select EventGadget()
    Case #Button_1
      SetActiveGadget(#Button_3)
      SetWindowState(#Window_Main, #PB_Window_Minimize)
      HideWindow(#Window_TB, 1)      
      ot=1;Just do one time
    Case #Button_2
      Select EventWindow()
      Case #Window_TB
        CloseWindow(#Window_TB)
        CloseWindow(#Window_Main)
        End
      Default
      EndSelect
    Default
    EndSelect
  Case #PB_Event_CloseWindow
    Select EventWindow()
    Case #Window_TB
      CloseWindow(#Window_TB)
      CloseWindow(#Window_Main)
      End
    Default
    EndSelect
  EndSelect
  
  If GetWindowState(#Window_MAIN)=#PB_Window_Normal  And ot=1    
    HideWindow(#Window_TB, 0)
    ot=0
    md=0
  EndIf
  
  If GetActiveWindow() = #Window_TB
    i=IsLeftPressed()
    ;i = 32768 when left mouse button is down and goes to 0 when up.
    If i>0
      ;When you first click on window then get that x y point and then get WindowX and WindowY.
      ;Get distanve from WindowX and WindowY and set as a reference.  dx  and dy.
      ;Then as you move the mouse, use that reference.  dx  and dy to subtract frorm wmx and wmy.
      nx=DesktopMouseX();will always be > WindowX
      ny=DesktopMouseY()
      If md=0;Another just do one time on first mouse down to get reference point.
        wmx = WindowX(#Window_TB)
        wmy = WindowY(#Window_TB)
        dx=nx-wmx
        dy=ny-wmy
      EndIf
      md=1
      
      mx=nx-dx
      my=ny-dy
      ResizeWindow(#Window_TB, mx, my, 405, 22)
      ResizeWindow(#Window_MAIN, mx, my+22, 405, 427)      
    Else
      md=0
      SetActiveWindow(#Window_MAIN)
    EndIf
  EndIf  
  
ForEver
Last edited by yrreti on Sun Jan 16, 2011 1:23 pm, edited 2 times in total.
User avatar
pcfreak
User
User
Posts: 75
Joined: Sat May 22, 2004 1:38 am

Re: An Interesting Window

Post by pcfreak »

you might want to change

Code: Select all

If OpenWindow(#Window_TB, mx, my, 405, 22, "",#PB_Window_BorderLess,#Window_Main)
to

Code: Select all

If OpenWindow(#Window_TB, mx, my, 405, 22, "",#PB_Window_BorderLess,WindowID(#Window_Main))
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: An Interesting Window

Post by yrreti »

Thanks pcfreak,
Your absolutely right. That one slipped by me, changing #Window_Main) to WindowID(#Window_Main))
like it should be, took care of the two boxes displayed on the lower Task bar. Now just one shows.
Thanks

* * * * * ( I just put these changes in the first post already ) * * * * * *
you might want to change
Code: Select all
If OpenWindow(#Window_TB, mx, my, 405, 22, "",#PB_Window_BorderLess,#Window_Main)
to
Code: Select all
If OpenWindow(#Window_TB, mx, my, 405, 22, "",#PB_Window_BorderLess,WindowID(#Window_Main))
I just noticed another small error: (I forgot to clear the one time variables here)
Change this code:

Code: Select all

  
If GetWindowState(#Window_MAIN)=#PB_Window_Normal  And ot=1    
    HideWindow(#Window_TB, 0)
 EndIf
to this:
Change this code:

Code: Select all

  
If GetWindowState(#Window_MAIN)=#PB_Window_Normal  And ot=1    
    HideWindow(#Window_TB, 0)
    ot=0
    md=0
 EndIf
Thanks
Post Reply