Sign in to follow this  
Followers 0
Kip

GUICaret UDF

7 posts in this topic

#1 ·  Posted (edited)

My third UDF this week. I hope you like it as much as the other ones.

A caret can have multiple shapes, but does the same thing: showing you where the next next will be insterted.

Posted Image

Functions:

Func _Caret_Create($hWnd, $hBitmap=0, $iWidth=1, $iHeight=16)
 Func _Caret_Show($hWnd)
 Func _Caret_SetPos($iX, $iY)
 Func _Caret_SetBlinkTime($iTime); WARNING! Do not use this function! This is the same as setting the blink time in the Control Panel. Other applications will use this time too.
 Func _Caret_GetBlinkTime()
 Func _Caret_Hide($hWnd)
 Func _Caret_Destroy()
 Func _Caret_GetPos()

MSDN says that you should destroy the control everytime the window looses focus, and create it again when the focus is back.

I haven't got any error when I didn't, but if I were you I should do it anyway.

Example:

#Include <WindowsConstants.au3>
 #include <GuiConstantsEx.au3>
 #include <GuiCaret.au3>
 #include <WinAPI.au3>
 #include <Constants.au3>
 
 $GUI = GUICreate("bye",700,500)
     
     GUICtrlCreateLabel("This is a text which can't be edited",200,102,163)
     GUICtrlCreateLabel("(Altough it might looks like it.)",200,118,200)
     
     _Caret_Create($GUI); The blinking thing
     _Caret_SetPos(364, 100)
     _Caret_Show($GUI)
     
 GUISetState()
 
; >> These two functions are for registering messages. If you dont get these functions, just use GUIRegisterMsg()
 $sCallback = DllCallbackRegister("CallbackFunc","int","hwnd;uint;wparam;lparam")
 $MsgProc = _WinAPI_SetWindowLong(WinGetHandle($GUI),$GWL_WNDPROC,DllCallBackGetPtr($sCallback))
; <<
 
 
 While 1
     If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
 WEnd
 
 
 Func CallbackFunc($hWnd,$iMsg,$wParam,$lParam)
     
     Switch $hWnd
         Case $GUI
             
             Switch $iMsg
                 
                 Case $WM_KILLFOCUS
                     
                     _Caret_Destroy(); MSDN says that I should destroy it when the focus is lost...
                     
                 Case $WM_SETFOCUS
                     
                     _Caret_Create($hWnd); ... and create it again when the focus is set. Altough I havent seen any errors when I didn't destroyed it.
                     _Caret_SetPos(200, 100)
                     _Caret_Show($hWnd)
                     
             EndSwitch
             
             Return _WinAPI_CallWindowProc($MsgProc,$hWnd,$iMsg,$wParam,$lParam)
             
     EndSwitch
     
 EndFunc

GUICaret.au3

Edited by Kip

Share this post


Link to post
Share on other sites

Very nice UDF!

Thanks for sharing.

About the shapes of the caret, how do i set them? for example underline.


 

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

Share this post


Link to post
Share on other sites

Like this:?

That's it, thanks ;)

And how about bitmaps, can you please show an example of bitmap usage?


 

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

Share this post


Link to post
Share on other sites

#Include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiCaret.au3>
#include <WinAPI.au3>
#include <Constants.au3>


$GUI = GUICreate("bye",700,500)
    
     GUICtrlCreateLabel("This is a text which can't be edited",200,102,163)
     GUICtrlCreateLabel("(Altough it might looks like it.)",200,118,200)
    
     $hBitmap = _WinAPI_LoadImage(0, "pinch.bmp", $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
    
     _Caret_Create($GUI, $hBitmap); The blinking thing
     _Caret_SetPos(364, 100)
     _Caret_Show($GUI)
    
GUISetState()

; >> These two functions are for registering messages. If you dont get these functions, just use GUIRegisterMsg()
$sCallback = DllCallbackRegister("CallbackFunc","int","hwnd;uint;wparam;lparam")
$MsgProc = _WinAPI_SetWindowLong(WinGetHandle($GUI),$GWL_WNDPROC,DllCallBackGetPtr($sCallback))
; <<


While 1
     If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd


Func CallbackFunc($hWnd,$iMsg,$wParam,$lParam)
    
     Switch $hWnd
         Case $GUI
            
             Switch $iMsg
                
                 Case $WM_KILLFOCUS
                    
                     _Caret_Destroy(); MSDN says that I should destroy it when the focus is lost...
                    
                 Case $WM_SETFOCUS
                    
                     _Caret_Create($hWnd); ... and create it again when the focus is set. Altough I havent seen any errors when I didn't destroyed it.
                     _Caret_SetPos(200, 100)
                     _Caret_Show($hWnd)
                    
             EndSwitch
            
             Return _WinAPI_CallWindowProc($MsgProc,$hWnd,$iMsg,$wParam,$lParam)
            
     EndSwitch
    
EndFunc

Share this post


Link to post
Share on other sites

Thanks, now i get it ;)


 

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0