|
Try this API code:
-------- 8< paste on a module 8< ------------------------------------------
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Sub MakeNormal(hwnd As Long)
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
Public Sub MakeTopMost(hwnd As Long)
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
-------- 8< paste on a module 8< ------------------------------------------
now, whenever you need it, call MakeTopMost(frmMain.hWnd), and if you need to 'free' the window, not being 'Always on top' anymore, call
MakeNormal(frmMain.hWnd), that´s it!
btw, if you close the app, and you never free-ed the window, nothing happens, in case you are wondering...
Pablo.Ar
PS: I got this code from someone else, of course. Glad to have a chance to pass it along.
|
|
|
|
|
Thanks much for the info! The question I have now though is, where can I find the hwnd for the two different applications? In other words, I assume that you have to reference the handle of the application that you wish to place on top. If I don't have access to the source code, how do I find out what this handle is?
Thanks again for your help!
Walt Hucks
|
|
|
|
|
Never mind my reply to your post... I guess that you meant for that code to be used for my VB form and not necessarily the other two applications that I'm switching between.
But now I would like to know what is the proper way to terminate my VB form/application. The event prompting the closure would be another button click that returns the VB form to "Normal" (or not on top all the time), switches to another application and then closes.
Once again, I appreciate all help.
Walt Hucks
|
|
|
|
|
well, I really don´t follow you that much on what you are trying to achieve, but as much as I understood, I can suggest try coding on this section of the main form:
Form_Terminate()
or
Form_QueryUnload()
those two events are the safest ways to end an app, giving you space to code the final process of the program´s 'normal' termination.
Pablo.Ar
ps:I hope this one helped enough, but I encourage you to re-post with a more specific description of the steps in the problem solving...
|
|
|
|
|
I have a couple sprocs that I wanted to enclose in a transaction. The transaction only has to assure that if one fails they all fail, I don't need to prevent updates or anything of the like, but that is somewhat irrelevant I guess.
The problem is, is that as soon as the trans was put into place it always threw exceptions on the first sproc. I think I will just combine the sprocs together in sql, but I am curious to what I am doing wrong.
Here is the code
<br />
Public Function UpdateFieldErrors(ByRef conn As SqlConnection, ByRef dt As DataTable) As Integer<br />
<br />
'counter of the number of records updated<br />
Dim counter As Integer = 0<br />
Dim corrected_fl As String<br />
Dim trans As SqlClient.SqlTransaction<br />
<br />
'submit all the corrected values and the comments to the database<br />
For Each row As DataRow In dt.Rows<br />
'ensure that the columns that were not corrected were not submitted<br />
Try<br />
'only require a transaction that will allow all to rollback if required<br />
'since there is a lock on the image other users updating or querying<br />
'the data is of no concern<br />
trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)<br />
<br />
Dim cmd As New SqlCommand("dbo.mySproc", conn)<br />
cmd.CommandType = CommandType.StoredProcedure<br />
cmd.Parameters.Add("@err_id", row.Item("err_id"))<br />
cmd.Parameters.Add("@new_value", row.Item("new_value"))<br />
cmd.Parameters.Add("@comments", row.Item("comments"))<br />
<br />
'only set the error to corrected if there is user input in the newvalue field<br />
If row.Item("new_value") = "" Or row.Item("new_value") Is DBNull.Value Then<br />
cmd.Parameters.Add("@corrected_fl", "N")<br />
Else<br />
cmd.Parameters.Add("@corrected_fl", "Y")<br />
End If<br />
<br />
cmd.ExecuteNonQuery()<br />
<br />
'update the answer string containing all the students answers<br />
DbAnswerUpdate.UpdateAnswerString(conn, row)<br />
trans.Commit()<br />
<br />
counter += 1<br />
Catch ex As Exception<br />
trans.Rollback()<br />
MessageBox.Show("Exception occured when inserting one of the updated rows.")<br />
End Try<br />
Next<br />
<br />
dt.AcceptChanges()<br />
<br />
Return counter<br />
<br />
End Function<br />
Thanks for the help
|
|
|
|
|
You forgot to tell us what the Exceptions are and on what lines they are occuring.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
oops I will get those up in a bit, but right now some other changes have to get worked out first. thx
|
|
|
|
|
how can I code the datagrid to reload it every time when the submit button is clicked?
button1_click
???how can I code something in here to tell function results to reload every time when the submit button is clicked?????
results()
end sub
public function results()
Try
objConn.Open()
objDA.SelectCommand = New OleDbCommand
objDA.SelectCommand.Connection = objConn
objDA.SelectCommand.CommandText = "SELECT * from XXX"
objDA.SelectCommand.CommandType = CommandType.Text
objDA.SelectCommand.ExecuteNonQuery()
objDA.Fill(objDS, "XXX")
objConn.Close()
Catch ex As Exception
MessageBox.Show("fail connection")
End Try
grdResults.DataSource = objDS
grdResults.DataMember = "XXX"
end function
Lisa
|
|
|
|
|
I'm using a network stream to send data but don't how to recieve it efficently. Reading data from the stream assumes knowing data is there. How do I know when data is waiting to be read?? Is a event triggered when data is able to be recieved??
Thanks
|
|
|
|
|
The NetworkStream object doesn't fire any events. You have to poll the DataAvailable property of the NetworkStream object to see if there is something to read.
You can look at this[^] example for a demo of DataAvailable .
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
In retrieving 4000 records (sequential read-only access) from an Oracle 9i database, using Visual Basic 6 and ODBC API functions, I built my business collection object in 6 hours. I noticed that the first 400 records, program execution was fast but it slowly depreciated after that.
I created an object/class to handle retrieval of records using ODBC API.
Cursor.Build
--> rc = SQLDriverConnect(DbHandle, FormWnd, DBConnectStr$, SQL_NTS, ConnectOut, 1024, ConnectOutLen, SQL_DRIVER_COMPLETE)
--> rc = SQLSetConnectOption(DbHandle, SQL_ACCESS_MODE, SQL_MODE_DEFAULT)
--> rc = SQLSetConnectOption(DbHandle, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF)
--> rc = SQLAllocStmt(gDatabase.DbHandle, hstmt)
--> rc = SQLSetStmtOption(hstmt, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY)
--> rc = SQLSetStmtOption(hstmt, SQL_CONCURRENCY, SQL_CONCUR_READ_ONLY)
--> rc = SQLSetStmtOption(hstmt, SQL_ROWSET_SIZE, 1)
--> rc = SQLExecDirect(hstmt, Statement, Len(Statement))
Cursor.Read
--> rc = SQLGetData(hstmt, tiColNo + 1, SQL_C_CHAR, tsBuffer$, NoChars, cbtsBuffer)
--> rc = SQLFetch(gDatabase.hstmt)
Business Collection
Set aCursor = New Cursor
if aCursor.Build > 0 then
With aCursor
While .Read
Set aBusiness = New Business Class
aBusiness.Property(1) = .ReturnValue(1)
...
aBusiness.Property(50) = .ReturnValue(50)
cBusiness.Add Item:=Business
Set aBusiness = Nothing
Wend
End With
End If
Set aCursor = Nothing
But if instead of using the cursor object/class, I used the ODBC API functions directly, I built my business collection object in 6 minutes. What could have caused this difference in execution time?
|
|
|
|
|
hi all,
i now facing the problem to convert the hexadecimal to decimal. anybody knowing it? the following are the example:-
Text1.Text = Hex(Int(PrintTAZC(1)))
Text2.Text = Hex(Int(PrintTAZC(2)))
Text3.Text = Text1.Text + Text2.Text
Text4.Text =
The Text4 textbox will display the result of the convertion in decimal of the Text3.Text. Text3.Text is in hexadecimal form.
|
|
|
|
|
Your question is a little vague. Are your trying to add two numbers or is TextBox3 support to have TextBox2 appended to TextBox1, the result showing in Hex in TextBox3 and the Decimal verison in TextBox4?
The code as you posted will append, not add!, TextBox2 to TextBox1 and show the result in TextBox3. The code to convert that result to Decimal and show it in TextBox4 is easy enough:
Text1.Text = Hex(Int(PrintTAZC(1)))
Text2.Text = Hex(Int(PrintTAZC(2)))
Text3.Text = Text1.Text + Text2.Text
Text4.Text = Val( "&H" & Text3.Text )
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for ur help. I oledi try it by using ur example in my program, it are success to running. Thanks a lot...........
|
|
|
|
|
Dear Sir/Madam,
I have developed on vb app and I would like to run it as a windows service. I used srvany.exe to make it as service. when I make it as a service and try to start the service it is giving message like "windows is started your service but windows stop your service automatically if there is no use of this servic."
|
|
|
|
|
Your going to have to supply the EXACT error message. Just guessing at what it said can be very misleading.
Is your app a Windows Forms app? Does it expect to get user input? Is your service setup under the Local System account and is it set for "Allow interaction with the desktop"?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dear Dave,
I have made the Vb application in Standerd EXE project type. and make it as service by SRVANY.exe wizards.
The exact message which I am getting while I starts the service is
"The MyClient service of local computer started and stopped Some services stop automatically if they have no work to do for example, The performance log and Alert service"
The MyClient is my service name. My VB application is a Vb form app with standerd exe. and it is a form which is axpect to get two input from user as user id and password.
service setup under the Local System account and it is not set for "Allow interaction with the desktop
my application was already running in windows startup.
but when i make it as a service its not coming in startup.
Thanks
Patel Murtuza.
|
|
|
|
|
Dear Dave,
I have made the Vb application in Standerd EXE project type. and I make it as service by SRVANY.exe wizards.
The exact message which I am getting while I starts the service is
"The MyClient service of local computer started and stopped Some services stop automatically if they have no work to do for example, The performance log and Alert service"
The MyClient is my service name. My VB application is a Vb form app with standerd exe. and it is a form which is axpect to get two input from user as user id and password.
service setup under the Local System account and it is not set for "Allow interaction with the desktop
my application was already running in windows startup.
but when i make it as a service its not coming in startup.
Thanks
Patel Murtuza.
|
|
|
|
|
patelmurtuza wrote:
and it is not set for "Allow interaction with the desktop
Since your putting up a form that asks for user input when the "service" starts, you have two problems that will stop you dead in your tracks.
First, is the above quote. This should be a big clue. Without "allow interaction with desktop", you're never going to see your form since the services don't get a desktop. This is what is making your app quit immediately on startup.
Second, your app can't put up a form if there is no user logged in. Your service must be able to handle the service control managers window messages that say when a user is logging on, when the user logs off, when Windows starts and stops...
Your app can't handle these messages because it's a VB app that doesn't expose its message handler to you to override. VB.NET does do this. Once your app starts, normally, you MUST call the Win32 API function RegisterServiceControlHandlerEx with the pointer to another function, that you write, called HandlerEx . This function will receive the messages that notify you when a user if logging on and off and the normal service control messages like, stop, pause, resume. Even if you call this function, you still have the problem where your app must be running code in a loop to keep the app alive so the HandlerEx function does get killed.
SRVANY can't make ANY app a service. Especially ones that require user interaction!
Avoid the headaches with doing this and write the thing in VB.NET, which supports writing services natively. VB6 doesn't and is not a good choice for it at all.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need my application to scan my harddrive folder by folder for files of type [whatever] and write the results to a file in the app directory.
Can anyone help me with this? Thanks.
[edit]
Yeah, yeah. Someone voted this post down as noise. Whatever. I'm just asking a simple question as I'm in the process of figuring out the answer on my own. I was just kind of hoping that someone had thirty seconds to point me towards something that could help me in my search.
Not everyone is an expert. I know I'm not, and I thought this website was meant to help people who didn't necessarily know everything. Sorry for wasting the time it took you to vote this post as noise in your opinion.
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|
This sample checks the .Doc files and copy them to 1.txt file
Refer this for your problem
private ArrayList files = new ArrayList(); // ArrayList to store files
private void button1_Click(object sender, System.EventArgs e)
{
string path = @"C:\";
string ext = ".doc";
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(path);
LoopDirectory(dirInfo, ext);
// Save files
using(System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\1.txt"))
{
foreach(string file in files)
sw.WriteLine(file);
sw.Close();
}
}
// Loop files
private void LoopDirectory(System.IO.DirectoryInfo dirInfo, string extension)
{
foreach(System.IO.FileInfo file in dirInfo.GetFiles())
{
if(file.Extension.ToLower() == extension.ToLower() )
files.Add(file.FullName);
}
foreach(System.IO.DirectoryInfo dir in dirInfo.GetDirectories())
LoopDirectory(dir, extension);
}
}
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
Thanks for your help. I appreciated it a lot.
This is a VB forum though, and I was hoping to see the answer in VB code.
Let me know if you can help. Thanks.
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|
My mistake, check code in VB.NET
Dim files As New ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String
Dim ext As String
path = "C:\Documents and Settings"
ext = ".doc"
Dim dirInfo As New System.IO.DirectoryInfo(path)
LoopDirectory(dirInfo, ext)
Dim sw As New System.IO.StreamWriter("C:\1.txt")
For Each file As String In files
sw.WriteLine(file)
Next
sw.Close()
End Sub
Private Sub LoopDirectory(ByVal dirInfo As System.IO.DirectoryInfo, ByVal extension As String)
For Each file As System.IO.FileInfo In dirInfo.GetFiles()
If (file.Extension.ToLower() = extension.ToLower()) Then
files.Add(file.FullName)
End If
Next
For Each dir As System.IO.DirectoryInfo In dirInfo.GetDirectories()
LoopDirectory(dir, extension)
Next
End Sub
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
This might get you started.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' make a reference to a directory
Dim dirInfo As New IO.DirectoryInfo("c:\")
Dim dirArg As IO.FileInfo() = dirInfo.GetFiles(".whatever")
Dim dirFileInfo As IO.FileInfo
'list the names of all files in the specified directory
For Each dirFileInfo In dirArg
ListBox1.Items.Add(dirFileInfo)
Next
End Sub
|
|
|
|
|
Is this VB.net code? I only have VB 6. I'll see if I can adapt it.
Thanks for your help.
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|