AutoHotkey Community

It is currently May 26th, 2012, 4:58 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: March 12th, 2007, 12:42 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
dara asked help to make IP Address controls with value validation.
Instead of improving this code based on Edit controls, I though it would be nicer to use the standard Windows control for IP Addresses, letting it make the hard work.

So I took the code I made for AVI control embedding, and I reworked it to fit the SysIPAddress32 control.

I updated the script to allow setting an initial value and to better encapsulate the functions, thanks to majknetor's advices/pushing... :-P
I prefer to give a link to the file, it makes it easier to update (and to get): Control_IPAddress.ahk
[EDIT] Changed name from CreateWindow_IPA to Control_IPAddress, less cryptic...

Quote:
// File/Project history:
1.03.000 -- 2007/05/25 (PL) -- Added IPM_CLEARADDRESS on request of aCkRiTe.
1.02.000 -- 2007/05/23 (PL) -- Added IPM_SETADDRESS and improved encapsulation.
1.01.000 -- 2007/05/16 (PL) -- Changed API for consistency with CreateWindow_AniGif.
1.00.000 -- 2007/03/12 (PL) -- Creation.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Last edited by PhiLho on May 28th, 2007, 11:00 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 1:56 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
This doesn't work here

Code:
Gui, +lastfound
h := WInExist()

GuiAddIPAddress(h, 0, 0, 100, 100)
Gui,  Show, w200 h200


The function is returning valid handle.


EDIT: When I move constants above this, it works. There should be a note that you must include this in your autorun section rather then at the end. Its better to harcode constants anyway, or to put them in appropriate functions as statics

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 5:31 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Nice. Is there any way to change the font and have a part for port numbers and allow letters for hostnames?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 5:53 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Changing the font can be done like for any other Windows control.
This control is useful but rather limited to the most common format, 4 decimal fields. It doesn't handle other formats nor IPv6... So to allow host names, you have to manage a separate Edit control, I suppose.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 18th, 2009, 4:45 pm 
Hi,

I realise that this thread is coming up for its 2nd birthday but I was hoping to make use of this block of code in a little Gui that I have been writing.

But what I need to know is, is it possible to use your control in a Gui with tabs? Or is it only possible to hide / show it when the appropriate tab is selected in order to emulate correct operation?

I can only get it to display over the whole window with it staying there regardless of the tab you select.

Thanks in advance,
Mike


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 5:02 pm 
Offline

Joined: March 7th, 2006, 6:34 pm
Posts: 7
Hi again,

I forgot to log in!

Any help with getting this control to work correctly with tabs would be greatly appreciated.

Regards,
Mike


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 4:25 am 
Offline

Joined: June 26th, 2008, 3:58 am
Posts: 56
Hi Mikie, this should give you an idea of how to do it.
(I've modified the function to make the control easier to position, but PhiLho's will work too)
Code:
#SingleInstance force

Gui, +LastFound
Gui, Add, Tab2, w170 h90 gTabChange AltSubmit vctab, tab 1|tab 2
hIPA := IPAddress_CreateControl(WinExist(), "w150 h20")
Gui Add, Text, , o hai thar, I am a text control
Gui Show, , %A_Space%
return

GuiClose:
   ExitApp

TabChange:
   Gui, Submit, NoHide
   IPAddress_Show(hIPA, ctab = 1)
   return
IPAddress_Show(hwnd, show) {
   Control, % show ? "Show" : "Hide", , , ahk_id %hwnd%
   }

IPAddress_CreateControl(guiHwnd, options) {
   static ctext

   Gui, Add, Text, hidden vctext %options%
   GuiControlGet, _, Pos, ctext
   GuiControl, -v, ctext

   ipaHwnd := DLLCall("CreateWindowEx"
         , "UInt", 0               ; Style, can be WS_EX_CLIENTEDGE = 0x200
         , "Str", "SysIPAddress32" ; Class Name
         , "UInt", 0               ; Window name
         , "UInt", 0x50010000      ; Window style:  WS_CHILD | WS_VISIBLE | WS_TABSTOP
         , "Int", _x               ; X position
         , "Int", _y               ; Y position
         , "Int", _w               ; Width
         , "Int", _h               ; Height
         , "UInt", guiHwnd         ; Handle of parent
         , "UInt", 0               ; Menu
         , "UInt", 0               ; hInstance, unneeded with User32 components
         , "UInt", 0)              ; User defined style

   return ipaHwnd
   }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 10:57 am 
Offline

Joined: March 7th, 2006, 6:34 pm
Posts: 7
Thanks tkoi, that has really helped me out. I appreciate your support.
Mike.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 7:32 am 
Offline

Joined: June 3rd, 2008, 7:34 pm
Posts: 86
Location: Italy
Thank you Philo. Could you provide the functions to Enable and Disable the fields?

_________________
All my scripts/snippets are released under the WTFPL: http://sam.zoy.org/wtfpl/COPYING


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 8:38 am 
Offline

Joined: June 3rd, 2008, 7:34 pm
Posts: 86
Location: Italy
Ahhh, i wrote that function. It's more simple than i thought:

Code:
/**
 * Enable and Disable the control. _ipaFlag must be 1 (Enable) or 0 (Disable)
 */
IPAddress_EnableDisable(_ipaHwnd, _ipaFlag)
{
   ; WM_ENABLE := 0x0A
   PostMessage 10, %_ipaFlag%, 0, , ahk_id %_ipaHwnd%
}

_________________
All my scripts/snippets are released under the WTFPL: http://sam.zoy.org/wtfpl/COPYING


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group