Author Topic: oxygen + menu  (Read 2730 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Guest
oxygen + menu
« on: June 13, 2013, 03:02:54 AM »
here's a simple menu api for oxygen. place it into "example/GUI" folder for running.

Code: [Select]
 '
  ' simple example how to setup a menu for oxygen basic
  ' converted from powerbasic by frankolinox (frank brĂ¼bach), 11.juni.2013, bsa
  ' taken some part from petzolds menubar example
  ' folder: "example/GUI"
  '
  '
  $ filename "t.exe"
  includepath "$/inc/"
  '#include "RTL32.inc"
  '#include "RTL64.inc"
  #include "MinWin.inc"
  #lookahead ' for procedures
  s=error()
  '
  if s then
    print s
    end
  end if

%ID_TIMER = 1

%IDM_FILE_NEW     = 40001
%IDM_FILE_OPEN    = 40002
%IDM_FILE_SAVE    = 40003
%IDM_FILE_SAVE_AS = 40004
%IDM_APP_EXIT     = 40005
%IDM_EDIT_UNDO    = 40006
%IDM_EDIT_CUT     = 40007
%IDM_EDIT_COPY    = 40008
%IDM_EDIT_PASTE   = 40009
%IDM_EDIT_CLEAR   = 40010
%IDM_BKGND_WHITE  = 40011
%IDM_BKGND_LTGRAY = 40012
%IDM_BKGND_GRAY   = 40013
%IDM_BKGND_DKGRAY = 40014
%IDM_BKGND_BLACK  = 40015
%IDM_TIMER_START  = 40016
%IDM_TIMER_STOP   = 40017
%IDM_APP_HELP     = 40018
%IDM_APP_ABOUT    = 40019

%MF_INSERT          = &H00000000???
%MF_CHANGE          = &H00000080???
%MF_APPEND          = &H00000100???
%MF_DELETE          = &H00000200???
%MF_REMOVE          = &H00001000???

%MF_BYCOMMAND       = &H00000000???
%MF_BYPOSITION      = &H00000400???

%MF_SEPARATOR       = &H00000800???

'%MF_ENABLED         = &H00000000???
'%MF_GRAYED          = &H00000001???
'%MF_DISABLED        = &H00000002???

'%MF_UNCHECKED       = &H00000000???
'%MF_CHECKED         = &H00000008???
%MF_USECHECKBITMAPS = &H00000200???

%MF_STRING          = &H00000000???
%MF_BITMAP          = &H00000004???
%MF_OWNERDRAW       = &H00000100???

%MF_POPUP           = &H00000010???
%MF_MENUBARBREAK    = &H00000020???
%MF_MENUBREAK       = &H00000040???

declare InitCommonControlsEx lib "ComCtl32.dll" (INITCOMMONCONTROLSEXtype*ic) as sys

indexbase 0

DECLARE FUNCTION GetMenu LIB "USER32.DLL" ALIAS "GetMenu" ( _
   BYVAL hWnd AS SYS _                                ' __in HWND hWnd
 ) AS SYS                                             ' HMENU

DECLARE FUNCTION SetMenu LIB "USER32.DLL" ALIAS "SetMenu" ( _
   BYVAL hWnd AS SYS _                                ' __in HWND hWnd
 , OPTIONAL BYVAL hMenu AS SYS _                      ' __in_opt HMENU hMenu
 ) AS LONG                                              ' BOOL

DECLARE FUNCTION AppendMenuA LIB "USER32.DLL" ALIAS "AppendMenuA" ( _
   BYVAL hMenu AS SYS _                               ' __in HMENU hMenu
 , BYVAL uFlags AS SYS _                              ' __in UINT uFlags
 , BYVAL uIDNewItem AS SYS _                          ' __in UINT_PTR uIDNewItem
 , OPTIONAL BYREF lpNewItem AS ASCIIZ _                 ' __in_opt LPCSTR lpNewItem
 ) AS LONG                                              ' BOOL

%DESKTOP_CREATEMENU       = &H0004???
DECLARE FUNCTION CreateMenu LIB "USER32.DLL" ALIAS "CreateMenu" ( _
 ) AS SYS                                             ' HMENU


  '=========
  'MAIN CODE
  '=========
  
  dim cmdline as asciiz ptr, inst as sys
  &cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  'WINDOWS START
  '=============
  '
  WinMain inst,0,cmdline,SW_NORMAL
  end

  '--------------------------------------------------------------------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  '====================================================================
  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax

  wc.style = CS_HREDRAW or CS_VREDRAW
  wc.lpfnWndProc = @WndProc
  wc.cbClsExtra =0
  wc.cbWndExtra =0    
  wc.hInstance =inst
  wc.hIcon=LoadIcon 0, IDI_APPLICATION
  wc.hCursor=LoadCursor 0,IDC_ARROW
  wc.hbrBackground = GetStockObject WHITE_BRUSH
  wc.lpszMenuName =null
  wc.lpszClassName = strptr "Demo"

  RegisterClass (@wc)
 
  Wwd = 420 : Wht = 300
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"Menu+Oxygen Basic",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0

'---------------------------------------------------------- // MENU START ---------------
  sys hMenu,hMenuPopup,iCmdShow
      hMenu = CreateMenu()

      hMenuPopup = CreateMenu()
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_FILE_NEW,     "&New"
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_FILE_OPEN,    "&Open..."
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_FILE_SAVE,    "&Save"
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_FILE_SAVE_AS, "Save &As..."
         AppendMenuA hMenuPopup, %MF_SEPARATOR, 0,0 '                 BYVAL %NULL
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_APP_EXIT,     "E&xit"
      AppendMenuA hMenu, %MF_POPUP, hMenuPopup, "&File"
         SetMenu hwnd, hMenu

     hMenuPopup = CreateMenu()
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_EDIT_UNDO,  "&Undo"
         AppendMenuA hMenuPopup, %MF_SEPARATOR, 0,               BYVAL %NULL
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_EDIT_CUT,   "Cu&t"
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_EDIT_COPY,  "&Copy"
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_EDIT_PASTE, "&Paste"
         AppendMenuA hMenuPopup, %MF_STRING,    %IDM_EDIT_CLEAR, "De&lete"
      AppendMenuA hMenu, %MF_POPUP, hMenuPopup, "&Edit"

      hMenuPopup = CreateMenu()
         AppendMenuA hMenuPopup, %MF_STRING, %IDM_APP_HELP,  "&Help"
         AppendMenuA hMenuPopup, %MF_STRING, %IDM_APP_ABOUT, "&About MenuDemo..."
      AppendMenuA hMenu, %MF_POPUP, hMenuPopup, "&Help"
'---------------------------------------------------------- // MENU END ---------------
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd
  '
  sys bRet
  '
  do while bRet := GetMessage (@wm, 0, 0, 0)
    if bRet = -1 then
      'show an error message
    else
      TranslateMessage @wm
      DispatchMessage @wm
    end if
  wend

  End Function



  dim as rect crect 'for WndProc and TimerProc

  '--------------------------------------------------------------
  function WndProc ( hWnd, wMsg, wParam, lparam ) as sys callback
  '==============================================================

    static as sys hdc
    static as String txt
    static as PaintStruct Paintst
    sys id
    '==========
    select wMsg
    '==========
      
      case WM_COMMAND
        hMenu = GetMenu(hwnd)
            if wparam = %IDM_APP_EXIT THEN        
            print "hello and exit"
            SendMessage hwnd, WM_CLOSE, 0, 0
            end if
      
      '--------------
      case WM_CREATE
      '=============

      GetClientRect  hWnd,&cRect
      
      '--------------  
      case WM_DESTROY
      '===============
          
      PostQuitMessage 0
        
      '------------
      case WM_PAINT
      '============
      
      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello Menu World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
        
      '--------------  
      case WM_KEYDOWN
      '==============

      '============            
      Select wParam
      '============

Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE
      End Select
      
      '--------        
      case else
      '========          
        function=DefWindowProc hWnd,wMsg,wParam,lParam        
    end select
  end function


best regards, frank

X

Aurel

  • Guest
Re: oxygen + menu
« Reply #1 on: June 13, 2013, 08:39:39 AM »
Yo dude.. :)
Frank that is really good example, i don't know why i forget about menus   ::)

Frankolinox

  • Guest
Re: oxygen + menu
« Reply #2 on: June 13, 2013, 09:30:31 AM »
Quote
Frank that is really good example, i don't know why i forget about menus

..because you probably haven't the knowledge from powerbasic site ;)

there's a lot of example from "petzold's" archive they are interesting for studying and converting or even learning about winapi and much more...

regards, frank

Aurel

  • Guest
Re: oxygen + menu
« Reply #3 on: June 13, 2013, 09:40:56 AM »
Hi Frank..  :)

Quote
..because you probably haven't the knowledge from powerbasic site

no,no man i do this functions long time ago when i implement them into AurelBasic
but i simply forget add them into my include file... ::)
I will do this soon...

Charles Pegge

  • Guest
Re: oxygen + menu
« Reply #4 on: June 15, 2013, 01:27:57 AM »
Thank you Frank. I will add it to /examples/GUI

Frankolinox

  • Guest
Re: oxygen + menu
« Reply #5 on: July 25, 2013, 08:25:33 AM »
@charles: my menu example doesnt work with latest oxygen.dll. have you changed something in "declare function.. lib" statements?

regards, frank

Aurel

  • Guest
Re: oxygen + menu
« Reply #6 on: July 25, 2013, 09:30:31 AM »
Because of this i always keep older dll in backup folder.
Interesting thing is that changes makes conflict with winapi functions most of the time .
But i am sure that Charles will fix this .. ;)

Charles Pegge

  • Guest
Re: oxygen + menu
« Reply #7 on: July 25, 2013, 10:03:08 AM »
Hi Frank,

I made a further update very recently:

http://www.oxygenbasic.org/forum/index.php?topic=749

I checked it with this version of your menus program (attached), and it looks fine.




X