vb.net - ShowWindowAsync() don't show hidden window (SW_SHOW) -


hello i'm using visual basic 2008

here part of code:

    private const sw_hide integer = 0     private const sw_show integer = 5      <dllimport("user32.dll", setlasterror:=true, charset:=charset.auto)> _      private shared function showwindowasync(byval hwnd intptr, byval ncmdshow integer) boolean         end function 

button1 code:

            try                dim p() process = process.getprocessesbyname("notepad")                dim mwh = p(0).mainwindowhandle                showwindowasync(mwh, sw_hide)             catch ex exception                msgbox("error")             end try       

button2 code:

            try                         dim p() process = process.getprocessesbyname("notepad")                dim mwh = p(0).mainwindowhandle                showwindowasync(mwh, sw_show)             catch ex exception                msgbox("error")             end try   

when click button 1 ( hide window ) works good, when want display window ( clicking button 2 ) function returns false, can tell me why? , how work, hide window , show again?

because showwindowasync() returns 0 when window hidden according msdn documentation, , 0 interpreted false. return value not indicate whether function succeeded or not.

so first time call showwindowasync(mwh, sw_hide) on visible window function returns true because showwindowasync() returns non-zero value indicating window (that now/will hidden) used visible.

then second call showwindowasync(mwh, sw_show) on hidden window returns false because showwindowasync() returns 0 value indicating window (that now/will visible) used hidden.

in other words, design , function should work intended (unless mwh window not responding messages or invalid).

but real problem here once hide window, process::mainwindowhandle property doesn't have handle anymore.

a process has main window associated if process has graphical interface. if associated process not have main window, mainwindowhandle value zero. the value 0 processes have been hidden, is, processes not visible in taskbar. can case processes appear icons in notification area, @ far right of taskbar.

what should obtain window handle via p(0).mainwindowhandle once , save returned handle somewhere, can show/hide window. of course, should make sure 0 out saved handle when window gets destroyed target process. in notepad's case, can use process::exited event.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -