Author Topic: Menu demo  (Read 1221 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
Menu demo
« on: February 22, 2015, 02:50:53 PM »
Here is quick example about how to set standard menu in Oxygen basic...

Code: [Select]
'skeleton VB way...
$ filename "skeletonMenu.exe"
include "rtl32.inc"
'#lookahead
'structures
Type WNDCLASSEX
 cbSize        as int
 Style         as int
 lpfnwndproc   as sys
 cbClsextra    as int
 cbWndExtra    as int
 hInstance     as sys
 hIcon         as sys
 hCursor       as sys
 hbrBackground as sys
 lpszMenuName  as sys
 lpszClassName as sys
 hIconSm       AS sys
End Type

Type POINTAPI
 x as long
 y as long
End Type

Type MSG
 hwnd    as sys
 message as int
 wParam  as sys
 lParam  as sys
 time    as dword
 pt      as POINTAPI
End Type

'constants
% IDI_WINLOGO     = 32517
% IDI_APPLICATION = 32512
% IDC_ARROW       = 32512
% CS_OWNDC        = 32
% CS_DBLCLKS      =  &H8
% SW_NORMAL       = 1
% SW_SHOW         = 5

% WM_CREATE      = 1
% WM_DESTROY     = 2
% WM_PAINT       = 15
% WM_QUIT        = 18
% WM_SIZE        = 5
% WM_MOVE        = 3
% WM_CHAR        = 258
% WM_KEYDOWN     = 256
% WM_KEYUP       = 257
% WM_MOUSEMOVE   = 512
% WM_MBUTTONDOWN = 519
% WM_LBUTTONDOWN = 513
% WM_RBUTTONDOWN = 516
% WM_LBUTTONUP   = 514
% WM_RBUTTONUP   = 517
% WM_MBUTTONUP   = 520

% WS_OVERLAPPEDWINDOW = 0x00CF0000
% WS_SYSMENU     = 0x80000
% WS_OVERLAPPED  = WS_SYSMENU     
% WS_POPUP       = 0x80000000
% WS_DLGFRAME    = 0x400000
% WS_VISIBLE     = 0x10000000
'defines...
INT WHITE_BRUSH = 4

'declarations...
Declare Function LoadIcon         Lib "user32.dll"   Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Any) As Long
Declare Function LoadCursor       Lib "user32.dll"   Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Declare Function GetModuleHandle  Lib "kernel32.dll" Alias "GetModuleHandleA" (sys lpModuleName) as Long
Declare Function RegisterClassEx  Lib "user32.dll"   Alias "RegisterClassExA" (byref lpwcx as WNDCLASSEX) as Long
Declare Function CreateWindowEx   Lib "user32.dll"   Alias "CreateWindowExA" (byval dwExStyle AS INT,byval lpClassName AS STRING,byval lpWindowName AS STRING,byval dwStyle AS INT,byval x AS INT,byval y AS INT,byval nWidth AS INT,byval nHeight AS INT,byval hWndParent AS INT,byval hMenu AS INT,byval hInstance AS INT,byval lpParam AS INT) as Long
Declare Function TranslateMessage Lib "user32.dll"  (byref lpMsg as MSG) as Long
Declare Function DispatchMessage  Lib "user32.dll"   Alias "DispatchMessageA" (byref lpMsg as MSG) as Long
Declare Function GetMessage       Lib "user32.dll"   Alias "GetMessageA" (lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Declare Function ShowWindow       Lib "user32.dll"  (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function UpdateWindow     Lib "user32.dll"  (ByVal lhwnd As Long) As Long
Declare Function DefWindowProc    Lib "user32.dll"  Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Sub PostQuitMessage       Lib "user32.dll"  (ByVal nExitCode As Long)

Declare Function CreatePopupMenu Lib "user32.dll" () As Long
Declare Function CreateMenu      Lib "user32.dll" () As Long
Declare Function GetMenu         Lib "user32.dll" (ByVal hwnd As Long) As Long
Declare Function SetMenu         Lib "user32.dll" (ByVal hwnd As Long, ByVal hMenu As Long) As Long
Declare Function AppendMenu      Lib "user32.dll" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Declare Function DrawMenuBar     Lib "user32.dll" (ByVal hwnd As Long) As Long
Declare Function DeleteMenu      Lib "user32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Declare Function DestroyMenu     Lib "user32.dll" (ByVal hMenu As Long) As Long
Declare Function TrackPopupMenu  Lib "user32.dll" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT) As Long


Dim wcx as WNDCLASSEX
Dim wm as MSG
Dim hwnd,style, Wx, Wy, Ww, Wh, wparent as Long
Dim wcaption,ClassName as String

'wcaption  = "MyWindow"
classname = "Oxygen"
style   = WS_OVERLAPPEDWINDOW
Wx=0 : Wy=0 : Ww=640 : Wh=480
wparent = 0 'HWND_DESKTOP
'-------------------------------

'FILL WNDCLASSEX structure
inst = GetModuleHandle 0
wcx.cbSize        = sizeOf(WNDCLASSEX)
wcx.style         = CS_DBLCLKS
wcx.lpfnWndProc   = &WndProc
wcx.cbClsExtra    = 0
wcx.cbWndExtra    = 0
wcx.hInstance     = inst
wcx.hIcon         = LoadIcon 0,IDI_APPLICATION         
wcx.hCursor       = LoadCursor 0,IDC_ARROW 
wcx.hbrBackground = WHITE_BRUSH     
wcx.lpszMenuName  = strptr ""
wcx.lpszClassName = strptr Classname
wcx.hIconSm       = 0

RegisterClassEx wcx

wcaption  = "MyWindowEx"
'create window -------------------------------
Hwnd = CreateWindowEx 0,ClassName , wcaption, style, Wx, Wy, Ww, Wh, wparent, 0, inst,0
ShowWindow Hwnd,SW_SHOW

'create Menu
'Appendmenu hMenu , wFlags, wIDNewItem, lpNewItem
int mainMenu,submenu1
mainMenu = CreateMenu()
'...............................................
submenu1 = CreatePopupMenu ()
'addsub menu items with ID
AppendMenu (submenu1,0,100,strptr "New")
AppendMenu (submenu1,0,101,strptr "Open")
AppendMenu (submenu1,0,102,strptr "Save")
AppendMenu (submenu1,0,103,strptr "Quit")
'set submwnu on main menu
AppendMenu (mainMenu,16,submenu1,strptr "File")
'...............................................

SetMenu  hwnd ,mainMenu


'message loop
WHILE GetMessage(wm,0,0,0)
     TranslateMessage wm
     DispatchMessage  wm
WEND

'main callback procedure ---------------------------------------
Function WndProc (sys hwnd,wMsg,wParam,lParam) as sys callback
Select wMsg
case WM_DESTROY
PostQuitMessage 0

End Select
'never put default return inside select
Return DefWindowProc(Hwnd,wMsg,wParam,lParam)

End Function
'------------------------------------------