Kip Posted September 2, 2008 Share Posted September 2, 2008 (edited) Register your own classes, get rid of "AutoIt v3 GUI"Q: What are classes?A: If you dont know that, just skip this topic.Q: Why should I create my own class, instead of using autoit's standard class?A: There are some extra's, you can't do with AutoIt's class. Like: dropping a shadow under a window and setting a custom cursor for your GUIs.Ok, original function created by amel27, and I made it work without any bugs.There are some extra functions in the file: _WinAPI_LoadCursor() and RGB_to_BGR(), because I needed them. And well, I thought lets mention them too in case someone needs them.Ofcourse there is an unregister function: _WinAPI_UnregisterClass($sClassName)Function:expandcollapse popup#cs _WinAPI_RegisterClassEx($sClassName, $sCallbackFunction, $hIcon=0, $hCursor=0, $iBkColor=$COLOR_BTNFACE, $iStyle=$CS_DEFAULTSTYLE) $sClassName - Classname $sCallbackFunction - WindowProc callback function $hIcon - Handle to a icon which will be be used as the window icon (Default = application icon) $hCursor - Handle to cursor which will be used as the window cursor (Default = arraow cursor) Use _WinAPI_LoadCursor() [also included with this UDF] to load a system cursor: $CURSOR_ARROW $CURSOR_IBEAM $CURSOR_WAIT $CURSOR_CROSS $CURSOR_UPARROW $CURSOR_SIZENWSE $CURSOR_SIZENESW $CURSOR_SIZEWE $CURSOR_SIZENS $CURSOR_SIZEALL $CURSOR_NO $CURSOR_APPSTARTING $CURSOR_HELP Example: _WinAPI_LoadCursor(0, $CURSOR_IBEAM) Do not use the $IDC_ constants declared in Constants.au3 $iBkColor - RGB color code of window background color $iStyle - Class style. A combination of these values: (Default = $CS_DEFAULTSTYLE) $CS_VREDRAW $CS_HREDRAW $CS_DBLCLKS $CS_OWNDC $CS_CLASSDC $CS_PARENTDC $CS_NOCLOSE $CS_SAVEBITS $CS_BYTEALIGNCLIENT $CS_BYTEALIGNWINDOW $CS_GLOBALCLASS $CS_DROPSHADOW Function: Creating a class which can be used with CreateWindowEx, and others Author: Original - amel27 Working version - Kip #ceHave fun creating classes. _RegisterClassEx.au3 Edited September 2, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Kip Posted September 2, 2008 Author Share Posted September 2, 2008 (edited) Example: #Include <WinAPI.au3> #Include <WindowsConstants.au3> #include <_RegisterClassEx.au3> $hCursor = _WinAPI_LoadCursor(0,$CURSOR_HELP) _WinAPI_RegisterClassEx("MyOwnClass", "WindowCallback", 0, $hCursor, 0xFF0000, $CS_DEFAULTSTYLE+$CS_DROPSHADOW); Creates a class with a red bgcolor, and a shadow under the window $hWnd = _WinAPI_CreateWindowEx(0, "MyOwnClass", "Window with custom class", $WS_OVERLAPPEDWINDOW, 100, 100, 400, 300, 0) _WinAPI_ShowWindow($hWnd) While 1 WEnd Func WindowCallback($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_CLOSE _WinAPI_UnregisterClass("MyOwnClass") Exit EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc Edited September 2, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
James Posted September 2, 2008 Share Posted September 2, 2008 Nice work Kip! I shall try this when I get home Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
gseller Posted September 2, 2008 Share Posted September 2, 2008 Cool, I like the drop shadow example.. Thanks for sharing.. Link to comment Share on other sites More sharing options...
Kip Posted September 2, 2008 Author Share Posted September 2, 2008 Added _WinAPI_UnregisterClass() MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted September 2, 2008 Share Posted September 2, 2008 Very nice job Kip! Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
GtaSpider Posted September 2, 2008 Share Posted September 2, 2008 (edited) Nice Quick example: expandcollapse popup#Include <WinAPI.au3> #Include <WindowsConstants.au3> #include <_RegisterClassEx.au3> #include<GDIPlus.au3> $hCursor = _WinAPI_LoadCursor(0,$CURSOR_HELP) _WinAPI_RegisterClassEx("MyOwnToolTipClass", "WindowCallback", 0, $hCursor, 0xFFFFE1, $CS_DEFAULTSTYLE+$CS_DROPSHADOW); Creates a class with a red bgcolor, and a shadow under the window $hWnd = _WinAPI_CreateWindowEx(0, "MyOwnToolTipClass", "Window with custom class", $WS_POPUP, 100, 100, 150, 30, 0) _GDIPlus_Startup () WinSetTrans($hWnd,"",0) _WinAPI_ShowWindow($hWnd) $hGraph = _GDIPlus_GraphicsCreateFromHWND($hWnd) _GDIPlus_GraphicsDrawString($hGraph,"My Own ToolTip Class",8,8) for $i = 0 To 255 Step 2 WinSetTrans($hWnd,"",$i) Sleep(Random(0,1,1)) Next Sleep(2000) for $i = 255 To 0 Step -2 WinSetTrans($hWnd,"",$i) Sleep(Random(0,1,1)) Next Func WindowCallback($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_CLOSE _WinAPI_UnregisterClass("MyOwnToolTipClass") Exit EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc Edited September 2, 2008 by GtaSpider www.AutoIt.de - Moderator of the German AutoIt Forum  Link to comment Share on other sites More sharing options...
ptrex Posted September 2, 2008 Share Posted September 2, 2008 @Kip Very nice indead !! regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Nahuel Posted September 2, 2008 Share Posted September 2, 2008 Excellent! Link to comment Share on other sites More sharing options...
Kip Posted September 2, 2008 Author Share Posted September 2, 2008 $hGraph = _GDIPlus_GraphicsCreateFromHWND($hWnd) _GDIPlus_GraphicsDrawString($hGraph,"My Own ToolTip Class",8,8)Why GDI, why not just a label control? $hNew = _WinApi_CreateWindowEx(0, "Static", "My label text", $WS_VISIBLE+$WS_CHILD+$WS_CAPTION, $iX, $iY, $iWidth, $iHeight, $hWnd) (I dont get it why a label isn't included with the UDFs) MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
GtaSpider Posted September 2, 2008 Share Posted September 2, 2008 Label wont work for GDI Gui, because not AutoIt creats the GUI. WinApi does. Spider www.AutoIt.de - Moderator of the German AutoIt Forum  Link to comment Share on other sites More sharing options...
Kip Posted September 2, 2008 Author Share Posted September 2, 2008 (edited) Thats why you should read my example, just one line below. Here is the code again: $hNew = _WinApi_CreateWindowEx(0, "Static", "My label text", $WS_VISIBLE+$WS_CHILD+$WS_CAPTION, $iX, $iY, $iWidth, $iHeight, $hWnd) That creates an label control!. Edited September 2, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Zedna Posted September 2, 2008 Share Posted September 2, 2008 Nice kip!! Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
SxyfrG Posted September 3, 2008 Share Posted September 3, 2008 YOU ARE THE GREATEST EVER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I've been looking for a way to get a shadow under your window without having to use a .png as your background and all that stuff for a LONG LONG TIME! My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website Link to comment Share on other sites More sharing options...
Kip Posted September 3, 2008 Author Share Posted September 3, 2008 Thanks everybody :} MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
MrCreatoR Posted September 3, 2008 Share Posted September 3, 2008 Nice, but only problem that i have using it, is that GUIRegisterMsg() will not work with this created window, we will have to build all these stuff manualy (by WinAPI i supose). I thought that this will help me to make an interaction between two scripts, with custom classname it should be more reliable/unique.  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Kip Posted September 3, 2008 Author Share Posted September 3, 2008 (edited) Nice, but only problem that i have using it, is that GUIRegisterMsg() will not work with this created windowThe code isnt much longer. This: While 1 $Msg = GuiGetMsg() switch $Msg case $GUI_EVENT_CLOSE Exit endswitch WEnd Or this: Func WindowCallback($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_CLOSE Exit EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc Edited September 3, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
MrCreatoR Posted September 3, 2008 Share Posted September 3, 2008 The code isnt much longer. or this: While 1 $Msg = GuiGetMsg() switch $Msg case $GUI_EVENT_CLOSE Exit endswitch WEnd or: Func WindowCallback($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_CLOSE Exit EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc Wow, it's that simple - Thanks.  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Kip Posted September 3, 2008 Author Share Posted September 3, 2008 It even gives you more possibilities. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
wraithdu Posted September 3, 2008 Share Posted September 3, 2008 (edited) Example showing a button with user font and event. Creating all the controls and events would be really tedious for a complicated GUI.... expandcollapse popup#Include <WinAPI.au3> #Include <WindowsConstants.au3> #include <_RegisterClassEx.au3> #include <ButtonConstants.au3> #include <FontConstants.au3> $hCursor = _WinAPI_LoadCursor(0,$CURSOR_HELP) $hFont = _WinAPI_CreateFont(16, 6, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') _WinAPI_RegisterClassEx("MyOwnClass", "WindowCallback", 0, $hCursor, 0xFF0000, $CS_DEFAULTSTYLE+$CS_DROPSHADOW); Creates a class with a red bgcolor, and a shadow under the window $hWnd = _WinAPI_CreateWindowEx(0, "MyOwnClass", "Window with custom class", $WS_OVERLAPPEDWINDOW, 100, 100, 400, 300, 0) $hNew = _WinApi_CreateWindowEx(0, "Button", "Click", BitOR($WS_VISIBLE, $WS_CHILD), 10, 10, 50, 30, $hWnd) $iNew = _WinAPI_GetDlgCtrlID($hNew) _SendMessage($hNew, $WM_SETFONT, $hFont, 1) _WinAPI_ShowWindow($hWnd) While 1 WEnd Func WindowCallback($hWnd, $iMsg, $wParam, $lParam) Local $iNC, $iID Switch $iMsg Case $WM_CLOSE _WinAPI_DeleteObject($hFont) _WinAPI_UnregisterClass("MyOwnClass") Exit Case $WM_COMMAND $iNC = _WinAPI_HiWord($wParam) $iID = _WinAPI_LoWord($wParam) Switch $iNC Case $BN_CLICKED Switch $iID Case $iNew MsgBox(0, "Event", "Clicked the button!") EndSwitch EndSwitch EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc If nothing else, this procedure gives more insight into how windows are created and how they function. I like it! Edited September 3, 2008 by wraithdu 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