Jump to content

_WinAPI_RegisterClassEx()


Kip
 Share

Recommended Posts

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:

#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
 
 #ce

Have fun creating classes. ;)

_RegisterClassEx.au3

Edited by Kip
Link to comment
Share on other sites

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 by Kip
Link to comment
Share on other sites

Nice ;)

Quick example:

#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 by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

$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)

Link to comment
Share on other sites

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 by Kip
Link to comment
Share on other sites

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

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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Nice, but only problem that i have using it, is that GUIRegisterMsg() will not work with this created window

The 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 by Kip
Link to comment
Share on other sites

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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Example showing a button with user font and event. Creating all the controls and events would be really tedious for a complicated GUI....

#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 by wraithdu
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...