|
at the main form write this also
main.hide(this will hide the main form)
and when another form is loaded then
also create a command button there and write in the code window the following in click event
|
|
|
|
|
write in the main form command button
main.hide
also when second form is loaded then
create a commandbutton and write the following code
me.hide
main.show
|
|
|
|
|
Hi,
I am trying to create a SPARSE file that reflects the size of an original file. for excample, I would like to create a 33gb(Logical) file that is physically only a few bytes.
I am able to create a 0(logical/physical) byte file only with the following code but I can't seem to get the Logical value assigned. Could someone tel me what I'm missing?
Module Module1
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Integer, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Public Declare Function SetFilePointer Lib "kernel32" Alias "SetFilePointer" ( _
ByVal hFile As Integer, _
ByVal lDistanceToMove As Integer, _
ByVal lpDistanceToMoveHigh As Integer, _
ByVal dwMoveMethod As Integer) As Integer
Public Declare Function SetEndOfFile Lib "kernel32" ( _
ByVal hFile As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Integer) As Integer
Public Declare Function DeviceIoControl Lib "kernel32" ( _
ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
|ByVal lpInBuffer As String, _
ByVal nInBufferSize As Long, _
ByVal lpOutBuffer As String, _
ByVal nOutBufferSize As Long, _
ByVal lpBytesReturned As Long, _
ByVal lpOverlapped As String) As Long
End Module
Public Class Form1
Inherits System.Windows.Forms.Form
Const _WIN32_WINNT = 5
Public Const CREATE_ALWAYS = 2
Public Const CREATE_NEW = 1
Public Const OPEN_ALWAYS = 4 'Create if doesn't exist
Public Const OPEN_EXISTING = 3
Public Const TRUNCATE_EXISTING = 5
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FSCTL_SET_SPARSE = &H900C4
Public Const MOVEFILE_REPLACE_EXISTING = &H1
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_BEGIN = 0
Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim h
Dim d
Dim n
Dim dw As Integer
Dim lDist As Integer
h = CreateFile("D:\Wes.log", GENERIC_WRITE + GENERIC_READ, 0, 0, CREATE_ALWAYS, 0, 0)
dw = 0
d = DeviceIoControl(h, FSCTL_SET_SPARSE, n, 0, n, 0, dw, 0)
lDist = 8
MsgBox(h & " " & lDist)
SetFilePointer(h, 0, lDist, FILE_BEGIN)
CloseHandle(h)
End Sub
|
|
|
|
|
First, your declaration for DeviceIOControl is wrong. Your passing all variable in ByVal, but some of the parameters must be passed in ByRef. This is because DeviceIOControl is looking for the address of the variable, not it's value. The parameters that start with 'lp' are actually long pointers, which represent a 32-bit address, not a value. This is where you pass by reference.
Public Declare Function DeviceIoControl Lib "kernel32" ( _
ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
ByRef lpInBuffer As String, _
ByVal nInBufferSize As Long, _
ByRef lpOutBuffer As String, _
ByVal nOutBufferSize As Long, _
ByRef lpBytesReturned As Long, _
ByVal lpOverlapped As String) As Long
Try that and see what happens...
RageInTheMachine9532
|
|
|
|
|
I've tried it but it dies with the following error.....
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at WS_NTFS.Module1.DeviceIoControl(Int64 hDevice, Int64 dwIoControlCode, String& lpInBuffer, Int64 nInBufferSize, String& lpOutBuffer, Int64 nOutBufferSize, Int64& lpBytesReturned, String& lpOverlapped)
at WS_NTFS.Form1.Button1_Click(Object sender, EventArgs e) in D:\@Projects\WeshillNTFS\NTFS_5_PT2_Src\WS_NTFS\Form1.vb:line 127
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
|
|
|
|
|
Part of the problem is you are passing in strings for your buffers, don't. This is the example your looking for:
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Module Module1
Private Const FILE_ANY_ACCESS = 0
Private Const FILE_READ_ACCESS = 1
Private Const FILE_WRITE_ACCESS = 2
Private Const FILE_DEVICE_FILE_SYSTEM = 9
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = 1
Private Const FILE_SHARE_WRITE = 2
Private Const CREATE_NEW = 1
Private Const CREATE_ALWAYS = 2
Private Const OPEN_EXISTING = 3
Private Const OPEN_ALWAYS = 4
Private Const TRUNCATE_EXISTING = 5
Public Const FSCTL_SET_REPARSE_POINT = &H900A4
Public Const FSCTL_GET_REPARSE_POINT = &H900A8
Public Const FSCTL_DELETE_REPARSE_POINT = &H900AC
Public Const FSCTL_SET_SPARSE = &H900C4
Public Const FSCTL_SET_ZERO_DATA = &H980C8
Private Const INVALID_HANDLE_VALUE = -1
Private Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As Integer
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Integer, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" ( _
ByVal handle As Integer) As Integer
Private Declare Function DeviceIoControl Lib "kernel32" ( _
ByVal hDevice As Integer, _
ByVal dwIoControlCode As Integer, _
ByRef lpInBuffer() As Byte, _
ByVal nInBufferSize As Integer, _
ByRef lpOutBuffer() As Byte, _
ByVal nOutBufferSize As Integer, _
ByRef lpBytesReturned As Integer, _
ByVal lpOverlapped As Long) As Integer
Sub Main()
Dim path As String = "D:\MyTest.dat"
Dim hFileHandle As Integer
Dim rc As Integer
Dim iBytesReturned As Integer
Dim inBuffer(512) As Byte
Dim outBuffer(512) As Byte
hFileHandle = CreateFile(path, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0)
If hFileHandle <> INVALID_HANDLE_VALUE Then
Console.WriteLine("The {0} file has been created, handle is {1}.", path, hFileHandle)
If Not ReportSparseStatus(path) Then
' Change the status to sparse...
rc = DeviceIoControl(hFileHandle, FSCTL_SET_SPARSE, inBuffer, 0, outBuffer, 0, iBytesReturned, 0)
Console.WriteLine("DeviceIOControl returned {0}.", rc)
CloseHandle(hFileHandle)
If rc = 0 Then
rc = GetLastError()
Console.WriteLine("DeviceIOControl failed with Win32Error {0}.", rc)
Else
Console.WriteLine("DeviceIOControl call with FSCTL_SET_SPARSE returned as successful.")
If ReportSparseStatus(path) Then
Dim fs As New FileStream(path, FileMode.Open, FileAccess.ReadWrite)
fs.SetLength(33792000000) ' SetLength takes a 64-bit Integer, so GB lengths are possible.
fs.Seek(fs.Length, SeekOrigin.Begin)
fs.WriteByte(42)
fs.Close()
End If
End If
End If
Else
Console.WriteLine("Unable to create file!")
rc = GetLastError()
Console.WriteLine("CreateFile failed with Win32Error {0}.", rc)
End If
Console.Write("Done...Press <Enter> to quit.")
Console.ReadLine()
End Sub
Private Function ReportSparseStatus(ByVal path As String) As Boolean
Dim fa As FileAttributes
fa = File.GetAttributes(path)
If (fa And FileAttributes.SparseFile) = FileAttributes.SparseFile Then
Console.WriteLine("The {0} file is tagged as a sparse file.", path)
Return True
Else
Console.WriteLine("The {0} file is NOT tagged as a sparse file.", path)
Return False
End If
End Function
End Module
Hope this helps!
BTW: Why would you want to create a 33GB file with nothing in it?
RageInTheMachine9532
|
|
|
|
|
I will give this a try. The reason for this is that I want to copy the original file to tape, for example, then create an empty file of the same name, to free up space. This file will act as a reference to remind me that I do have a file by that name on tape. I know that I could create a 0 byte file but I prefer to see the original size of the file without actually having it use the disk space.
I am hoping that Sparsing would help with this.
Thanks for your help.
|
|
|
|
|
I have tried this and it works beautifully. Thanks so much.
I have another question... I notice when the file is sparsed I have access to that space, however, when I try to copy or delete the Sparsed file the OS treats it like a regular file. For example, instead of coping 8kb of data it tries to copy 33gb. Is there a way to view the logical size as 33gb but tell the OS to treat it as an 8kb file during these type of manipulations?
Thanks,
I am not sure if there is someway besig
|
|
|
|
|
im very new to vs.net windows apps. i know the console apps quite a bit now. i am also coming from vb6.
i was just wondering how to perform code when events such as mousehover occurs? or any of these basic events. any help appreciated, thanks.
------------------------
Jordan.
III
|
|
|
|
|
If you are using the VS.NET IDE then in the code view there are two dropdowns. Set the first dropdown to the object you want to set the event for and set the second dropdown to the event you want to hook into. It will generate the Subs for you, you just fill in the details.
-OR-
If you are not using the IDE then you can use addHandler to hook into the events.
ex. addhandler Panel1.Click, addressof clickResponse
(addrssof sets clickResponse as the callback sub)
the advantage to doing this is you can do somthing like
addhandler Panel1.Click, addressof clickResponse
addhandler Panel2.Click, addressof clickResponse
addhandler Panel3.Click, addressof clickResponse
and in clickResponse just do a sender.name to get the object that called the sub
-or (the easiest way) -
You can declare it like this:
Private Sub Panel1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Panel1.Click
The handles on the end specifies whats tied to this sub
you can also specify multiple events this way like so:
Private Sub Panel1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Panel1.Click, Panel2.Click, Panel3.Click
as you can see the name of the sub is not important using this method it could be anything you want like..
Private Sub eatAtJoes(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Panel1.Click, Panel2.Click, Panel3.Click
|
|
|
|
|
first of all, thank you.
and i do like that last easy method..
only one problem, i was just messing around with the events for a button. im using system.eventargs to handle the click event, and forms.mouseeventargs to handle mousemove. is there a page to go to that gives a list of all the references you must use in order to do each event? like, say i want to do an event for a button which controls the mousedown method. is there a way of determining what you need to set 'e' as?
------------------------
Jordan.
III
|
|
|
|
|
|
about the 'e' thing, i was referring to the 'ByVal e As System.EventArgs' part. i guess i shouldntve said what do you set e to, but what type, or event, or wutever its called, do you set e to. but thank you.
I will go check out the docs now, thx again for ur help.
------------------------
Jordan.
III
|
|
|
|
|
I've recently bought VB.net and I like it!
..however, I'm struggling to understand all the new concepts...like forms e.g in VB6 to load another form you would Load Form1, Form1.show...how does this work in VB.net????
|
|
|
|
|
Simply,
Declare an instance of your form and call the Show method.
Dim myForm As New Form2
myForm.Show()
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
Thanks...problem solved...
|
|
|
|
|
I'm using VB 6.0 and I was wondering if you could also skin your programs. So that you don't see just the basic VB skin, but that you can adjust this.. Just like you can do with Windows with for example WindowsBlinds...
And by skinning, I don't mean only changing colors but also textures and shapes etc.
Please help me,
<<<eRiK>>>
|
|
|
|
|
Hi...
skinning....
u have to use an image as a form. I mean an image which incorporates the graphic elements of your application. this image would sit on top of your application and you can easily change the colors etc. by just using images of diff colors. For this to happen, no part of your forms shuld be visible to the users but the image.
rIsHaBh
|
|
|
|
|
Whow, I menth skinning your program, so like in WinAmp, you can change shapes, colors and stuff.. So you start (for example WinAmp) whit a rectangle shape and then, with some skins, you can change the whole interface (different shapes, colors, features...). So that, if you make a normal VB program, it's a rectangle shape, I want to create a diiferent shape for instance...
Ok?? Now how to?? Please tell me!!
eRiK
<<<erik>>>
|
|
|
|
|
hey,
if u wanna make ur life easy just use activeskin v4.3 by softshape or better skincrafter. Both of these are activex controls and are very easy to use. Just download and install them. Or u could use VBskinner it's easier u just have to place the control over your form and voila u get a skinnable application. u can also give it an XP or Win 2003 look and feel if u wish complete with menus and buttons.
;)
|
|
|
|
|
I have been trying to install SQL Server from Windows 2000 disc so that I can be able to use VB.NET front end on SQL SERVER.The Windows XP I am running does not allow any program from earlier version of Windows to be installed. Can anyone give me an idea on how I can acquire an SQL Server that is compatible with VB.NET to sit on my computer?
to all who have given me replies before, thank you, they have always been helpful
Ben
|
|
|
|
|
bensoncd wrote:
I have been trying to install SQL Server from Windows 2000 disc
Huh?
SQL Server isn't distributed as part of Windows 2000 - it's a distinct product, so I'm confused by your statement here.
I run SQL Server 2000 Developer Edition on an XP box at work, and have used ADO.NET in VB.NET to access it without any problems.
I think Visual Studio.NET ships with MSDE (which is the SQL Server engine with some of the enterprise bits removed), which is suitable for most database development work as well. You may not have installed it though.
Ian Darling
"One of the few systems...which has had “no deaths” in the reliability requirements." - Michael Platt
|
|
|
|
|
Thank you Michael , you may have clarified a point. I had got the instruction from the Dummies addition (VB.NET Database Programming for Dummies), to use Windows 2000 disc to install SQL Server 2000. Seemed not to work. So it seems I will have to purchase SQL Server 2000 package hey. The version of Visual Studio I have is the Student version; does not ship with MSDE.
As someone who is still on the learning curve, I would also like to get an opinion on the future of an aspiring VB.NET/SQL Server programmer.
Thank you Mic
|
|
|
|
|
In tab control the are 3 tab page
when i click a button with is in tabpage 1
i have written(tabpage3.focus) the focus to go to tabpage 3 but its not going what can i do pls help
|
|
|
|
|
Are you talking about when you right click on a tab setting it to focused before you "do stuff" to the tabpage. If so I was having this problem the other day and fixed it with a little workaround.
Private Sub tabFromClick(ByVal e As System.Windows.Forms.MouseEventArgs)
Dim thisTab As Integer
For thisTab = 0 To Me.TabCount - 1
Dim tabRect As Rectangle = Me.GetTabRect(thisTab)
If tabRect.Contains(New Point(e.X, e.Y)) Then
Me.SelectedIndex = thisTab
End If
Next
End Sub
|
|
|
|
|