Change menubar location?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Change menubar location?

Post by Fluid Byte »

Here's the deal. I want to change the location of a menubar in my programm but there's currently no way to do that via an API command. At least I haven't found anything related.

So I tought myself to create a child window and append my menu there instead. Problem is that the menu is not shown with the #WS_CHILD style. It will show just fine with #WS_POPUP style and addtionally hide any window elements like the border and caption. Now there's the next problem. the #WS_CHILD and #WS_POPUP style can't be combined and thus I have to stick with #WS_POPUP alone but the main window and the menu window now behave like to seperate windows, not like parent and child.

Run this to see what I mean:

Code: Select all

Structure NCCALCSIZE_PARAMS
	rgrc.RECT[3]
	lppos.WINDOWPOS 
EndStructure

Procedure WindowCallback(hWnd.l,uMsg.l,wParam.l,lParam.l)
    Select uMsg
    	Case #WM_NCCALCSIZE
    	*pncc.NCCALCSIZE_PARAMS = lParam
    	
    	*pncc\rgrc[0]\top + 50
    EndSelect
     
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0,0,0,500,400,"untitled",#WS_OVERLAPPEDWINDOW | #WS_VISIBLE | 1)

GetClientRect_(WindowID(0),wrc.RECT)
Result = OpenWindow(#PB_Any,0,50,wrc\right,100,"",#WS_POPUP,WindowID(0))
SetWindowColor(Result,255)
SetParent_(WindowID(Result),WindowID(0))

CreateMenu(0,WindowID(Result))
MenuTitle("File") : For i=1 To 8 : MenuItem(0,"Menu Item #" + Str(i)) : Next
MenuTitle("Edit") : For i=1 To 8 : MenuItem(0,"Menu Item #" + Str(i)) : Next
MenuTitle("Help") : For i=1 To 8 : MenuItem(0,"Menu Item #" + Str(i)) : Next

SetWindowCallback(@WindowCallback())

HideWindow(0,0)

While WaitWindowEvent() ! 16 : Wend
Any tips are welcome, I'm lost!

EDIT: Forgot to mention I also tried to change the menubar location by modifying the client area with #WM_NCCALCSIZE message. Didn't work as well.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You can't move menubars around. (Unless you move the window as well.)
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

found here :
http://purebasic.hmt-forum.com/viewtopi ... u+position

Code: Select all

#Window = 0


Procedure CreateMenuEx(ID.l, WindowID.l, Position.l)
  ; ID = Numéro du menu
  ; WindowID = fenêtre associé au menu
  ; Position = Position du menu sur la fenêtre
  ; si -1 : menu en bas de la fenêtre
  ; si x > 0 : menu décalé de x pixel du haut de la fenêtre

  x = WindowWidth(0)
  If Position = -1
    Position = WindowHeight(0) - MenuHeight()
  EndIf
 
  NewWindow = OpenWindow(#PB_Any, 0, Position, x, MenuHeight(), "Menu", #PB_Window_BorderLess)
  Resultat = CreateMenu(ID, WindowID(NewWindow))
 
  SetWindowLong_(WindowID(NewWindow), #GWL_STYLE, GetWindowLong_(WindowID(NewWindow), #GWL_STYLE) | #WS_CHILD | #WS_CLIPCHILDREN)
  SetParent_(WindowID(NewWindow), WindowID(WindowID))
 
  ProcedureReturn Resultat
EndProcedure

Procedure CloseMenuEx(WindowID)
  ;UseWindow(WindowID)
  UseGadgetList(WindowID(WindowID))
EndProcedure


OpenWindow(#Window, 0, 0, 200, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #WS_CLIPCHILDREN)
; ne pas oublier de mettre la constante #WS_CLIPCHILDREN dans les paramètre de la fenêtre

If CreateMenuEx(0, #Window, -1)
  MenuTitle("Fichier")
  MenuItem(0, "Quitter")
  CloseMenuEx(#Window) ; On ferme le menu
EndIf

Repeat
  Event = WaitWindowEvent()
 
  If Event = #PB_Event_Menu
    Select EventMenu() ; menu et barre d'outils
      Case 0
        Event = #PB_Event_CloseWindow
    EndSelect
  EndIf
 
Until Event = #PB_Event_CloseWindow
Dri
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

That code has the same problem.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Indeed..... :(

Well, the only option is to create the menu on another window? If so, how do I make this window behave like a child ? I mean none of the windows should lose their focus when clicking one of them.

Possible ?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I don't think so since I've never seen it.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Change menubar location?

Post by Tomi »

after long time, have you a impressive solution :?:
Post Reply