|
Hey ppl, I have ported this code from a vb6 example, but can't seem to get it working... Any ideas
<br />
Private Class TitleBarInfo<br />
<System.Runtime.InteropServices.DllImport("user32")> Shared Function GetTitleBarInfo(ByVal hwnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean<br />
End Function<br />
<br />
<br />
Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000<br />
Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S<br />
Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000<br />
Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S<br />
Private Const STATE_SYSTEM_PRESSED As Short = &H8S<br />
Private Const CCHILDREN_TITLEBAR As Short = 5<br />
Public Structure RECT<br />
Public left As Integer<br />
Public top As Integer<br />
Public right As Integer<br />
Public bottom As Integer<br />
End Structure<br />
Public Structure TITLEBARINFO<br />
Public cbSize As Integer<br />
Public rcTitleBar As RECT<br />
<VBFixedArray(CCHILDREN_TITLEBAR)> Public rgstate() As Integer<br />
Public Sub Initialize()<br />
ReDim rgstate(CCHILDREN_TITLEBAR)<br />
End Sub<br />
End Structure<br />
Public Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO<br />
Dim TitleInfo As TITLEBARINFO<br />
'Initialize structure<br />
TitleInfo.Initialize()<br />
TitleInfo.cbSize = Len(TitleInfo)<br />
<br />
GetTitleBarInfo(Handle, TitleInfo)<br />
return TitleInfo<br />
Return TitleInfo<br />
End Function<br />
End Class<br />
|
|
|
|
|
Private Structure TITLEBARINFO
Dim cbSize As Integer
Dim rcTitleBar As RECT
<VBFixedArray(CCHILDREN_TITLEBAR + 1)> _
Dim rgstate() As Integer
Public Sub Initialize()
ReDim rgstate(CCHILDREN_TITLEBAR + 1)
End Sub
End Structure
and
GetTitleBarInfo(Me.Handle.ToInt32, TitleInfo)
hope this helps
|
|
|
|
|
Sorry AndrewVos,
I sent that last message to fast, I checked it again and I was still getting a error 87, sorry.
add this import:
Imports System.Runtime.InteropServices
and the structure should be more like this:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure TITLEBARINFO
Dim cbSize As Long
Dim rcTitleBar As RECT
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=CCHILDREN_TITLEBAR)> _
Dim rgstate() As Long
Public Sub Initialize()
ReDim rgstate(CCHILDREN_TITLEBAR)
End Sub
End Structure
It should return err code 0 now.
hope that helps
|
|
|
|
|
Still not working... The elements of rgstate() are all = 0.
Consider this code....
<br />
Private Class TitleBarInfo<br />
<System.Runtime.InteropServices.DllImport("user32")> Private Shared Function GetTitleBarInfo(ByVal hWnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean<br />
End Function<br />
<br />
Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000<br />
Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S<br />
Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000<br />
Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S<br />
Private Const STATE_SYSTEM_PRESSED As Short = &H8S<br />
Private Const CCHILDREN_TITLEBAR As Short = 5<br />
Public Structure RECT<br />
Public left As Integer<br />
Public top As Integer<br />
Public right As Integer<br />
Public bottom As Integer<br />
End Structure<br />
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Private Structure TITLEBARINFO<br />
Dim cbSize As Integer<br />
Dim rcTitleBar As RECT<br />
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=CCHILDREN_TITLEBAR + 1)> Dim rgstate() As Integer<br />
Public Sub Initialize()<br />
ReDim rgstate(CCHILDREN_TITLEBAR + 1)<br />
End Sub<br />
End Structure<br />
<br />
Private Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO<br />
Dim TitleInfo As TITLEBARINFO<br />
'Initialize structure<br />
<br />
TitleInfo.Initialize()<br />
TitleInfo.cbSize = Len(TitleInfo)<br />
<br />
' GetTitleBarInfo(Handle, TitleInfo)<br />
GetTitleBarInfo(Handle, TitleInfo)<br />
'Show some of that information<br />
Return TitleInfo<br />
End Function<br />
<br />
<br />
Public Shared ReadOnly Property CaptionButtonCount(ByVal Handle As IntPtr) As Integer<br />
Get<br />
Dim count As Integer<br />
<br />
Dim tbi As TITLEBARINFO<br />
tbi = GetTitleBarInfo(Handle)<br />
<br />
'Index TitleBar Element<br />
'0 The title bar itself. <br />
'1 Reserved. <br />
'2 Minimize button. <br />
'3 Maximize button. <br />
'4 Help button. <br />
'5 Close button. <br />
Dim x As Integer<br />
For x = 2 To 5<br />
If Not (tbi.rgstate(x) = STATE_SYSTEM_INVISIBLE) And Not tbi.rgstate(x) = 0 Then<br />
count += 1<br />
End If<br />
Next x<br />
Return count<br />
End Get<br />
End Property<br />
<br />
End Class<br />
<br />
|
|
|
|
|
MSDN on the GetTitleBarInfo function.....
"If the function succeeds, the return value is nonzero."
|
|
|
|
|
Yeah, I been tweaking the code for a while now with no luck, anyone with a good understanding of interop, please comment, thanks.
|
|
|
|
|
AndrewVos,
Sorry, I was woring on it between other code so it didn't get my full attention or time, I think this solution should work now that I've had time to see what was going on. It works on my end.
'----------------------------------------
Imports System.Runtime.InteropServices
'----------------------------------------
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Structure Rect
Public rLeft, rTop, rRight, rBottom As Int32
Public Function ToRectangle() As Rectangle
Return Rectangle.FromLTRB(rLeft, rTop, rRight, rBottom)
End Function
Public Overrides Function ToString() As String
Return "Rect: " & ToRectangle.ToString
End Function
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Structure TitleBarButtonStates
Public TitleBarState As TBBStates
Public Reserved As TBBStates
Public MinState As TBBStates
Public MaxState As TBBStates
Public HelpState As TBBStates
Public CloseState As TBBStates
End Structure
Enum TBBStates
STATE_SYSTEM_UNAVAILABLE = &H1
STATE_SYSTEM_PRESSED = &H8
STATE_SYSTEM_INVISIBLE = &H8000
STATE_SYSTEM_OFFSCREEN = &H10000
STATE_SYSTEM_FOCUSABLE = &H100000
End Enum
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure TITLEBARINFO
Dim cbSize As Int32
Dim rcTitleBar As Rect
Dim rgstate As TitleBarButtonStates
End Structure
Private Declare Function GetTitleBarInfo Lib "user32.dll" ( _
ByVal hwnd As Int32, ByRef pti As TITLEBARINFO) As Long
Public Shared Function GetTitleBarInfo(ByVal Handle As Int32) As TITLEBARINFO
Dim TitleInfo As TitleBarInfo
'Initialize structure
TitleInfo.cbSize = Len(TitleInfo)
GetTitleBarInfo(Handle, TitleInfo)
' *debug* the information we got back
With TitleInfo.rcTitleBar
System.Diagnostics.Debug.WriteLine(" (" & CStr(.rLeft) & "," & CStr(.rTop) & ")-(" & CStr(.rRight) & "," & CStr(.rBottom) & ")")
End With
With TitleInfo.rgstate
System.Diagnostics.Debug.WriteLine(.TitleBarState)
End With
'return with the TitleInfo
Return TitleInfo
End Function
'----------------------------------------------------------
My last test Return was:
Last DLL Error
(51,33)-(318,59)
STATE_SYSTEM_FOCUSABLE
whew.. Hope this helps...
|
|
|
|
|
Shweeet. Dunno how u got this working properly, well I havent reviewed it yet properly, but everything seems right.
Thanks alot Anonymous!
I actually resorted to GetWindowLong to check if the caption buttons r there.
Well done, ur a genius :>
|
|
|
|
|
Wasnt logged in there... Thanks so much for your work, Anonymous, and the last post was mine. Cheers mate
|
|
|
|
|
AndrewVos,
Thanks, it was interesting, and no problem, I don't log in a lot of times either.
progload
|
|
|
|
|
i have an application that I wrote about a year ago. Within this application I allow certain users to change the DB access for all users of the application on a given PC.
SaveSetting("DMaTS", "SQL_Server", "ServerName", gstrServer)
**where gstrServer is the name of the server)
This has worked without issue until recently when I have opened this code up and have added new functionality. Now the SaveSettings only works for the user that applied the DB Change. Is this change if bahavior something to do with some security patching?
If I do a registry check for the entry is lists under "Current User..."?
I am a bit puzzled by this change in behavior and am looking for an explanation of why, as well as any corrective action I should take to correct my code and coding habits.
Thanks in Advance.
mtognetti.
|
|
|
|
|
SaveSetting has always saved to HKEY_CURRENT_USER . I don't know what's changed, but this functionality wasn't it. Anything saved under CurrentUser is visible only to the user that saved it, not to anyone else.
If you need to save application settings that apply to all users of your application, then they should have gone under HKEY_LOCAL_MACHINE .
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As I have done some further reading since posting this I have come to the same conclusion that you have.
Thank you for the validation. I will now redefine this to actually change/add the setting to HK_Local_Machine. This way I will actually get the functionality that I am expecting...all of the time.
Thanks again.
Mtognetti
|
|
|
|
|
Hi everyone,
I have found tons and tons of code on how to add users to the active directory, but I have not found much on how to set folder permission for these users. I have an FTP site that I use a batch to create 50 username and password combinations and then I add those to the active directory (currently by hand; working on code for autonomous). I then have to set all the user permissions to the folder that is reserved for each user. Everywhere I look there is very little discussion on how to do this automatically. Any help is VERY appreciated. Thanks!
Mike
Gaming at the GuildofBlades.com is the only way to really experiece the level 99 Soul-Sucking Sword!
|
|
|
|
|
Here is a sample code I would like to be able to cut in half. The Dim is the only difference. I want to connect to a different db - through web services - based on a command button clicked in Excel. I currently have the button set a property (thanks Dave) in the form but this is a bunch of repeated code (and this is one of the short segments). I would put just the Dim in the If statement but since I can't use it outside of the if the rest of the code has no definition.
Private Sub frmCJ_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsOrg As DataSet
If m_ConnectionString = "prod" Then
Dim wsrv As New seoweb.Service1
dsOrg = wsrv.CJGetOrganization
Dim DV As DataView = dsOrg.Tables(0).DefaultView
With cbOrganization
.DataSource = DV
.DisplayMember = "organization"
.ValueMember = "organization"
End With
Else
Dim wsrv As New seodev.Service1
dsOrg = wsrv.CJGetOrganization
Dim DV As DataView = dsOrg.Tables(0).DefaultView
With cbOrganization
.DataSource = DV
.DisplayMember = "organization"
.ValueMember = "organization"
End With
End If
End Sub
|
|
|
|
|
Private Sub frmCJ_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim dsOrg As DataSet<br />
<br />
If m_ConnectionString = "prod" Then<br />
Dim wsrv As New seoweb.Service1<br />
dsOrg = wsrv.CJGetOrganization<br />
Else<br />
Dim wsrv As New seodev.Service1<br />
dsOrg = wsrv.CJGetOrganization<br />
End If<br />
<br />
'common stuff<br />
Dim DV As DataView = dsOrg.Tables(0).DefaultView<br />
With cbOrganization<br />
.DataSource = DV<br />
.DisplayMember = "organization"<br />
.ValueMember = "organization"<br />
End With<br />
End Sub
This is what I got out of your code. Simplifies it slighty
|
|
|
|
|
Does anybody know if it is possible to clear the ErrorProvider on ALL controls with one simple function?
ErrorProvider1.SetError([ALL Controls], "")
Thanks
Brad
|
|
|
|
|
No, but you could create your own,
This is what I use:
'--- hErrorProvider.vb -------
Public Class hErrorProvider
Inherits System.Windows.Forms.ErrorProvider
#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<system.diagnostics.debuggerstepthrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
#End Region
Private _errorList As New ArrayList
Private _activeControl As Control
Public Shadows Sub SetError(ByVal control As Control, ByVal value As String)
If value = "" Then
If _errorList.Contains(control) Then
_errorList.Remove(control)
End If
Else
If Not _errorList.Contains(_errorList) Then
_errorList.Add(control)
End If
End If
MyBase.SetError(control, value)
End Sub
Public Shadows Sub SetError(ByVal value As String)
If _activeControl Is Nothing Then
Throw New Exception("Active control has not been set.")
End If
Call Me.SetError(_activeControl, value)
End Sub
Public Sub ClearError(ByVal control As Control)
If _errorList.Contains(control) Then
_errorList.Remove(control)
End If
MyBase.SetError(control, "")
End Sub
Public Sub ClearError()
If _activeControl Is Nothing Then
Throw New Exception("Active control has not been set.")
End If
Call Me.ClearError(_activeControl)
End Sub
Public Sub ClearAll()
For Each control As Control In _errorList
MyBase.SetError(control, "")
Next
_errorList.Clear()
End Sub
Public Function HasErrors() As Boolean
Return _errorList.Count > 0
End Function
End Class
|
|
|
|
|
Hi folks,
I have a kind of listview, with a couple of 1000 items.
Each item displays a bitmap of around 100x100 pixels.
Because it takes very long to make the bitmap, each item caches the bitmap instead of redrawing it over again.
But, because there are so many items, memory goes berserk (+200000 private bytes)
Each bitmap has a pixelformat of 32bppPArgb.
Because i want to keep the memory within bounds, i would like to change this to Format16bppArgb1555 or something.
But then i can't create a Graphics object from the bitmap (OutOfMemoryException).
Does anyone here have any ideas?
Thanks in andvance!
|
|
|
|
|
... but you guys probably already thought of that
|
|
|
|
|
I want to send data to one of control of parent form from child form at run time . how can I ?
|
|
|
|
|
|
I am calling a stored procedure in my vbscript and I need to be able to grab the results from the stored procedure execution. Right now I have tried several accessors, but nothing seems to be working. Also other methods I have seen done actually return fields from a table, the sql procedure I am executing is printing strings.
Does anyone know how to do this? Or any other thoughts how I could integrate this into my script?
TIA
VB CODE
-----
Dim dbnames_connection_jobs
Dim dbnames_command_jobs
Dim dbnames_recordset_jobs
Set dbnames_connection_jobs = CreateObject("ADODB.Connection")
Set dbnames_command_jobs = CreateObject("ADODB.Command")
Set dbnames_recordset_jobs = CreateObject("ADODB.Recordset")
dbnames_connection_jobs.ConnectionString = "Provider='sqloledb';Data Source='" & database_name & "';" & _
"Initial Catalog='master';Integrated Security='SSPI';"
dbnames_connection_jobs.open
dbnames_command_jobs.ActiveConnection = dbnames_connection_jobs
dbnames_command_jobs.CommandTimeout = 15
dbnames_command_jobs.CommandText = "exec sp_help_revlogin"
Set dbnames_recordset_jobs = dbnames_command_jobs.Execute
----
Stored Procedure
----
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @xstatus int
DECLARE @binpwd varbinary (256)
DECLARE @txtpwd sysname
DECLARE @tmpstr varchar (256)
DECLARE @SID_varbinary varbinary(85)
DECLARE @SID_string varchar(256)
IF (@login_name IS NULL)
DECLARE login_curs CURSOR FOR
SELECT sid, name, xstatus, password FROM master..sysxlogins
WHERE srvid IS NULL AND name <> 'sa'
ELSE
DECLARE login_curs CURSOR FOR
SELECT sid, name, xstatus, password FROM master..sysxlogins
WHERE srvid IS NULL AND name = @login_name
OPEN login_curs
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
IF (@@fetch_status = -1)
BEGIN
PRINT 'No login(s) found.'
CLOSE login_curs
DEALLOCATE login_curs
RETURN -1
END
SET @tmpstr = '/* sp_help_revlogin script '
PRINT @tmpstr
SET @tmpstr = '** Generated '
+ CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
PRINT 'DECLARE @pwd sysname'
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT ''
SET @tmpstr = '-- Login: ' + @name
PRINT @tmpstr
IF (@xstatus & 4) = 4
BEGIN -- NT authenticated account/group
IF (@xstatus & 1) = 1
BEGIN -- NT login is denied access
SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
PRINT @tmpstr
END
ELSE BEGIN -- NT login has access
SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''
PRINT @tmpstr
END
END
ELSE BEGIN -- SQL Server authentication
IF (@binpwd IS NOT NULL)
BEGIN -- Non-null password
EXEC sp_hexadecimal @binpwd, @txtpwd OUT
IF (@xstatus & 2048) = 2048
SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'
ELSE
SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'
PRINT @tmpstr
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
+ ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '
END
ELSE BEGIN
-- Null password
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
+ ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '
END
IF (@xstatus & 2048) = 2048
-- login upgraded from 6.5
SET @tmpstr = @tmpstr + '''skip_encryption_old'''
ELSE
SET @tmpstr = @tmpstr + '''skip_encryption'''
PRINT @tmpstr
END
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO
---
|
|
|
|
|
You'd probably have to setup a Parameter object, in your Command object, with a direction parameter of adParamReturnValue . You could probably read the results from that parameter after the Execute method returns.
Or you might be looking for something like this[^] example.
I don't know for sure which one will work for you. I never had to look at the return value text before...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Made some small changes to the variable names, but tried what was posted in:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdconcommandparams.asp
and here
http://www.microsoft.com/resources/documentation/Windows/2000/server/reskit/en-us/iisbook/c07_returning_values_from_stored_procedures.asp
Now getting error' Item cannot be found in the collection corresponding to the requested name or ordinal.
800A0CC1
This means that the Recordset var isn't getting any data returned to it, but the stored proc when run in query analyzer is returning data?
What do I have blatantly incorrect in the code below?
--
Dim userinformation_connection_jobs
Dim userinformation_command_jobs
Dim userinformation_recordset_jobs
Set userinformation_connection_jobs = CreateObject("ADODB.Connection")
Set userinformation_command_jobs = CreateObject("ADODB.Command")
Set userinformation_recordset_jobs = CreateObject("ADODB.Recordset")
userinformation_connection_jobs.ConnectionString = "Provider='sqloledb';Data Source='" & database_name & "';" & _
"Initial Catalog='master';Integrated Security='SSPI';"
userinformation_connection_jobs.open
userinformation_command_jobs.ActiveConnection = userinformation_connection_jobs
userinformation_command_jobs.CommandTimeout = 15
userinformation_command_jobs.CommandText = "exec sp_help_revlogin"
'userinformation_command_jobs.CommandType = adCmdStoredProc
Set userinformation_recordset_jobs = userinformation_command_jobs.Execute
userinformation_recordset_jobs(0).Direction = adParamReturnValue
'userinformation_command_jobs.Execute
output_file.WriteLine(userinformation_recordset_jobs(0))
|
|
|
|
|