You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
I am trying to write a control that will have a standard menubar in the control. Child windows can not have a standard menubar. Has anyone written any code duplicating the look and feel of a standard menubar with buttons(sensitive to mouse movements) and popup menus - and willing to share it. Thanks
I know for me as a user, I would prefer a toolbar in a child window to another menu... I think of menus as "top level" items and more than one would confuse me.
Here is just a thought to get you started... this is not optimized code, proof of concept only.
The last challenge is to continue hot-tracking over the labels while the popup menu has the focus.
I'll be thinking this over, I might be back later...
Regards,
Jules
Code:
#Compile Exe
#Dim All
#Include "WIN32API.INC"
%IDC_LABEL1 = 1001
%IDC_LABEL2 = 1002
%IDC_LABEL3 = 1003
%IDC_LABEL4 = 1004
%IDC_LABEL5 = 1005
%IDD_DIALOG1 = 101
'-Menu declares
%IDM_POPUP1 = 201
%IDM_POPUP2 = 202
%IDM_POPUP3 = 203
Declare CallBack Function ShowDIALOG1Proc()
Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
Function PbMain()
ShowDIALOG1 %HWND_DESKTOP
End Function
'------------------------------------------------------------------------------
'
'------------------------------------------------------------------------------
CallBack Function ShowDIALOG1Proc()
LOCAL hMenu AS DWORD
LOCAL xPos AS LONG, yPos AS LONG
LOCAL rc AS RECT
local xp as long, yp as long, pt AS POINTAPI
local stext as string
local bflag as long
Select Case As Long CbMsg
Case %WM_INITDIALOG
Case %WM_LBUTTONDOWN
'--determine menu item
xp = lowrd(cblparam)
yp = hiwrd(cblparam)
pt.x = xp
pt.y = yp
ClientToScreen CBHNDL,pt
'--FILE MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL1), rc
If ptInRect(rc,pt.x,pt.y) THEN
'--add popup menu...
MENU NEW POPUP TO hMenu
MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
MENU ADD STRING, hMenu, "-", 0, 0
MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
'--get position of top menu item, & position popup below the label
' note that xPos and yPos are in screen coordinates!
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL1), rc
xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
END IF
'--EDIT MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL2), rc
If ptInRect(rc,pt.x,pt.y) THEN
'--add popup menu...
MENU NEW POPUP TO hMenu
MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
MENU ADD STRING, hMenu, "-", 0, 0
MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
'--get position of top menu item, & position popup below the label
' note that xPos and yPos are in screen coordinates!
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL2), rc
xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
END IF
'--VIEW MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL3), rc
If ptInRect(rc,pt.x,pt.y) THEN
'--add popup menu...
MENU NEW POPUP TO hMenu
MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
MENU ADD STRING, hMenu, "-", 0, 0
MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
'--get position of top menu item, & position popup below the label
' note that xPos and yPos are in screen coordinates!
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL3), rc
xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
END IF
'--TOOL MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL4), rc
If ptInRect(rc,pt.x,pt.y) THEN
'--add popup menu...
MENU NEW POPUP TO hMenu
MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
MENU ADD STRING, hMenu, "-", 0, 0
MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
'--get position of top menu item, & position popup below the label
' note that xPos and yPos are in screen coordinates!
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL4), rc
xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
END IF
'--FILE MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL5), rc
If ptInRect(rc,pt.x,pt.y) THEN
'--add popup menu...
MENU NEW POPUP TO hMenu
MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
MENU ADD STRING, hMenu, "-", 0, 0
MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
'--get position of top menu item, & position popup below the label
' note that xPos and yPos are in screen coordinates!
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL5), rc
xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
END IF
CASE %WM_MOUSEMOVE
xp = lowrd(cblparam)
yp = hiwrd(cblparam)
stext = "xPos = " & str$(xp) & " yPos = " & str$(yp)
setwindowtext cbhndl, byval strptr(stext)
pt.x = xp
pt.y = yp
ClientToScreen CBHNDL,pt
'--FILE MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL1), rc
If ptInRect(rc,pt.x,pt.y) THEN
Control Set Color CBHNDL,%IDC_LABEL1, -1, RGB(83,83,255)
Control Redraw CBHNDL,%IDC_LABEL1
Else
Control Set Color CBHNDL, %IDC_LABEL1, -1, %Yellow
Control Redraw CBHNDL,%IDC_LABEL1
END IF
'--EDIT MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL2), rc
If ptInRect(rc,pt.x,pt.y) THEN
Control Set Color CBHNDL,%IDC_LABEL2, -1, RGB(83,83,255)
Control Redraw CBHNDL,%IDC_LABEL2
Else
Control Set Color CBHNDL, %IDC_LABEL2, -1, %Yellow
Control Redraw CBHNDL,%IDC_LABEL2
END IF
'-- VIEW MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL3), rc
If ptInRect(rc,pt.x,pt.y) THEN
Control Set Color CBHNDL,%IDC_LABEL3, -1, RGB(83,83,255)
Control Redraw CBHNDL,%IDC_LABEL3
Else
Control Set Color CBHNDL, %IDC_LABEL3, -1, %Yellow
Control Redraw CBHNDL,%IDC_LABEL3
END IF
'-- TOOLS MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL4), rc
If ptInRect(rc,pt.x,pt.y) THEN
Control Set Color CBHNDL,%IDC_LABEL4, -1, RGB(83,83,255)
Control Redraw CBHNDL,%IDC_LABEL4
Else
Control Set Color CBHNDL, %IDC_LABEL4, -1, %Yellow
Control Redraw CBHNDL,%IDC_LABEL4
END IF
'-- HELP MENU
GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL5), rc
If ptInRect(rc,pt.x,pt.y) THEN
Control Set Color CBHNDL,%IDC_LABEL5, -1, RGB(83,83,255)
Control Redraw CBHNDL,%IDC_LABEL5
Else
Control Set Color CBHNDL, %IDC_LABEL5, -1, %Yellow
Control Redraw CBHNDL,%IDC_LABEL5
END IF
Case %WM_COMMAND
Select Case As Long CbCtl
CASE %IDM_POPUP1
IF CBCTLMSG = %BN_CLICKED THEN
MSGBOX "%IDM_POPUP1"
END IF
CASE %IDM_POPUP2
IF CBCTLMSG = %BN_CLICKED THEN
MSGBOX "%IDM_POPUP2"
END IF
CASE %IDM_POPUP3
IF CBCTLMSG = %BN_CLICKED THEN
MSGBOX "%IDM_POPUP3"
END IF
End Select
End Select
End Function
'------------------------------------------------------------------------------
'
'------------------------------------------------------------------------------
Function ShowDIALOG1(ByVal hParent As Dword) As Long
Local lRslt As Long
Local hDlg As Dword
Dialog New hParent, "Cheezy Menu...", 132, 80, 329, 165, %WS_POPUP Or _
%WS_BORDER Or %WS_DLGFRAME Or %WS_THICKFRAME Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or _
%WS_CLIPSIBLINGS Or %WS_VISIBLE Or %DS_MODALFRAME Or %DS_3DLOOK Or _
%DS_NOFAILCREATE Or %DS_SETFONT, %WS_EX_CONTROLPARENT Or %WS_EX_LEFT _
Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
Control Add Label, hDlg, %IDC_LABEL1, "&File", 40, 50, 30, 10, %WS_CHILD _
Or %WS_VISIBLE Or %SS_CENTER
Control Set Color hDlg, %IDC_LABEL1, -1, %Yellow
Control Add Label, hDlg, %IDC_LABEL2, "&Edit", 70, 50, 30, 10, %WS_CHILD _
Or %WS_VISIBLE Or %SS_CENTER
Control Set Color hDlg, %IDC_LABEL2, -1, %Yellow
Control Add Label, hDlg, %IDC_LABEL3, "&View", 100, 50, 30, 10, %WS_CHILD _
Or %WS_VISIBLE Or %SS_CENTER
Control Set Color hDlg, %IDC_LABEL3, -1, %Yellow
Control Add Label, hDlg, %IDC_LABEL4, "&Tools", 130, 50, 30, 10, _
%WS_CHILD Or %WS_VISIBLE Or %SS_CENTER
Control Set Color hDlg, %IDC_LABEL4, -1, %Yellow
Control Add Label, hDlg, %IDC_LABEL5, "&Help", 160, 50, 30, 10, %WS_CHILD _
Or %WS_VISIBLE Or %SS_CENTER
Control Set Color hDlg, %IDC_LABEL5, -1, %Yellow
Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
Function = lRslt
End Function
Last edited by Jules Marchildon; 18 Nov 2007, 08:03 PM.
Reason: Added to code
No problem James, I need the exercise. I did make some more changes, not posted as of yet, I added a mouse hook procedure and moved the hot-tracking there. I need to find out how to programmatically dismiss the popup menu, DestroyMenu does not have any effect on TrackPopupMenu, as soon as I can figure that part out, I can move the popup menu (destroy and create) while hot-tracking the menu strip, perhaps if I could simulate an Esc key press or mouseclick that would dismiss the popup menu. Still working on it...
I wrote a menubar control that ships with Phoenix. Unfortunately, if you
want your control to act and feel like the real thing, a lot of code is required.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment