How to add menus to an MDI Child window

Windows specific questions.
VirusScanner
Posts: 775
Joined: Jul 01, 2005 18:45

How to add menus to an MDI Child window

Postby VirusScanner » Dec 25, 2005 20:03

I've got menus working in the MDI frame window, the MDI client window works correctly, associates with the 'window' menu, but now when I'm trying to add menus to an MDI child nothing happens. The window opens, but it's just blank. Am I doing something wrong or is there some rule that you're not allowed to have menus in MDI children?

Code: Select all

   hFileMenuBar = CreateMenu()
   AppendMenu(hFileMenuBar, MF_STRING, 1, "&Commander Window")
   AppendMenu(hFileMenuBar, MF_STRING, 2, "&Output Window")
   SetMenu(child, hFileMenuBar)
   DrawMenuBar(child)

where child is an HWND, hFileMenuBar is a HMENU, unicode is defined and windows.bi is included. So I assume it translates to AppendMenuW(...)

Edit: After trying this with a language I'm more familiar with, it looks like it's not possible to add menus to an MDI child, so I'll do it another way. But if it is possible please let me know. Thanks.
dkl
Site Admin
Posts: 3221
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Dec 25, 2005 20:17

if it doesn't work with SetMenu... the other way is to specify the menu in the window class. Did you try this?

Otherwise, I think it's impossible.
For example, MDI Child Windows often are maximized ... if so, their window icon and the '_','X' etc buttons appear in the menu bar of the frame window.. you know what I mean :-)

EDIT: hahaha I just see that CreateWindowEx has a hMenu parameter, too... but not CreateMDIWindow() (what you normally use to create a MDI child window)

and specifying in the window class for the mdi child doesn't work, either... (just tested :-))
VirusScanner
Posts: 775
Joined: Jul 01, 2005 18:45

Postby VirusScanner » Dec 25, 2005 21:20

You specify the ID of a control in the hMenu parameter, I didn't know about CreateMDIWindow, I just used CreateWindowEx with a separate class and it works fine.

All I wanted were two buttons, it would be easier to do in the menu area, but I'll just add an accelerator. It'd be more clean looking that way anyways. Thanks for the help though.
jmgbsas
Posts: 24
Joined: Dec 26, 2020 16:03

Re: How to add menus to an MDI Child window

Postby jmgbsas » Mar 22, 2021 15:37

(I can only reply to one post, but I can't create a new one ... that's why I always use reply)
This is my question ,,,
HOW CAN I EXECUTE COMMANDS IN A MENU ON A WINDOWS SCREEN ScreenRes Graphics mode ?
I was able to add a menu to ScreenRes, but it doesn't execute commands ... Is it impossible?' -------
This is the idea:

Dim As HMENU hMenu, hFile, hHelp
Dim As MSG msg

'Create a window:
hMenu = CreateMenu()
hFile = CreateMenu()
hHelp = CreateMenu()
MenuTitle(hMenu, hFile, "File")
MenuTitle(hMenu, hHelp, "Help")

'Create menu items:
MenuItem(hFile, 1, "New")
MenuItem(hFile, 2, "Open")
MenuItem(hFile, 3, "Save")
MenuItem(hFile, 4, "Exit")
MenuItem(hHelp, 5, "Info")
MenuItem(hFile, 6, "FIN")

ScreenControl(fb.GET_WINDOW_HANDLE,IhWnd)
Dim As hWnd hwnd = Cast(hwnd,IhWnd)
SetMenu(hwnd, hMenu)

The menu works but does not execute commands, the hwnd is from Screenres.
Seems the problem is the cast of hwnd....
I compiled as a console to see the prints, but there is no screen print.
Of course I tested with window new and run ok....but I would like a Screenres window

Do
WaitEvent(hwnd,msg )

Select Case msg.hwnd

Case hwnd
Select Case msg.message
Case WM_COMMAND ' Menu commands
Select Case msg.wParam
Case 1
Print "New"
Case 2
Print "Open"
Case 3
Print "Save"
Case 4
Print "Exit"
Case 5
Messagebox(0, "Test of menu functions", "Info", 0)
End Select
Case 6
End
End Select

End Select
loop
End 0

Thanks
jj2007
Posts: 2148
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: How to add menus to an MDI Child window

Postby jj2007 » Mar 22, 2021 17:06

What about using code tags, and posting complete code...?

Code: Select all

error 133: Too many errors, exiting
adeyblue
Posts: 72
Joined: Nov 07, 2019 20:08

Re: How to add menus to an MDI Child window

Postby adeyblue » Mar 23, 2021 3:03

jmgbsas wrote:HOW CAN I EXECUTE COMMANDS IN A MENU ON A WINDOWS SCREEN ScreenRes Graphics mode ?
I was able to add a menu to ScreenRes, but it doesn't execute commands ... Is it impossible?' -------


You can't, easily. The graphics window doesn't listen for WM_COMMAND messages, so menu clicks are just ignored.

You'd have to get the thread id of the graphics window (GetWindowThreadProcessId), set a WH_GETMESSAGE hook with that thread id and then process the command messages in your hook function.
jmgbsas
Posts: 24
Joined: Dec 26, 2020 16:03

Re: How to add menus to an MDI Child window

Postby jmgbsas » Mar 23, 2021 12:30

adeyblue wrote:
jmgbsas wrote:HOW CAN I EXECUTE COMMANDS IN A MENU ON A WINDOWS SCREEN ScreenRes Graphics mode ?
I was able to add a menu to ScreenRes, but it doesn't execute commands ... Is it impossible?' -------


You can't, easily. The graphics window doesn't listen for WM_COMMAND messages, so menu clicks are just ignored.

You'd have to get the thread id of the graphics window (GetWindowThreadProcessId), set a WH_GETMESSAGE hook with that thread id and then process the command messages in your hook function.


ok, I will try,
Thanks for the answer!
dodicat
Posts: 6953
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How to add menus to an MDI Child window

Postby dodicat » Mar 23, 2021 19:56

You could do it crudely:

Code: Select all


#include "windows.bi"
Screen 19,32,,&h10 or &h80 or &h20
Color ,Rgb(0,100,255)
Cls

setmouse ,,,1

Dim Win As Any Ptr

Screencontrol 2, *Cptr(Integer Ptr,@Win )

Var C=CreateWindowEx(0,"Button","Click", WS_VISIBLE Or WS_CHILD,0,0,60,30,win,0,0,0)
Var c1=CreateWindowEx( 0,"STATIC","", WS_BORDER Or WS_VISIBLE Or WS_CHILD ,150,50,300,20,  win,0,0,0)
Var E=CreateWindowEx(0,"Button","END",WS_BORDER or WS_VISIBLE Or WS_CHILD,150,80,60,30,win,0,0,0)
Dim As msg msg

While GetMessage( @msg,Win,0,0)
   
    TranslateMessage(@msg)
    DispatchMessage(@msg)
    Select Case msg.hwnd
    Case C
        Select Case msg.message 
        Case WM_LBUTTONDOWN
           
            setWindowText(c1,"You can press any key to end or click END")
        End Select
       
    Case E
        Select Case msg.message 
        Case WM_LBUTTONDOWN
            End
        End Select
       
    End Select
   
    select case msg.message
    case WM_KEYDOWN
        end
    end select
    if inkey=chr(27) then end
Wend

Sleep
 

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 6 guests