Window without Close Button [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Window without Close Button [Windows]

Post by RASHAD »

Esc to Quit

Code: Select all


Global winID

Import "window.lib"   
  CompilerIf #PB_Compiler_Version  < 550 And #PB_Compiler_Unicode 
    _PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent_UNICODE@16"
  CompilerElse
    _PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent@16"
  CompilerEndIf

  PB_Window_Icon
  PB_Window_Cursor
  PB_Window_Objects  
  PB_Object_GetOrAllocateID(*Object,id)  
EndImport

Procedure _OpenWindow(id,x,y,cx,cy,title.s,flags=#WS_VISIBLE |#WS_OVERLAPPEDWINDOW,parent=0)
  Protected wnd.wndclass
  Protected classname.s = "Window_CLASS"
  Protected *WinObj.integer
  Protected hWnd.i
  Protected rc.rect 
  
  With wnd
    \style          = #CS_HREDRAW | #CS_VREDRAW | #CS_NOCLOSE ;| #CS_DROPSHADOW 
    \lpfnWndProc    = @_PB_Window_ProcessEvent() 
    \hInstance      = GetModuleHandle_(0)
    \hIcon          = PB_Window_Icon
    \hCursor        = PB_Window_Cursor
    \lpszClassName  = @classname
    \hbrBackground  = #COLOR_WINDOW
    \cbWndExtra     = 0
    \cbClsExtra     = 0
  EndWith
  
  If RegisterClass_(wnd)
    
    SetRect_(rc,0,0,cx,cy)
    
    AdjustWindowRectEx_(rc,flags,0,#WS_EX_WINDOWEDGE)
    
    If x = #PB_Ignore Or y = #PB_Ignore
      x = #CW_USEDEFAULT
      y = #CW_USEDEFAULT
    EndIf
    
    hWnd = CreateWindowEx_(#WS_EX_WINDOWEDGE,classname,title,flags,x,y, rc\right-rc\left,rc\bottom-rc\top,parent,0,GetModuleHandle_(0),0)
    
    If hWnd 
      *WinObj   = PB_Object_GetOrAllocateID(PB_Window_Objects,id)
      *WinObj\i = hWnd  

      If id = #PB_Any
        SetProp_(hWnd,"Pb_WindowID",*WinObj+1) 
      Else
        SetProp_(hWnd,"Pb_WindowID",id+1) 
      EndIf 

    Else 
      UnregisterClass_(GetModuleHandle_(0),classname)
    EndIf 
    
  EndIf
  If id = #PB_Any
    id = *WinObj
  Else
    id = hWnd 
  EndIf
  winID = id
  ProcedureReturn winID
EndProcedure
  
 _OpenWindow(0,#PB_Ignore,#PB_Ignore,600,400,"Windows No Close")
 SetWindowLongPtr_(winID,#GWL_STYLE	,GetWindowLongPtr_(winID,#GWL_STYLE	) &~ #WS_MAXIMIZEBOX)
 HideWindow(0,0,#PB_Window_ScreenCentered)
 CatchImage(0, ?Icon)
 SendMessage_(winID,#WM_SETICON,0,ImageID(0))  
 StickyWindow(0,1)
 AddKeyboardShortcut(0,#PB_Shortcut_Escape ,10)
  
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Menu
      Select EventMenu()
        Case 10
          End
      EndSelect
  EndSelect
ForEver
  
DataSection
  Icon:
    Data.b 0, 0, 1, 0, 1, 0, 32, 32, 4, 0, 0, 0, 0, 0, 232, 2, 0, 0, 22, 0, 0, 0, 40, 0, 0, 0, 32, 0, 0, 0, 64, 0, 0, 0, 1, 0, 4, 0, 0, 0
    Data.b 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 128, 0, 0, 0, 128, 128, 0, 128, 0
    Data.b 0, 0, 128, 0, 128, 0, 128, 128, 0, 0, 128, 128, 128, 0, 192, 192, 192, 0, 0, 0, 255, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 255
    Data.b 0, 0, 255, 255, 255, 0, 0, 9, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 144, 0, 0, 159, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 249, 0, 9, 255
    Data.b 255, 255, 255, 135, 119, 255, 255, 135, 120, 255, 255, 255, 255, 144, 159, 255, 255, 255, 247, 7, 135, 255, 255, 72, 112, 8, 255, 255, 255, 249, 159, 255, 255, 255, 119, 136, 136, 127, 247, 120
    Data.b 136, 112, 255, 255, 255, 249, 159, 255, 255, 255, 120, 136, 136, 112, 0, 136, 136, 135, 255, 255, 255, 249, 159, 255, 255, 255, 135, 136, 136, 136, 136, 136, 136, 136, 255, 255, 255, 249, 159, 255
    Data.b 255, 255, 128, 136, 136, 136, 136, 136, 136, 120, 255, 255, 255, 249, 159, 255, 119, 136, 7, 136, 136, 136, 136, 136, 136, 119, 248, 119, 255, 249, 159, 240, 120, 112, 120, 136, 136, 136, 136, 136
    Data.b 136, 135, 7, 119, 15, 249, 159, 128, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 8, 249, 159, 119, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 119, 249, 159, 120
    Data.b 136, 136, 136, 136, 136, 135, 120, 136, 136, 136, 136, 136, 128, 249, 159, 119, 136, 136, 136, 136, 135, 15, 240, 120, 136, 136, 136, 136, 112, 249, 159, 248, 7, 136, 136, 136, 112, 255, 255, 7
    Data.b 136, 136, 136, 112, 143, 249, 159, 255, 240, 136, 136, 136, 0, 255, 255, 0, 136, 136, 136, 15, 255, 249, 159, 255, 240, 136, 136, 136, 0, 255, 255, 0, 136, 136, 136, 15, 255, 249, 159, 255
    Data.b 116, 136, 136, 136, 112, 15, 255, 7, 136, 136, 136, 7, 255, 249, 159, 128, 120, 136, 136, 136, 128, 0, 0, 8, 136, 136, 136, 135, 8, 249, 159, 8, 136, 136, 255, 248, 136, 112, 7, 136
    Data.b 136, 136, 136, 136, 128, 249, 159, 120, 143, 255, 255, 255, 255, 136, 136, 143, 255, 255, 255, 136, 128, 249, 159, 132, 136, 143, 255, 255, 255, 255, 255, 255, 255, 255, 136, 136, 120, 249, 159, 240
    Data.b 136, 135, 143, 255, 255, 255, 255, 255, 255, 248, 120, 136, 15, 249, 159, 248, 119, 135, 8, 255, 255, 255, 255, 255, 255, 128, 120, 119, 127, 249, 159, 255, 255, 255, 112, 255, 255, 255, 255, 255
    Data.b 255, 119, 255, 248, 255, 249, 159, 255, 255, 255, 135, 255, 255, 255, 255, 255, 255, 120, 255, 255, 136, 249, 159, 255, 255, 255, 120, 255, 255, 119, 119, 255, 255, 135, 255, 255, 255, 249, 159, 255
    Data.b 255, 255, 120, 255, 248, 120, 135, 143, 255, 128, 255, 255, 255, 249, 159, 255, 255, 255, 128, 120, 247, 143, 255, 127, 135, 8, 255, 255, 255, 249, 9, 255, 255, 255, 255, 119, 112, 255, 255, 119
    Data.b 119, 255, 255, 255, 255, 144, 0, 159, 255, 255, 255, 255, 143, 255, 255, 248, 255, 255, 255, 255, 249, 0, 0, 9, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 144, 0, 224, 0
    Data.b 0, 7, 192, 0, 0, 3, 128, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 1, 192, 0
    Data.b 0, 3, 224, 0, 0, 7
  Iconend:
EndDataSection

Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Window without Close Button [Windows]

Post by Dude »

Are you just wanting to disable (gray) the Close button? I feel like I'm missing something? :oops:

Code: Select all

OpenWindow(0,200,200,200,100,"test",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
EnableMenuItem_(GetSystemMenu_(WindowID(0),0),#SC_CLOSE,#MF_BYCOMMAND|#MF_DISABLED|#MF_GRAYED)
Repeat : WaitWindowEvent(1) : Until GetAsyncKeyState_(#VK_ESCAPE) & $8000
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Window without Close Button [Windows]

Post by RSBasic »

Hello RASHAD,

thank you for your code but the code doesn't work:
PureBasic - Linker error wrote:POLINK: error: Unresolved external symbol '_PB_Window_ProcessEvent@16'.

POLINK: fatal error: 1 unresolved external(s).
Tested with 5.60 (x64) and Windows 10.
Image
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 6249
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Window without Close Button [Windows]

Post by mk-soft »

RSBasic wrote:Hello RASHAD,

thank you for your code but the code doesn't work:
PureBasic - Linker error wrote:POLINK: error: Unresolved external symbol '_PB_Window_ProcessEvent@16'.

POLINK: fatal error: 1 unresolved external(s).
Tested with 5.60 (x64) and Windows 10.

Code: Select all

Import "window.lib"   
  CompilerIf #PB_Compiler_Version  < 550 And #PB_Compiler_Unicode 
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      _PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent_UNICODE@16"
    CompilerElse
      _PB_Window_ProcessEvent(a,b,c,d) As "PB_Window_ProcessEvent_UNICODE"
    CompilerEndIf
  CompilerElse
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      _PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent@16"
    CompilerElse
      _PB_Window_ProcessEvent(a,b,c,d) As "PB_Window_ProcessEvent"
    CompilerEndIf
  CompilerEndIf

  PB_Window_Icon
  PB_Window_Cursor
  PB_Window_Objects  
  PB_Object_GetOrAllocateID(*Object,id)  
EndImport
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Window without Close Button [Windows]

Post by RASHAD »

Thanks guys for reporting
And special thanks to mk-soft :)
Egypt my love
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Window without Close Button [Windows]

Post by RSBasic »

@mk-soft
Thank you for the code extension. It's working now.

@RASHAD
Thank you for your code but why don't disable with EnableMenuItem_()? The code with EnableMenuItem_() is much smaller.
But still interesting to see another way. :)
Image
Image
Post Reply