Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[ALPHA2] MDI using native menus

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> Snippet Testing
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jan 7th, 2008, 9:59pm    Post subject: [ALPHA2] MDI using native menus Reply with quote

This is mostly an update to the "MDI Test" demo that has shipped with WMLiberty for a long time. It requires LB 4.xx.

The demo uses a hidden native window containing all of the menus. The MDI frame window forwards all WM_COMMAND messages to this window, allowing you to write menu handlers in native LB code.
Code:
Global g.FRAMECLASS$, g.CHILDCLASS$, g.g.hInstance
Global g.hwndMDIClient, g.Running

g.FRAMECLASS$ = "WMLibertyMDIFrame"
g.CHILDCLASS$ = "WMLibertyMDIChild"
CallDLL #kernel32, "GetModuleHandleA", _
    _NULL As Long, _
    g.hInstance As ULong

Open "WMLiberty.dll" For DLL As #wmlib

Menu #menus, _
    "&File", _
    "E&xit", menuFileExit
Menu #menus, _
    "&Window", _
    "&New Window", menuWindowNewWin
Menu #menus, _
    "&Help", _
    "About this demo...", menuHelpAbout

StyleBits #menus, 0, _WS_VISIBLE, 0, 0
Open "Hidden Menu Handler" For Window As #menus

CallDLL #user32, "LoadCursorA", _
    _NULL As Long, _
    _IDC_ARROW As Long, _
    hCursor As ULong

style = _CS_HREDRAW Or _CS_VREDRAW
CallDLL #wmlib, "RegisterMDIFrameClass", _
    g.FRAMECLASS$ As Ptr, _
    style As ULong, _
    0 As Long, _
    0 As Long, _
    g.hInstance As ULong, _
    0 As Long, _
    hCursor As ULong, _
    _COLOR_WINDOW As Long, _
    result As Long

style = _WS_OVERLAPPEDWINDOW Or _WS_VISIBLE
CallDLL #user32, "CreateWindowExA", _
    0 As Long, _
    g.FRAMECLASS$ As Ptr, _
    "MDI Test - Click Window->New Window" As Ptr, _
    style As Long, _
    _CW_USEDEFAULT As Long, _
    _CW_USEDEFAULT As Long, _
    _CW_USEDEFAULT As Long, _
    _CW_USEDEFAULT As Long, _
    0 As Long, _
    0 As Long, _
    g.hInstance As ULong, _
    0 As Long, _
    hwndFrame As ULong

hwndMenus = HWnd(#menus)

CallDLL #user32, "GetMenu", _
    hwndMenus As ULong, _
    hmenuMain As ULong

CallDLL #user32, "GetSubMenu", _
    hmenuMain As ULong, _
    1 As Long, _
    hmenuWindow As ULong

CallDLL #user32, "SetMenu", _
    hwndFrame As ULong, _
    hmenuMain As ULong, _
    result As ULong

style = _WS_CHILD Or _WS_CLIPCHILDREN Or _WS_VISIBLE
CallDLL #wmlib, "CreateMDIClientEx", _
    _WS_EX_CLIENTEDGE As ULong, _
    style As ULong, _
    0 As Long, _
    0 As Long, _
    -1 As Long, _
    -1 As Long, _
    hwndFrame As ULong, _
    0 As Long, _
    g.hInstance As ULong, _
    hmenuWindow As ULong, _
    101 As Long, _
    g.hwndMDIClient As ULong

style = _CS_HREDRAW Or _CS_VREDRAW
CallDLL #wmlib, "RegisterMDIChildClass", _
    g.CHILDCLASS$ As Ptr, _
    style As ULong, _
    0 As Long, _
    0 As Long, _
    g.hInstance As ULong, _
    0 As Long, _
    hCursor As ULong, _
    _COLOR_WINDOW As Long, _
    result As Long

Callback lpfnSysCommand, OnSysCommand( ULong, ULong, Long, Long ), Long
CallDLL #wmlib, "SetWMHandler", _
    hwndFrame As ULong, _
    _WM_SYSCOMMAND As ULong, _
    lpfnSysCommand As ULong, _
    0 As Long, _
    result As Long

Callback lpfnSize, OnSize( ULong, ULong, Long, Long ), Long
CallDLL #wmlib, "SetWMHandler", _
    hwndFrame As ULong, _
    _WM_SIZE As ULong, _
    lpfnSize As ULong, _
    0 As Long, _
    result As Long

Callback lpfnCommand, OnCommand( ULong, ULong, Long, Long ), Long
CallDLL #wmlib, "SetWMHandler", _
    hwndFrame As ULong, _
    _WM_COMMAND As ULong, _
    lpfnCommand As ULong, _
    -1 As Long, _
    result As Long

g.Running = 1

[DoEvents]
Scan
CallDLL #kernel32, "Sleep", _
    100 As ULong, _
    result As Void
If g.Running Then [DoEvents]

CallDLL #user32, "DestroyWindow", _
    hwndFrame As ULong, _
    result As Long

CallDLL #user32, "UnregisterClassA", _
    g.FRAMECLASS$ As Ptr, _
    g.hInstance As ULong, _
    result As Long

CallDLL #user32, "UnregisterClassA", _
    g.CHILDCLASS$ As Ptr, _
    g.hInstance As ULong, _
    result As Long

Close #wmlib
Close #menus

End

Sub menuFileExit
    g.Running = 0
End Sub

Sub menuWindowNewWin
    CallDLL #user32, "CreateMDIWindowA", _
        g.CHILDCLASS$ As Ptr, _
        "New Window" As Ptr, _
        _WS_VISIBLE As ULong, _
        _CW_USEDEFAULT As Long, _
        _CW_USEDEFAULT As Long, _
        _CW_USEDEFAULT As Long, _
        _CW_USEDEFAULT As Long, _
        g.hwndMDIClient As ULong, _
        g.hInstance As ULong, _
        0 As Long, _
        hwndChild As ULong
End Sub

Sub menuHelpAbout
    Notice "This demo uses WMLiberty, by Brent D. Thorn"
End Sub

Function OnSysCommand( hwnd, uMsg, wParam, lParam )
    OnSysCommand = 1
    If _SC_CLOSE = wParam Then g.Running = 0
End Function

Function OnCommand( hwnd, uMsg, wParam, lParam )
    hwndMenus = HWnd(#menus)
    CallDLL #user32, "SendMessageA", _
        hwndMenus As ULong, _
        _WM_COMMAND As ULong, _
        wParam As ULong, _
        lParam As ULong, _
        result As Long
End Function

Function OnSize( hwnd, uMsg, wParam, lParam )
    OnSize = 1
    If wParam <> _SIZE_MINIMIZED Then
        nWidth = LOWORD(lParam)
        nHeight = HIWORD(lParam)

        CallDLL #user32, "MoveWindow", _
            g.hwndMDIClient As ULong, _
            0 As Long, _
            0 As Long, _
            nWidth As Long, _
            nHeight As Long, _
            1 As Long, _
            result As Long
    End If
End Function

Function LOWORD( dw )
    LOWORD = (dw And 65535)
End Function

Function HIWORD( dw )
    HIWORD = Int((dw And 4294901760) / 65536)
End Function

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jan 14th, 2008, 3:23am    Post subject: Re: [ALPHA2] MDI using native menus Reply with quote

Updated to ALPHA 2.
  • Fixed a bug in WM_COMMAND processing that broke the Windows list.
  • Changed a few more Longs to ULongs.

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> Snippet Testing All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group