Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/26/2015 in all areas

  1. suppose you want to display only a single large control, e.g. a ListView. you have a lot of data, but it may be viewed on a small-screen device. you care about not wasting screen area, but you need at least a few basic operations. sure you could use a menu bar, but real estate is pricey these days... inspired by >this - but not even remotely similar in implementation - let's click on the title bar caption text to pop-up a menu! (while clicking on the vacant area of the title bar is used for dragging, as usual). first let's add a small drop-down-like sign to indicate it's possible to click on the caption text: (the red line indicates the width of the title bar that when clicked will pop-up a menu. it is slightly extended, to compensate for situations where the font is larger. it is here for illustration only). the menu is designed as usual, but triggered by registering the WM_SYSCOMMAND message, and checking that the cursor is at the correct position. unfortunately, Windows XP/2003 do not render extended characters (well or at all), so a standard character was selected for them - see screenshots below. Windows Vista also does a poor job at it. but even more unfortunately, Windows 8 has the title bar caption centered! so here's a quick'n'dirty solution: extend the caption with a lot of whitespaces. this has two side effects - there's the 3-dots sign near the "Minimize" button, and the taskbar icon tooltip is extended. i can live with that... so this is how it looks: Windows 8: Windows Vista: Windows XP: Windows 2000 (for the classic theme): the script (uses >_StringSize by Melba23, but you can set the size fix according to your needs): #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "StringSize.au3" Global $nGUI_W = 700, $nGUI_H = 500 Global $sTitle = 'My Program Title' Global $nOSVersion = _OSVersion() If $nOSVersion < 6 Then ; not rendering ChrW well $sTitle = ' :: ' & $sTitle Else $sTitle &= ' ' & ChrW(9662) EndIf Global $aTitleWidth = _StringSize($sTitle) Global $iTitleWidth = 0 If Not @error Then $iTitleWidth = $aTitleWidth[2] + 3 ; ampirical Global $iTitleOffset = 20 ; ampirical: 16px icon + 4px space If $nOSVersion > 6.1 Then ; Windows 8, Windows 2012 => "align" caption to left, consider increased font size $sTitle &= ' ' $iTitleOffset = $iTitleOffset * 1.2 ; ampirical EndIf $iTitleWidth = $iTitleWidth * 1.3 ; ampirical Global $hGUI = GUICreate($sTitle, $nGUI_W, $nGUI_H, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU)) ; indicative label for the position and width of titlebar caption text to trigger menu GUICtrlCreateLabel('', $iTitleOffset, 0, $iTitleWidth, 1) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetBkColor(-1, 0xff0000) Global $gMenu_Dummy = GUICtrlCreateDummy() Global $gMenu = GUICtrlCreateContextMenu($gMenu_Dummy) Global $gMenu_Submenu = GUICtrlCreateMenu('Submenu', $gMenu) Global $gMenu_Option = GUICtrlCreateMenuItem('Option', $gMenu) Global $bOption = True GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateMenuItem('', $gMenu) For $i = 1 To 5 GUICtrlCreateMenuItem('Submenu Item ' & $i, $gMenu_Submenu) GUICtrlSetState(-1, $GUI_CHECKED) Next GUICtrlCreateMenuItem('Item 1', $gMenu) GUICtrlCreateMenuItem('Item 2', $gMenu) GUICtrlCreateMenuItem('Item 3', $gMenu) GUICtrlCreateMenuItem('', $gMenu) Global $gMenu_About = GUICtrlCreateMenuItem('About', $gMenu) Global $gMenu_Close = GUICtrlCreateMenuItem('Close', $gMenu) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_SYSCOMMAND, '_WM_SYSCOMMAND') GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") Global $msg While True $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $gMenu_Close ExitLoop Case $gMenu_Option $bOption = Not $bOption If $bOption Then GUICtrlSetState($gMenu_Option, $GUI_CHECKED) Else GUICtrlSetState($gMenu_Option, $GUI_UNCHECKED) EndIf EndSwitch WEnd #region context menu and auxiliary funcs Func _ContextMenu_ShowMenu($hWnd, $nContextID, $CtrlID = 0, $n_dx = 0, $n_dy = 0) ; Show a menu in a given GUI window which belongs to a given GUI ctrl Local $arPos[4], $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) If $CtrlID Then $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] + $n_dx $y = $arPos[1] + $arPos[3] + $n_dy _ContextMenu_ClientToScreen($hWnd, $x, $y) _ContextMenu_TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc ;==>_ContextMenu_ShowMenu Func _ContextMenu_ClientToScreen($hWnd, ByRef $x, ByRef $y) ; Convert the client (GUI) coordinates to screen (desktop) coordinates Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) ; release Struct not really needed as it is a local $stPoint = 0 EndFunc ;==>_ContextMenu_ClientToScreen Func _ContextMenu_TrackPopupMenu($hWnd, $hMenu, $x, $y) ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc ;==>_ContextMenu_TrackPopupMenu Func _WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam) ; to display main menu when click titlebar caption #forceref $hWnd, $iMsg, $wParam, $lParam Local $iMousePos Local $iClientAreaPosX, $iClientAreaPosY If $wParam = 0x0000F012 Then $iMousePos = MouseGetPos(0) _ContextMenu_ClientToScreen($hGUI, $iClientAreaPosX, $iClientAreaPosY) If $iMousePos > $iClientAreaPosX + $iTitleOffset And $iMousePos < $iClientAreaPosX + $iTitleOffset + $iTitleWidth Then _ContextMenu_ShowMenu($hWnd, $gMenu) EndIf EndFunc ;==>_WM_SYSCOMMAND Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) ; to enforce minimum window size #forceref $hWnd, $iMsg, $wParam, $lParam Local $tagMaxinfo If $hWnd = $hGUI Then $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, $nGUI_W - 100) DllStructSetData($tagMaxinfo, 8, $nGUI_H - 100) Return 0 EndIf EndFunc ;==>_WM_GETMINMAXINFO Func _OSVersion() $sOSVersion = RegRead('HKLM\Software\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion') If @error Then Return SetError(1, 0, 0) Return Number($sOSVersion) EndFunc ;==>_OSVersion #endregion context menu and auxiliary funcs the entire thing is as crude as hell, and i'm sure there are many more elegant ways to improve it. enjoy!
    2 points
  2. Introduction JSON (Javascript Object Notation) is a popular data-interchange format and supported by a lot of script languages. On AutoIt, there is already a >JSON UDF written by Gabriel Boehme. It is good but too slow, and not supports unicode and control characters very well. So I write a new one (and of course, fast one as usual). I use a machine code version of JSON parser called "jsmn". jsmn not only supports standard JSON, but also accepts some non-strict JSON string. See below for example. Important Update!! I rename the library from jsmn.au3 to json.au3. All function names are changed, too. Decoding Function Json_Decode($Json) $Json can be a standard or non-standard JSON string. For example, it accepts: { server: example.com port: 80 message: "this looks like a config file" } The most JSON data type will be decoded into corresponding AutoIt variable, including 1D array, string, number, true, false, and null. JSON object will be decoded into "Windows Scripting Dictionary Object" retuned from ObjCreate("Scripting.Dictionary"). AutoIt build-in functions like IsArray, IsBool, etc. can be used to check the returned data type. But for Object and Null, Json_IsObject() and Json_IsNull() should be used. If the input JSON string is invalid, @Error will be set to $JSMN_ERROR_INVAL. And if the input JSON string is not finish (maybe read from stream?), @Error will be set to $JSMN_ERROR_PART. Encoding Function Json_Encode($Data, $Option = 0, $Indent = "\t", $ArraySep = ",\r\n", $ObjectSep = ",\r\n", $ColonSep = ": ") $Data can be a string, number, bool, keyword(default or null), 1D arrry, or "Scripting.Dictionary" COM object. Ptr will be converted to number, Binary will be converted to string in UTF8 encoding. Other unsupported types like 2D array, dllstruct or object will be encoded into null. $Option is bitmask consisting following constant: $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) $JSON_UNESCAPED_UNICODE ; Encode multibyte Unicode characters literally $JSON_UNESCAPED_SLASHES ; Don't escape / $JSON_HEX_TAG ; All < and > are converted to \u003C and \u003E $JSON_HEX_AMP ; All &amp;amp;amp;amp;s are converted to \u0026 $JSON_HEX_APOS ; All ' are converted to \u0027 $JSON_HEX_QUOT ; All " are converted to \u0022 $JSON_PRETTY_PRINT ; Use whitespace in returned data to format it $JSON_STRICT_PRINT ; Make sure returned JSON string is RFC4627 compliant $JSON_UNQUOTED_STRING ; Output unquoted string if possible (conflicting with $JSMN_STRICT_PRINT) Most encoding option have the same means like PHP's json_enocde() function. When $JSON_PRETTY_PRINT is set, output format can be change by other 4 parameters ($Indent, $ArraySep, $ObjectSep, and $ColonSep). Because these 4 output format parameters will be checked inside Jsmn_Encode() function, returned string will be always accepted by Jsmn_Decode(). $JSON_UNQUOTED_STRING can be used to output unquoted string that also accetped by Jsmn_Decode(). $JSON_STRICT_PRINT is used to check output format setting and avoid non-standard JSON output. So this option is conflicting with $JSON_UNQUOTED_STRING. Get and Put Functions Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) Json_Get(ByRef $Var, $Notation) These functions helps user to access object or array more easily. Both dot notation and square bracket notation can be supported. Json_Put() by default will create non-exists objects and arrays. For example: Local $Obj Json_Put($Obj, ".foo", "foo") Json_Put($Obj, ".bar[0]", "bar") Json_Put($Obj, ".test[1].foo.bar[2].foo.bar", "Test") Local $Test = Json_Get($Obj, '["test"][1]["foo"]["bar"][2]["foo"]["bar"]') ; "Test" Object Help Functions Json_ObjCreate() Json_ObjPut(ByRef $Object, $Key, $Value) Json_ObjGet(ByRef $Object, $Key) Json_ObjDelete(ByRef $Object, $Key) Json_ObjExists(ByRef $Object, $Key) Json_ObjGetCount(ByRef $Object) Json_ObjGetKeys(ByRef $Object) Json_ObjClear(ByRef $Object) These functions are just warps of "Scripting.Dictionary" COM object. You can use these functions if you are not already familiar with it. == Update 2013/05/19 == * Add Jsmn_Encode() option "$JSMN_UNESCAPED_ASCII". Now the default output of Json_Encode() is exactly the same as PHP's json_encode() function (for example, chr(1) will be encoded into u0001). $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) == Update 2015/01/08 == * Rename the library from jsmn.au3 to json.au3. All function names are changed, too. * Add Json_Put() and Json_Get() * Add Null support * Using BinaryCall.au3 to loading the machine code. == Update 2018/01/13== (Jos) * Add JsonDump() to list all Json Keys and their values to easily figure out what they are. == Update 2018/10/01== (Jos) * Fixed JsonDump() some fields and values were not showing as discussed here - tnx @TheXman . == Update 2018/10/01b== (Jos) * Added Json_ObjGetItems, Tidied source and fixed au3check warnings - tnx @TheXman . == Update 2018/10/28== (Jos) * Added declaration for $value to avoid au3check warning - tnx @DerPensionist == Update 2018/12/16== (Jos) * Added another declaration for $value to avoid au3check warning and updated the version at the top - tnx @maniootek == Update 2018/12/29== (Jos) * Changed Json_ObjGet() and Json_ObjExists() to allow for multilevel object in string. == Update 2019/01/17== (Jos) * Added support for DOT notation in JSON functions. == Update 2019/07/15== (Jos) * Added support for reading keys with a dot inside when using a dot as separator (updated) == Update 2021/11/18== (TheXman) * Update details in below post: == Update 2021/11/20== (TheXman) * Minor RegEx update, no change to the functionality or result._Json(2021.11.20).zip
    1 point
  3. jmon

    Calendar UDF (WIP)

    Hello everyone, I started working on this calendar control for my company. It's still a work in progress, and there are some bugs and some features missing, but I still wanted to share it with you guys, to get some comments and ideas for future development. My question would be: "Would you have done it this way?", meaning, would you have built it with labels as I did, or would it be better using GDI+ or other methods? Screenshot: Here is an example (Try double-clicking on a date): #include <GUIConstantsEx.au3> #include "_CalendarUDF.au3" Opt("GUIOnEventMode", 1) Global $GUI, $fStartMonday = False, $iGridSize = 1, $sTheme = "Blue" _Main() Func _Main() Local $GUI = GUICreate("Calendar example", 800, 600, -1, -1, BitOR($WS_SYSMENU, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() GUICtrlCreateButton("Toggle grid", 20, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_ToggleGrid") GUICtrlCreateButton("Toggle Start Mon/Sun", 170, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_ToggleMondaySunday") GUICtrlCreateButton("Go to Date", 320, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_GoToDate") GUICtrlCreateButton("Add Event", 470, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_AddEvent") GUICtrlCreateButton("Switch theme", 620, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_SwitchTheme") ;Create the calendar control: _GuiCtrlCal_Create("My Calendar", 20, 40, 760, 520, @MON, @YEAR, 30, $fStartMonday, $iGridSize) ;Register my function, called when I double click a date: _GuiCtrlCal_OnDateDblClickRegister("_MyFunction") ;Add some Events: _GuiCtrlCal_EventAdd("2012/12/01", "World AIDS Day") _GuiCtrlCal_EventAdd("2012/12/25", "Christmas") _GuiCtrlCal_EventAdd("2012/12/21", "Winter Solstice") _GuiCtrlCal_EventAdd("2012/12/10", "Human Rights day") _GuiCtrlCal_EventAdd("2012/12/31", "Happy new year") _GuiCtrlCal_EventAdd("2013/01/11", "Human Trafficking Awareness") _GuiCtrlCal_EventAdd("2013/01/26", "Australia Day") ;Loop: While 1 Sleep(50) WEnd EndFunc ;This function will now be called when I doubleclick on a date. ;This function has to have one parameter that will contain ;the selected date: Func _MyFunction($sDate) ;The selected date is $sDate ConsoleWrite("Selected date is: " & $sDate & @CRLF) ;Create a small gui to input a text for the event: Local $mousePos = MouseGetPos() Local $GUIAddEvent = GUICreate("Add Event", 250, 50, $mousePos[0] - 125, $mousePos[1] - 15, $WS_POPUP, $WS_EX_TOPMOST, $GUI) GUISetState(@SW_SHOW, $GUIAddEvent) Local $Info = GUICtrlCreateLabel("Enter a text and press enter to add the event", 0, 0, 250, 15) Local $GUIAddEvent_Input = GUICtrlCreateInput("", 0, 15, 250, 35) GUICtrlSetState($GUIAddEvent_Input, $GUI_FOCUS) ;Wait for the user to press enter: While 1 If _IsPressed("0D") Then Do Sleep(10) Until Not _IsPressed("0D") ExitLoop EndIf Sleep(50) WEnd ;Read the text: Local $sText = GUICtrlRead($GUIAddEvent_Input) If $sText = "" Then Return GUIDelete($GUIAddEvent) ;Add the event: _GuiCtrlCal_EventAdd($sDate, $sText) EndFunc Func _Exit() _GuiCtrlCal_Destroy() Exit EndFunc Func Btn_ToggleGrid() If $iGridSize = 0 Then $iGridSize = 1 Else $iGridSize = 0 EndIf _GuiCtrlCal_SetGridSize($iGridSize) _GuiCtrlCal_Refresh() EndFunc Func Btn_ToggleMondaySunday() $fStartMonday = Not $fStartMonday _GuiCtrlCal_SetStartMonday($fStartMonday) _GuiCtrlCal_Refresh() EndFunc Func Btn_GoToDate() Local $sDate = InputBox("Go to Date", "Input the year, month and day : YYYY/MM/DD", @YEAR & "/" & @MON & "/" & @MDAY) If $sDate <> "" Then Local $aDate = StringSplit($sDate, "/") If Not @error Then _GuiCtrlCal_GoToMonth($aDate[1], $aDate[2]) _GuiCtrlCal_SetSelectedDate($sDate) EndIf EndIf EndFunc Func Btn_AddEvent() Local $sDateEvent = InputBox("Event Date", "Input the year, month and day (YYYY/MM/DD) for your event", @YEAR & "/" & @MON & "/" & @MDAY) If $sDateEvent = "" Then Return Local $sText = InputBox("Event Text", "Input the Text for your event", "My Event") If $sText = "" Then Return _GuiCtrlCal_EventAdd($sDateEvent, $sText) EndFunc Func Btn_SwitchTheme() Switch $sTheme Case "Blue" $sTheme = "Dark" _GuiCtrlCal_SetThemeDark() Case "Dark" $sTheme = "Blue" _GuiCtrlCal_SetThemeBlue() EndSwitch EndFunc And here is the UDF: _CalendarUDF.au3
    1 point
  4. JohnOne, Look at my Scrollbars UDF - GUIScrollbars_Size_Example_2 shows you how to do what you want. M23
    1 point
  5. Maybe overly complicated, but you can create a listview and only one edit and label...make the label and edit disabled until a listview item is selected...populate the label, and allow user to add data to the edit...add a button to submit the number to the listview, update the listview, and clear out the edit and label plus make disabled again.
    1 point
  6. 2. is pointless JohnOne is meaning _SQLite_Startup
    1 point
  7. Indeed, the sooner you learn how to figure stuff like this out, the sooner you're coding more independently.
    1 point
  8. Belini

    Video in Gui

    In win vista and win8 still have not tested but in win7 tested and works perfectly!
    1 point
  9. It's not really possible to "refresh" the registry. Some values can be changed freely and get an instant result, others require a restart. It depends on the program that is using the values. As for right-clicking and choosing next background... I think it would require some calls to Windows explorer.
    1 point
  10. The forum has been upgraded to IPB 3.4.7 which is just backend exploit/security fixes so there shouldn't be any visible changes that I know of. I've also fixed a number of database issues that would prevent a future upgrade to IPB 4 which is currently in the release candidate stage. Basically, the collation type of this forum was using utf_general_ci and IPB 4 will enforce utf8_unicode_ci.  Not a major difference but there were inconsistencies in database, table and column types in many places that needed fixing. When this forum was first created (IPB 1.2!) it was in latin1 and over the years it's gone through various upgrades and transitions to utf8 - I've just made sure everything is clean ready for any future upgrades. I'll be installing the release candidate of IPB 4 as a test forum on this site. I'll probably need help testing (especially the nightmare that will be getting autoit code tags working) so watch out for posts in the dev forum about that.
    1 point
  11. An example with web server - post + get Share you computer over http with user and password My_Computer_Web-Share.rar
    1 point
  12. Lol... I think I just figured it out. GUICtrlSetData($Edit1, StringRight(_GUICtrlEdit_GetText($Edit1), 25000)) Sorry for the quick post, replies and fix. Maybe this will help someone out at least?
    1 point
×
×
  • Create New...