mohammadezazi Posted June 16, 2013 Share Posted June 16, 2013 (edited) Hi I has been wrote a script for display a menu that contains Arabic items. I want to display items in right-to-left format. But I can't . Please help me. I think that I need a command such this : Local $hMenu = TrayItemGetHandle(0) ; Get the internal menu handle $hDC = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hMenu) $hDC = $hDC[0] DllCall("gdi32.dll", "int", "SetTextAlign", "hwnd", $hDC, "int", "TA_RIGHT|TA_TOP|TA_UPDATECP") Also how I can use TA_RTLREADING parameter in SetTextAlign function? Edited June 16, 2013 by mohammadezazi Link to comment Share on other sites More sharing options...
Mat Posted June 16, 2013 Share Posted June 16, 2013 Not sure what you want the output to look like, I know nothing about arabic or any language other than english I'm afraid. Menu's have a rtl property that should be used (you are using completely the wrong function, unless you intend to custom draw all the menu items). Unfortunately the AutoIt wrapper around _GUICtrlMenu_TrackPopupMenu doesn't support it, so I added it to a new function _GUICtrlMenu_TrackPopupMenu2. Below is an example which shows the normal version and the new one. To use in your code, you need to use a UDF menu, rather than the standard tray menu functions. When the user clicks the tray you then call TrackPopupMenu. It's a bit of extra work, but I don't see any alternative. expandcollapse popup#include <GUIMenu.au3> $hWindow = WinGetHandle(AutoItWinGetTitle()) $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "مرحبا") _GUICtrlMenu_InsertMenuItem($hMenu, 1, "بسيطة") _GUICtrlMenu_TrackPopupMenu($hMenu, $hWindow, -1, -1, 1, 1, 0, 0) _GUICtrlMenu_TrackPopupMenu2($hMenu, $hWindow, -1, -1, 1, 1, 0, 0, True) _GUICtrlMenu_DestroyMenu($hMenu) Func _GUICtrlMenu_TrackPopupMenu2($hMenu, $hWnd, $iX = -1, $iY = -1, $iAlignX = 1, $iAlignY = 1, $iNotify = 0, $iButtons = 0, $fRtl = False) If $iX = -1 Then $iX = _WinAPI_GetMousePosX() If $iY = -1 Then $iY = _WinAPI_GetMousePosY() Local $iFlags = 0 Switch $iAlignX Case 1 $iFlags = BitOR($iFlags, $TPM_LEFTALIGN) Case 2 $iFlags = BitOR($iFlags, $TPM_RIGHTALIGN) Case Else $iFlags = BitOR($iFlags, $TPM_CENTERALIGN) EndSwitch Switch $iAlignY Case 1 $iFlags = BitOR($iFlags, $TPM_TOPALIGN) Case 2 $iFlags = BitOR($iFlags, $TPM_VCENTERALIGN) Case Else $iFlags = BitOR($iFlags, $TPM_BOTTOMALIGN) EndSwitch If BitAND($iNotify, 1) <> 0 Then $iFlags = BitOR($iFlags, $TPM_NONOTIFY) If BitAND($iNotify, 2) <> 0 Then $iFlags = BitOR($iFlags, $TPM_RETURNCMD) Switch $iButtons Case 1 $iFlags = BitOR($iFlags, $TPM_RIGHTBUTTON) Case Else $iFlags = BitOR($iFlags, $TPM_LEFTBUTTON) EndSwitch If $fRtl Then $iFlags = BitOR($iFlags, $TPM_LAYOUTRTL) Local $aResult = DllCall("User32.dll", "bool", "TrackPopupMenu", "handle", $hMenu, "uint", $iFlags, "int", $iX, "int", $iY, "int", 0, "hwnd", $hWnd, "ptr", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc ;==>_GUICtrlMenu_TrackPopupMenu AutoIt Project Listing Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted June 16, 2013 Share Posted June 16, 2013 Hi, You will need the Extended Style $WS_EX_LAYOUTRTL Example $sGUI = GUICreate("Right-To-Left", 800, 525, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX), $WS_EX_LAYOUTRTL) Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
mohammadezazi Posted June 17, 2013 Author Share Posted June 17, 2013 (edited) Thank you very much. for your nice replys. But i couldn't use any of your solutions due to my weak knowledge about AutoIt and programming. Here is a part of my main code. If you help me to justificate my menus items in right hand, ill be grateful. Plz run it to see my purpose again. #include <Process.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <Constants.au3> #NoTrayIcon ;-------------------------------------------------------- Opt("TrayMenuMode", 1) ;----------------Create Menu----------------------------------- Local $webservicesitem = TrayCreateMenu("سرويسهاي وب") Local $item1 = TrayCreateItem("سرويس وب اول", $webservicesitem) Local $item2 = TrayCreateItem("اتوماسيون", $webservicesitem) Local $item3 = TrayCreateItem("منابع انساني", $webservicesitem) Local $item4 = TrayCreateItem("I want to justify these Arabic items to the right side of submenu", $webservicesitem) Local $item5 = TrayCreateItem("کدينگ", $webservicesitem) Local $item4 = TrayCreateItem("How I can justify these items Arabic texts to right side of menu?") Local $aboutitem = TrayCreateItem("About") Local $Exititem = TrayCreateItem("خروج") TraySetState() ;-------------------------------------------------------- While 1 Local $msg = TrayGetMsg() TrayItemSetState($msg,4) Select Case $msg = 0 ContinueLoop Case $msg = $item1 Local $rc = _RunDos("start Http://www.google.com") Edited June 19, 2013 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Mat Posted June 17, 2013 Share Posted June 17, 2013 Like I said previously, you can't use the standard AutoIt menu, so there are a couple of extra steps. Is this the output you were expecting? expandcollapse popup#include <Constants.au3> #include <MenuConstants.au3> #include <GUIMenu.au3> #include <Process.au3> #NoTrayIcon Opt("TrayMenuMode", 1) Local Enum $item1 = 1000, $item2, $item3, $item4, $item5, $item6, $itemAbout, $itemExit Local $hWindow = WinGetHandle(AutoItWinGetTitle()) ;----------------Create Menu----------------------------------- Local $webservicesitem = _GUICtrlMenu_CreatePopup("سرويسهاي وب") _GUICtrlMenu_AddMenuItem($webservicesitem, "سرويس وب اول", $item1) _GUICtrlMenu_AddMenuItem($webservicesitem, "اتوماسيون", $item2) _GUICtrlMenu_AddMenuItem($webservicesitem, "منابع انساني", $item3) _GUICtrlMenu_AddMenuItem($webservicesitem, "I want to justify these Arabic items to the right side of submenu", $item4) _GUICtrlMenu_AddMenuItem($webservicesitem, "کدينگ", $item5) _GUICtrlMenu_AddMenuItem($webservicesitem, "How I can justify these items Arabic texts to right side of menu?", $item6) _GUICtrlMenu_AddMenuItem($webservicesitem, "About", $itemAbout) _GUICtrlMenu_AddMenuItem($webservicesitem, "خروج", $itemExit) TraySetState() TraySetClick(0) ;-------------------------------------------------------- While 1 Local $msg = TrayGetMsg() If $msg = $TRAY_EVENT_SECONDARYDOWN Then $item = _GUICtrlMenu_TrackPopupMenu2($webservicesitem, $hWindow, -1, -1, 1, 1, 2, 0, True) Select Case $item = 0 ContinueLoop Case $item = $item1 Local $rc = _RunDos("start Http://www.google.com") mohammadezazi 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
mohammadezazi Posted June 18, 2013 Author Share Posted June 18, 2013 (edited) Thanks a million million ill insert it to my code and reply the result. Edited June 18, 2013 by mohammadezazi Link to comment Share on other sites More sharing options...
mohammadezazi Posted June 19, 2013 Author Share Posted June 19, 2013 (edited) Very thanks again. for your help and nice function.It works fine. Now my problems reduces downto 2 problems: 1) I can't create any sub menu in this method. for example, i want to ; item4 and item5 and item6 be a submenu for item2 . 2) When the menu pops up, the user must and must select an item and does not has any other way!! it means that if the user does not selects an item, the menu will not disappear ! This is my test code. thanks for any help expandcollapse popup;------------------------------------------------ #include <Constants.au3> #include <MenuConstants.au3> #include <GUIMenu.au3> #include <Process.au3> #NoTrayIcon Opt("TrayMenuMode", 1) Local Enum $item1 = 1000, $item2, $item3, $item4, $item5, $item6, $itemAbout, $itemExit ;Local Enum $item Local $hWindow = WinGetHandle(AutoItWinGetTitle()) ;----------------Create Menu----------------------------------- Local $mymainmenu = _GUICtrlMenu_CreatePopup("") _GUICtrlMenu_AddMenuItem($mymainmenu, "First right aligned item", $item1) _GUICtrlMenu_AddMenuItem($mymainmenu, "Second right aligned item", $item2) _GUICtrlMenu_AddMenuItem($mymainmenu, "Third right aligned item", $item3) ;Local $secondnmenu = _GUICtrlMenu_CreatePopup("") ;_GUICtrlMenu_AddMenuItem($secondnmenu, "TthirdSub1", $item3-1) ;_GUICtrlMenu_AddMenuItem($secondnmenu, "ThirdSub2", $item3-2) ;_GUICtrlMenu_AddMenuItem($secondnmenu, "ThirdSub3", $item3-3) _GUICtrlMenu_AddMenuItem($mymainmenu, "About", $itemAbout) _GUICtrlMenu_AddMenuItem($mymainmenu, "خروج", $itemExit) TraySetState() TraySetClick(0) ;-------------------------------------------------------- While 1 Local $msg = TrayGetMsg() If $msg = $TRAY_EVENT_SECONDARYDOWN Then Local $item = _GUICtrlMenu_TrackPopupMenu2($mymainmenu, $hWindow, -1, -1, 1, 1, 2, 0, True) Select Case $item = 0 ContinueLoop Case $item = $item1 MsgBox(64, "item1", "itm1") Case $item = $item2 MsgBox(64, "item2", "itm2") Case $item = $item3 MsgBox(64, "item3", "item3") Case $item = $itemAbout msgbox(64, "درباره", "درباره") Case $item = $itemexit ExitLoop EndSelect EndIf WEnd Exit Func _GUICtrlMenu_TrackPopupMenu2($hMenu, $hWnd, $iX = -1, $iY = -1, $iAlignX = 1, $iAlignY = 1, $iNotify = 0, $iButtons = 0, $fRtl = False) If $iX = -1 Then $iX = _WinAPI_GetMousePosX() If $iY = -1 Then $iY = _WinAPI_GetMousePosY() Local $iFlags = 0 Switch $iAlignX Case 1 $iFlags = BitOR($iFlags, $TPM_LEFTALIGN) Case 2 $iFlags = BitOR($iFlags, $TPM_RIGHTALIGN) Case Else $iFlags = BitOR($iFlags, $TPM_CENTERALIGN) EndSwitch Switch $iAlignY Case 1 $iFlags = BitOR($iFlags, $TPM_TOPALIGN) Case 2 $iFlags = BitOR($iFlags, $TPM_VCENTERALIGN) Case Else $iFlags = BitOR($iFlags, $TPM_BOTTOMALIGN) EndSwitch If BitAND($iNotify, 1) <> 0 Then $iFlags = BitOR($iFlags, $TPM_NONOTIFY) If BitAND($iNotify, 2) <> 0 Then $iFlags = BitOR($iFlags, $TPM_RETURNCMD) Switch $iButtons Case 1 $iFlags = BitOR($iFlags, $TPM_RIGHTBUTTON) Case Else $iFlags = BitOR($iFlags, $TPM_LEFTBUTTON) EndSwitch If $fRtl Then $iFlags = BitOR($iFlags, $TPM_LAYOUTRTL) Local $aResult = DllCall("User32.dll", "bool", "TrackPopupMenu", "handle", $hMenu, "uint", $iFlags, "int", $iX, "int", $iY, "int", 0, "hwnd", $hWnd, "ptr", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc ;==>_GUICtrlMenu_TrackPopupMenu Edited June 19, 2013 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Mat Posted June 19, 2013 Share Posted June 19, 2013 1) To create sub menus, you first create the sub menu with _GUICtrlMenu_CreateMenu, and then add it using this $hSubMenu argument of _GUICtrlMenu_AddMenuItem. 2) This seems to be a problem which occurs if the window passed to TrackPopupMenu is not visible. A quick workaround is to create a visible window, that is positioned off screen: #include <GUIMenu.au3> $hSubMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hSubMenu, "Submenu 1") _GUICtrlMenu_AddMenuItem($hSubMenu, "Submenu 2") _GUICtrlMenu_AddMenuItem($hSubMenu, "Submenu 3") $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($hMenu, "Menu 1") _GUICtrlMenu_AddMenuItem($hMenu, "Submenu", 0, $hSubMenu) _GUICtrlMenu_AddMenuItem($hMenu, "Menu 2") $hGUI = GUICreate("Test", 1, 1, -100, -100) GUISetState() _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) argumentum 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2013 Moderators Share Posted June 19, 2013 mohammadezazi, When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see in Mat's posts - and your post above now I have added the tags. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mohammadezazi Posted June 20, 2013 Author Share Posted June 20, 2013 (edited) Hi and thanks for your attentions. Best reagards for mat. Excuse me for my weakness in programming. I completed my code with your nice function and all my items aligned to right side of menu according to my needs. but there is a problem: The item numbers that are returned by function _GUICtrlMenu_TrackPopupMenu2 does not match by any of my items in menu ! Function _GUICtrlMenu_TrackPopupMenu2 returns wonderful numbers for each item and some of them are duplicated !! How i can match them by menus items. I think that i must get the controlID of each item. You can see this matter by running this test code. I show the returned values by MsgBox() command. 1) Please help me about matching item IDs by the returned values from function. 2) What type of data must items have? and why you set the 1000 value for item1 in your help code, at top of this post? But ,Hi Melba23; the reason for my inserting codes directly into my posts is: the AutoIt text box seems that has restrictions such limitation to 38 lines or some small bugs. you can see this matter in Mat's post above. you see that his Code has been inserted just to line 38: Local $rc = _RunDos("start Http://www.google.com") !! and it is incomplete. expandcollapse popup#include <Process.au3> #include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiMenu.au3> Local Enum $item1 = 1000 Local Enum $item2, $item3, $item4, $item5, $item6, $item7, $item8, $item9, $item10, $item11, $item12, $item13, $item14, $item15, $item16, $item17, $item18, $item19 Local Enum $item20, $item21, $item22, $item23, $item24, $item25, $item26, $item27, $item28, $item29, $item30, $item31, $item32, $item33, $item34, $item35, $item36, $item37, $item38, $item39 Local Enum $item40, $item41, $item42, $item43, $item44, $item45, $item46, $item47, $item48, $item49, $item50, $item51, $item52, $item53, $item54, $item55, $item56, $item57, $item58, $item59 Local Enum $item60, $item61, $item62, $item63, $item64, $item65, $item66, $item67, $item68, $item69, $item70, $item71, $item72, $item73, $item74, $item75, $item76, $item77, $item78, $item79 Local Enum $item80, $item81, $item82, $item83, $item84, $item85, $item86, $item87, $item88, $item89, $item90, $item91, $item92, $item93, $item94, $item95, $item96, $item97, $item98, $item99 Local Enum $itemAbout, $itemExit, $hamksub, $filersub, $nettestsub Opt("TrayMenuMode", 1) ;Default tray menu items (Script Paused/Exit) will not be shown. Local $hWindow = WinGetHandle(AutoItWinGetTitle()) ;----------------Create Menu----------------------------------- $hNetworkTests = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hNetworkTests, "تست ارتباط با فايلسرور", $item56) _GUICtrlMenu_AddMenuItem($hNetworkTests, "تست ارتباط با سرور دامنه", $item57) _GUICtrlMenu_AddMenuItem($hNetworkTests, "تست ارتباط با سرور ديتابيس", $item58) $hHamkaran = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hHamkaran, "ايجاد آيکون اجراي سيستم همکاران-سيستم روي دسکتاپ", $item76) _GUICtrlMenu_AddMenuItem($hHamkaran, "نصب کامل سيستم همکاران-سيستم", $item18) $hFilerpro = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hFilerpro, "نصب يا به روزرساني سيستم آرشيو - فايلرپرو", $item19) _GUICtrlMenu_AddMenuItem($hFilerpro, "تنظيم سرور فايلرپرو و اجراي فايلرپرو", $item83) $hInstallSofts = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hInstallSofts, "Install Office 2007", $item69) _GUICtrlMenu_AddMenuItem($hInstallSofts, "Install Office 2007 SP3", $item70) $hSomeTools = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hSomeTools, "اصلاح برخي تنظيمات ويندوز شما و تطبيق آن با شبکه", $item50) _GUICtrlMenu_AddMenuItem($hSomeTools, "مشخصات سخت افزاري کامپيوتر شما", $item51) _GUICtrlMenu_AddMenuItem($hSomeTools, "تستهاي شبکه", $nettestsub) _GUICtrlMenu_SetItemSubMenu($hSomeTools, $nettestsub, $hNetworkTests, 0) $hMainMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($hMainMenu, "نصب نرم افزار", 0, $hInstallSofts) _GUICtrlMenu_AddMenuItem($hMainMenu, "چند ابزار", 0, $hSomeTools) _GUICtrlMenu_AddMenuItem($hMainMenu, "درباره", $itemAbout) _GUICtrlMenu_AddMenuItem($hMainMenu, "خروج", $itemexit) ;$hGUI = GUICreate("Test", 100, 100, -100, -100) ;GUISetState() ;_GUICtrlMenu_TrackPopupMenu($hMainMenu, $hGUI) ;TraySetState() ;TraySetClick(0) ;TraySetToolTip("Welcome to network") ;-------------------------------------------------------- While 1 Local $msg = TrayGetMsg() ;Local $item = GUIGetMsg() ;msgbox(64,"msg is", $msg) ;TrayItemSetState($msg,4) If $msg = $TRAY_EVENT_SECONDARYDOWN Then $item = _GUICtrlMenu_TrackPopupMenu2($hMainMenu, $hWindow, -1, -1, 1, 1, 2, 0, True) msgbox(64,"item is", $item) Select Case $item = 0 ContinueLoop Case $item = $item1 MsgBox(64, "item 1 selected", "item 1 selected") Case $item = $item2 MsgBox(64, "item 2 selected", "item 2 selected") Case $item = $item3 MsgBox(64, "item 3 selected", "item 3 selected") Case $item = $itemAbout MsgBox(64, "About", "This tool has been developed by network-team") Case $item = $itemexit Exit EndSelect EndIf WEnd Exit ;======================================================================================================================== Func _GUICtrlMenu_TrackPopupMenu2($hMenu, $hWnd, $iX = -1, $iY = -1, $iAlignX = 1, $iAlignY = 1, $iNotify = 0, $iButtons = 0, $fRtl = False) If $iX = -1 Then $iX = _WinAPI_GetMousePosX() If $iY = -1 Then $iY = _WinAPI_GetMousePosY() Local $iFlags = 0 Switch $iAlignX Case 1 $iFlags = BitOR($iFlags, $TPM_LEFTALIGN) Case 2 $iFlags = BitOR($iFlags, $TPM_RIGHTALIGN) Case Else $iFlags = BitOR($iFlags, $TPM_CENTERALIGN) EndSwitch Switch $iAlignY Case 1 $iFlags = BitOR($iFlags, $TPM_TOPALIGN) Case 2 $iFlags = BitOR($iFlags, $TPM_VCENTERALIGN) Case Else $iFlags = BitOR($iFlags, $TPM_BOTTOMALIGN) EndSwitch If BitAND($iNotify, 1) <> 0 Then $iFlags = BitOR($iFlags, $TPM_NONOTIFY) If BitAND($iNotify, 2) <> 0 Then $iFlags = BitOR($iFlags, $TPM_RETURNCMD) Switch $iButtons Case 1 $iFlags = BitOR($iFlags, $TPM_RIGHTBUTTON) Case Else $iFlags = BitOR($iFlags, $TPM_LEFTBUTTON) EndSwitch If $fRtl Then $iFlags = BitOR($iFlags, $TPM_LAYOUTRTL) Local $aResult = DllCall("User32.dll", "bool", "TrackPopupMenu", "handle", $hMenu, "uint", $iFlags, "int", $iX, "int", $iY, "int", 0, "hwnd", $hWnd, "ptr", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc ;==>_GUICtrlMenu_TrackPopupMenu Edited June 20, 2013 by mohammadezazi Link to comment Share on other sites More sharing options...
Mat Posted June 20, 2013 Share Posted June 20, 2013 The item ID is passed to the _GUICtrlMenu_AddMenuItem. That same ID is then returned from TrackPopupMenu. I start with 1000 because traditionally menus are resources, and so use resource ids. Good practice is always to use ids in certain ranges, so the id tells you at least a little bit about what its identifying. 1000 is just what I normally use for menus. I think your problem above (without running the code) is that you are using multiple Enums, all of which start at zero. As a result you are going to have duplicate ids. AutoIt Project Listing Link to comment Share on other sites More sharing options...
mohammadezazi Posted June 20, 2013 Author Share Posted June 20, 2013 (edited) Thank you all a bilion ! Everything works wel now. Edited June 23, 2013 by mohammadezazi Mat 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now