Click here to Skip to main content
15,917,481 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: XML to SGML Conversion Pin
Ri Qen-Sin29-Jan-08 11:43
Ri Qen-Sin29-Jan-08 11:43 
GeneralLooping Enumerators with a For Each Pin
imonfiredammit29-Jan-08 7:01
imonfiredammit29-Jan-08 7:01 
GeneralRe: Looping Enumerators with a For Each Pin
Guffa29-Jan-08 7:53
Guffa29-Jan-08 7:53 
GeneralRe: Looping Enumerators with a For Each Pin
imonfiredammit29-Jan-08 8:21
imonfiredammit29-Jan-08 8:21 
GeneralRe: Looping Enumerators with a For Each Pin
Guffa29-Jan-08 9:51
Guffa29-Jan-08 9:51 
Generaldataview.rowfilter Pin
Smithers-Jones29-Jan-08 5:58
Smithers-Jones29-Jan-08 5:58 
QuestionAsync socket receive buffer problem? Pin
Benny_Lava29-Jan-08 3:31
Benny_Lava29-Jan-08 3:31 
QuestionHandling multiple mainWindowHandles of one Process Pin
wieczo.yo29-Jan-08 3:21
wieczo.yo29-Jan-08 3:21 
Hello!

I am developing an application to display different documents(txt, doc, xls, ppt, pdf files), arrange them on the desktop and scroll through the pages.
I use System.Diagnostics.Process.Start to open the relevant file with the right application. I use then Process.mainWindowHandle to resize, to move and scroll those apps with WinAPI methods.
It works good for documents for which every Process.Start call results in an independent process, e.g. I can open two txt-files in Windows' Notepad and I get two processes displayed in the task manager. I can get the mainWindowHandle of both easily and rearrange them.
But it crashes on mutex apps(right word?). The Microsoft Word Viewer is such a candidate. I open one document foo.doc, the Word Viewer starts a process. Then I start another "instance" of it with a different file bar.doc and it opens the file, but I don't get the right Process object returned, because the first instance(with foo.doc) adds bar.doc to its managed windows.

My code:
Public Overridable Function Start(ByVal x As Double, ByVal y As Double, _
    ByVal width As Double, ByVal height As Double) As Boolean
    
    Dim retValue As Boolean = False
    Dim fred As ProcessThread
    Dim waited As Boolean

    _x = x
    _y = y
    _width = width
    _height = height

    'Starts the application with the file, ...
    _process = Process.Start(_app_path, """" & _file.Path & """")
    If Not IsNothing(_process) Then
        '...but it crashes as soon as I try to access a member of _process
        waited = _process.WaitForInputIdle()

        If Not IsNothing(_process.Threads) Then
            fred = _process.Threads.Item(0)
            retValue = EnumThreadWindows(New IntPtr(fred.Id), _
                AddressOf MoveCallback, IntPtr.Zero)
        End If
    End If

    Return retValue
End Function


EnumThreadWindows is a WinAPI call and MoveCallback is a callback for it:
Private Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, _
    ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, _
    ByVal bRepaint As Boolean) As Boolean
End Function
<dllimport("user32.dll", setlasterror:="True)"> _
Private Function EnumThreadWindows(ByVal dwThreadId As IntPtr, _
    ByVal lpfn As EnumThreadDelegate, ByVal lParam As IntPtr) As Boolean
End Function

Private Function MoveCallback(ByVal hWnd As IntPtr, _
    ByVal lParam As IntPtr) As Boolean
    Dim screenwidth As Integer = Screen.PrimaryScreen.WorkingArea.Width
    Dim screenheight As Integer = Screen.PrimaryScreen.WorkingArea.Height

    Return MoveWindow(hWnd, 0, 0, 1, screenwidth  / 2, screenheight / 2, True)
End Function
</dllimport("user32.dll",>


Do you know how to access to the last instance of a running process? Am I trying to do something stupid?
Please help me. I am experienced with VB.Net and I have done a lot of maintenance work, but I am completely new to WinAPI calls.

Regards, Thomas


I am on .Net 1.1
QuestionMass creation of keyword meta tags into HTML pages? Pin
BungleBonce29-Jan-08 2:47
BungleBonce29-Jan-08 2:47 
AnswerRe: Mass creation of keyword meta tags into HTML pages? Pin
pmarfleet29-Jan-08 9:51
pmarfleet29-Jan-08 9:51 
GeneralRe: Mass creation of keyword meta tags into HTML pages? Pin
BungleBonce29-Jan-08 22:41
BungleBonce29-Jan-08 22:41 
GeneralRe: Mass creation of keyword meta tags into HTML pages? Pin
pmarfleet30-Jan-08 10:19
pmarfleet30-Jan-08 10:19 
QuestionHow Can I Execute this query??????????????? Pin
Vanamaindia29-Jan-08 2:37
Vanamaindia29-Jan-08 2:37 
AnswerRe: How Can I Execute this query??????????????? Pin
Guffa29-Jan-08 7:09
Guffa29-Jan-08 7:09 
GeneralI want my URL to be static for eg "http://project1" Pin
VB.Net Developer29-Jan-08 2:13
VB.Net Developer29-Jan-08 2:13 
GeneralRe: I want my URL to be static for eg "http://project1" Pin
Steven J Jowett29-Jan-08 5:54
Steven J Jowett29-Jan-08 5:54 
GeneralRe: I want my URL to be static for eg "http://project1" Pin
VB.Net Developer30-Jan-08 0:06
VB.Net Developer30-Jan-08 0:06 
QuestionHow to pass value from child form to parent form Pin
ejaz_pk29-Jan-08 1:44
ejaz_pk29-Jan-08 1:44 
GeneralRe: How to pass value from child form to parent form Pin
Justin Perez29-Jan-08 2:32
Justin Perez29-Jan-08 2:32 
GeneralRe: How to pass value from child form to parent form Pin
Vanamaindia29-Jan-08 2:42
Vanamaindia29-Jan-08 2:42 
GeneralRe: How to pass value from child form to parent form Pin
BooleanTrue29-Jan-08 3:07
professionalBooleanTrue29-Jan-08 3:07 
GeneralRe: How to pass value from child form to parent form Pin
KarstenK29-Jan-08 3:11
mveKarstenK29-Jan-08 3:11 
QuestionUplaod an Excel file to ftp server from a client which is on proxy Pin
Shahid Bilal29-Jan-08 1:12
Shahid Bilal29-Jan-08 1:12 
GeneralStack Overflow Exception in Vb.Net windows Application. Pin
Balagurunathan S29-Jan-08 0:56
Balagurunathan S29-Jan-08 0:56 
GeneralRe: Stack Overflow Exception in Vb.Net windows Application. Pin
Steven J Jowett29-Jan-08 1:36
Steven J Jowett29-Jan-08 1:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.