home *** CD-ROM | disk | FTP | other *** search
- (*********************************************************************)
- (* *)
- (* Microworks ObjectMate 2.52 *)
- (* *)
- (* Windows Interface Develpment Kit for the Borland Languages. *)
- (* *)
- (* WINMENU.PAS : 3D Ownerdraw menu demonstration *)
- (* *)
- (* Copyright 1992-94 Microworks Sydney, Australia. *)
- (* *)
- (*********************************************************************)
-
- (* WinMenu implements 3-dimensional ownerdraw menu's that let you change the
- * menu text font and highlight and text highlight colors.
- *)
-
- program WinMenu;
-
- uses WinTypes, WinProcs, CommDlg, ODMenu, SFX200,
- {$IFDEF Ver15}
- WObjects;
- {$ELSE}
- Objects, OWindows, ODialogs;
- {$ENDIF}
-
- {$R Winmenu.res}
-
- const
-
- {*** Menu Item ID's ***}
- CM_ITEM1 = 101;
- CM_ITEM2 = 102;
- CM_ITEM3 = 103;
- CM_ITEM4 = 104;
- CM_EXIT = 105;
- CM_FONT = 106;
- CM_COLOR = 107;
- CM_COLORTEXT = 109;
- CM_ABOUT = 110;
- AppName : PChar = 'MenuWindow';
-
- type
-
- PAboutDialog = ^TAboutDialog;
- TAboutDialog = object(TDialog)
- procedure SetupWindow; virtual;
- end;
-
- PMenuWindow = ^TMenuWindow;
- TMenuWindow = object(TSFXWindow)
- Font : HFont;
- Color : LongInt;
- TextColor : LongInt;
- LogFont : TLogFont;
- Menu : HMenu;
- SubMenu : HMenu;
- constructor Init(AParent: PWindowsObject; AName: PChar);
- destructor Done; virtual;
- function GetClassName : PChar; virtual;
- procedure GetWindowClass(var AWndClass: TWndClass); virtual;
- procedure SetUpWindow; virtual;
- procedure Create3DMenus;
- procedure WMCommand (var Msg: TMessage); virtual wm_First + wm_Command;
- procedure WMMeasureItem (var Msg: TMessage); virtual wm_First + wm_MeasureItem;
- procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
- procedure WMMenuChar (var Msg: TMessage); virtual wm_First + wm_MenuChar;
- procedure CMExitWindow (var Msg: TMessage); virtual cm_First + cm_Exit;
- procedure CMFont (var Msg: TMessage); virtual cm_First + cm_Font;
- procedure CMColor (var Msg: TMessage); virtual cm_First + cm_Color;
- procedure CMColorText (var Msg: TMessage); virtual cm_First + cm_ColorText;
- procedure CMAbout (var Msg: TMessage); virtual cm_First + cm_About;
- end;
-
- PMenuApp = ^TMenuApp;
- TMenuApp = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- {********** TMenuApp **********}
-
- procedure TMenuApp.InitMainWindow;
- begin
- MainWindow := New(PMenuWindow, Init(nil, 'WinMenu - 3D Menu Demonstration'));
- end;
-
- {********** TMenuWindow **********}
-
- constructor TMenuWindow.Init(AParent: PWindowsObject; AName: PChar);
- begin
- TSFXWindow.Init(AParent, AName);
- {Attr.Style := Attr.Style or mws_SFXFrame or mws_SFXCaption;}
- {Attr.Style := Attr.Style or mws_Raised3DFrame or mws_SFXCaption;}
- {Attr.Style := Attr.Style or mws_Raised3DGlaze or mws_SFXCaption;}
- Attr.Style := Attr.Style or mws_Raised3DSteel or mws_SFXCaption;
- Attr.Menu := LoadMenu(HInstance, 'WinMenu');
- Color := 0;
- TextColor := 0;
-
- { Set up fine system font for menu items }
- Font := GetStockObject(SYSTEM_FONT);
- GetObject(Font, SizeOf(TLogFont), @LogFont);
- LogFont.lfWeight := FW_NORMAL;
- lstrcpy(LogFont.lfFaceName, 'MS Sans Serif');
- Font := CreateFontIndirect(LogFont);
- end;
-
- destructor TMenuWindow.Done;
- begin
- EraseObject(Font);
- TSFXWindow.Done;
- end;
-
- function TMenuWindow.GetClassName;
- begin
- GetClassName := AppName;
- end;
-
- procedure TMenuWindow.GetWindowClass(var AWndClass: TWndClass);
- begin
- TSFXWindow.GetWindowClass(AWndClass);
- AWndclass.hIcon := LoadIcon(HInstance, 'WinMenu');
- end;
-
- procedure TMenuWindow.SetUpWindow;
- begin
- TSFXWindow.SetUpWindow;
- Create3DMenus;
- end;
-
- procedure TMenuWindow.Create3DMenus;
- begin
- (* Since the system menu rarely gets modified, Set3DSystemMenu can be used to
- * automatically set up a basic ownerdraw system menu.
- *)
- Set3DSystemMenu(HWindow, 'WinMenu');
-
- { Create popup submenu with ownerdraw items }
- SubMenu := CreatePopupMenu;
- AppendMenu(SubMenu, mf_OwnerDraw, CM_Item1, 'SubMenu Item &A');
- AppendMenu(SubMenu, mf_OwnerDraw, CM_Item2, 'SubMenu Item &B');
- AppendMenu(SubMenu, mf_OwnerDraw or mf_Checked, CM_Item3, 'SubMenu Item &C');
- AppendMenu(SubMenu, mf_OwnerDraw, CM_Item4, 'SubMenu Item &D');
-
- { Modify main menu to display ownerdraw items }
- Menu := GetSubMenu(Attr.Menu, 0);
- ModifyMenu(Menu, 0, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM1, 'Menu Item &A');
- ModifyMenu(Menu, 1, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM2, 'Menu Item &B');
- ModifyMenu(Menu, 2, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM3, 'Menu Item &C');
- ModifyMenu(Menu, 3, MF_BYPOSITION or MF_OWNERDRAW or MF_Checked, CM_ITEM4, 'Menu Item &D');
- ModifyMenu(Menu, 5, MF_BYPOSITION or MF_OWNERDRAW, CM_Exit, '&Exit WinMenu');
- Menu := GetSubMenu(Attr.Menu, 1);
- ModifyMenu(Menu, 0, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM1, 'Menu Item &A');
- ModifyMenu(Menu, 1, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM2, 'Menu Item &B');
- ModifyMenu(Menu, 2, MF_BYPOSITION or MF_OWNERDRAW or MF_POPUP, SubMenu, '&Sub Menu');
- ModifyMenu(Menu, 3, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM4, 'Menu Item &D');
- Menu := GetSubMenu(Attr.Menu, 2);
- ModifyMenu(Menu, 0, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM1, 'Menu Item &A');
- ModifyMenu(Menu, 1, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM2, 'Menu Item &B');
- ModifyMenu(Menu, 2, MF_BYPOSITION or MF_OWNERDRAW, CM_ITEM3, 'Menu Item &C');
- ModifyMenu(Menu, 3, MF_BYPOSITION or MF_OWNERDRAW or MF_POPUP, SubMenu, '&Sub Menu');
- Menu := GetSubMenu(Attr.Menu, 3);
- ModifyMenu(Menu, 0, MF_BYPOSITION or MF_OWNERDRAW, CM_FONT, 'Menu &Font');
- ModifyMenu(Menu, 1, MF_BYPOSITION or MF_OWNERDRAW, CM_COLOR, 'Hilite &Color');
- ModifyMenu(Menu, 2, MF_BYPOSITION or MF_OWNERDRAW, CM_COLORTEXT, 'Hilite &Text Color');
- Menu := GetSubMenu(Attr.Menu, 4);
- ModifyMenu(Menu, 0, MF_BYPOSITION or MF_OWNERDRAW, CM_ABOUT, '&About WinMenu');
- end;
-
- procedure TMenuWindow.WMCommand (var Msg: TMessage);
- var
- MsgText : PChar;
- begin
- MsgText := nil;
- with Msg do
- begin
- if wParam = CM_ITEM1 then
- MsgText := 'You selected item A'
- else
- if wParam = CM_ITEM2 then
- MsgText := 'You selected item B'
- else
- if wParam = CM_ITEM3 then
- MsgText := 'You selected item C'
- else
- if wParam = CM_ITEM4 then
- MsgText := 'You selected item D'
- else
- TSFXWindow.WMCommand(Msg);
- if MsgText <> nil then
- SFXMsgBox(HWindow, MsgText, 'Information', MB_ICONINFORMATION, 0);
- end;
- end;
-
- procedure TMenuWindow.WMDrawItem (var Msg:tMessage);
- begin
- (* Pass WMDrawItem onto DrawMenuItem. If you don't want the user to
- * change fonts and highlight colors you can use the default zero
- * values for Font, Color and TextColor.
- *)
- if PDrawItemStruct(Msg.lParam)^.CtlType = ODT_MENU then
- DrawMenuItem(PDrawItemStruct(Msg.lParam), Font, Color, TextColor);
- end;
-
- procedure TMenuWindow.WMMeasureItem (var Msg: TMessage);
- begin
- (* The same font handle passed to DrawMenuItem must be passed to MeasureMenuItem
- *)
- if PMeasureItemStruct(Msg.lParam)^.CtlType = ODT_MENU then
- MeasureMenuItem(HWindow, PMeasureItemStruct(Msg.lParam), Font);
- end;
-
- procedure TMenuWindow.WMMenuChar (var Msg: TMessage);
- begin
- (* A mnemonic is the undelined letter in the text of a menu item. When a menu
- * is active the user can select a menu item by pressing the key that corresponds
- * to the item's underlined letter. Ownerdraw menus don't process standard menu
- * mnemonics so you must trap the WM_MENUCHAR message and process them yourself.
- * A WM_MENUCHAR message is sent when a menu is active and the user presses a key.
- * wParam is the key's ascii character, the LOWORD of lParam is the menu type,
- * either MF_POPUP or MF_SYSMENU and the HIWORD of lParam is the handle of the
- * menu. The return value must be a long integer specifying the menu item's zero
- * based position in its LOWORD and '2' in its HIWORD.
- *
- * Since the system menu rarely gets modified, ProcessSystemChar can be used to
- * automatically handle system menu mnemonics.
- *)
- if Msg.lParamLo and mf_SysMenu <> 0 then
- Msg.Result := ProcessSystemChar(Msg.wParam)
- else
- if Msg.lParamHi = SubMenu then
- begin
- case Msg.wParam of
- 65, 97 : Msg.Result := MakeLong(0, 2);
- 66, 98 : Msg.Result := MakeLong(1, 2);
- 67, 99 : Msg.Result := MakeLong(2, 2);
- 68, 100 : Msg.Result := MakeLong(3, 2);
- end;
- end
- else
- if Msg.lParamHi = GetSubMenu(Attr.Menu, 0) then
- begin
- case Msg.wParam of
- 65, 97 : Msg.Result := MakeLong(0, 2);
- 66, 98 : Msg.Result := MakeLong(1, 2);
- 67, 99 : Msg.Result := MakeLong(2, 2);
- 68, 100 : Msg.Result := MakeLong(3, 2);
- 69, 101 : Msg.Result := MakeLong(5, 2);
- end;
- end
- else
- if Msg.lParamHi = GetSubMenu(Attr.Menu, 1) then
- begin
- case Msg.wParam of
- 65, 97 : Msg.Result := MakeLong(0, 2);
- 66, 98 : Msg.Result := MakeLong(1, 2);
- 83, 115 : Msg.Result := MakeLong(2, 2);
- 68, 100 : Msg.Result := MakeLong(3, 2);
- end;
- end
- else
- if Msg.lParamHi = GetSubMenu(Attr.Menu, 2) then
- begin
- case Msg.wParam of
- 65, 97 : Msg.Result := MakeLong(0, 2);
- 66, 98 : Msg.Result := MakeLong(1, 2);
- 67, 99 : Msg.Result := MakeLong(2, 2);
- 83, 115 : Msg.Result := MakeLong(3, 2);
- end;
- end
- else
- if Msg.lParamHi = GetSubMenu(Attr.Menu, 3) then
- begin
- case Msg.wParam of
- 70, 102 : Msg.Result := MakeLong(0, 2);
- 67, 99 : Msg.Result := MakeLong(1, 2);
- 84, 116 : Msg.Result := MakeLong(2, 2);
- end;
- end;
- end;
-
- procedure TMenuWindow.CMExitWindow (var Msg: TMessage);
- begin
- CloseWindow;
- end;
-
- procedure TMenuWindow.CMFont (var Msg: TMessage);
- var
- FontColor : LongInt;
- Template : Integer;
- begin
- Fontcolor := 0;
- Template := GetSFXTemplateId('SFX3DDlg', DLG_EXFONT);
- if SFXChooseFont(HWindow, LogFont, 0, Template, True, FontColor) then
- begin
- EraseObject(Font);
- Font := CreateFontIndirect(LogFont);
- DestroyMenu(Attr.Menu);
- Attr.Menu := LoadMenu(HInstance, 'WinMenu');
- Create3DMenus;
- end;
- end;
-
- procedure TMenuWindow.CMColor (var Msg: TMessage);
- var
- CCFlags : LongInt;
- Template : Integer;
- begin
- CCFlags := CC_RGBINIT;
- Template := GetSFXTemplateId('SFX3DDlg', DLG_EXCOLOR);
- SFXChooseColor(HWindow, Color, CCFlags, Template, TRUE, nil);
- end;
-
- procedure TMenuWindow.CMColorText (var Msg: TMessage);
- var
- CCFlags : LongInt;
- Template : Integer;
- begin
- CCFlags := CC_RGBINIT;
- Template := GetSFXTemplateId('SFX3DDlg', DLG_EXCOLOR);
- SFXChooseColor(HWindow, TextColor, CCFlags, Template, TRUE, nil);
- end;
-
- procedure TMenuWindow.CMAbout (var Msg: TMessage);
- begin
- Application^.ExecDialog(New(PAboutDialog, Init(@Self, 'AboutDialog')));
- end;
-
- {********** TAboutDialog **********}
-
- procedure TAboutDialog.SetUpWindow;
- begin
- TDialog.Setupwindow;
- CenterWindow(Parent^.HWindow, HWindow);
- end;
-
- {********** Main program **********}
-
- var
- App: TMenuApp;
- begin
- App.Init(AppName);
- App.Run;
- App.Done;
- end.
-