FindWindow& ShowWindow API [英] FindWindow & ShowWindow API

查看:98
本文介绍了FindWindow& ShowWindow API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows窗体中使用API​​隐藏外部应用程序。我尝试了以下代码,但它不起作用。有人可以帮忙吗?

I am trying to hide an external application using API in windows forms. I tried the following code but it does not work. Can someone help?

谢谢。

 

   私有声明函数FindWindow Lib"user32"别名"FindWindowA"(ByVal lpClassName As String,ByVal lpWindowName As String)As Long
   私有声明功能ShowWindow Lib"user32"(ByVal hwnd As Long,ByVal nCmdShow As Long)As Long
    Const SW_HIDE As Integer = 0
    Const SW_SHOW As Integer = 5

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Const SW_HIDE As Integer = 0
    Const SW_SHOW As Integer = 5

 

    Private Sub test_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
        Dim GetHandle As Long
        Dim retVal As Long

    Private Sub test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim GetHandle As Long
        Dim retVal As Long

        GetHandle = FindWindow(vbNullString,"Untitled - Notepad")
        'retVal = ShowWindow(GetHandle,SW_SHOW)
        'AppActivate("Untitled - Notepad")

        GetHandle = FindWindow(vbNullString, "Untitled - Notepad")
        'retVal = ShowWindow(GetHandle, SW_SHOW)
        'AppActivate("Untitled - Notepad")


        retVal = ShowWindow(GetHandle,SW_HIDE)
    End Sub


        retVal = ShowWindow(GetHandle, SW_HIDE)
    End Sub

推荐答案

实际上,我们可以提供帮助。但是在这个问题上肯定没有什么信息可以提供准确的结果。有关此问题的讨论已发现

 以及
library
。 可能的问题可能是:

Actually, we could help. But there's definately to little information in this question to provide accurate results. There are discussions about this found here and in the library. Possible issues may be:


  1. 错误的窗口句柄或没有窗口句柄。代码至少应检查FindWindow的返回值,以获得有效的,可用的结果
  2. 调用ShowWindow 两次。记事本可能提供
    STARTUPINFO
    结构在运行时,这意味着您需要调用ShowWindow一次(用于清除STARTUPINFO),然后再次设置可见性标志。
  3. 声明有问题。 (虽然我没有看到任何明显的错误。)
  1. Wrong window handle or no windows handle. The code should at least check the return value of FindWindow for a valid, usable result
  2. Call ShowWindow twice. Notepad probably provides a STARTUPINFO structure when it runs, that means you need to call ShowWindow once (for clearing STARTUPINFO) and then again to set the visibility flag.
  3. Something is wrong with the declaration. (Although I don't see any obvious errors.)

希望这有助于任何人阅读此内容。 ;)

Hope this helps whoever reads this. ;)

亲切的问候,

Jonny

Kind regards,
Jonny

------

MSDN热线 http://msdn-online.de/hotline |反馈
http://www.msdn-online.de/dialog/ | Messenger
MSDN-Messenger-Hotline@hotmail.de

------
MSDN Hotline http://msdn-online.de/hotline | Feedback http://www.msdn-online.de/dialog/ | Messenger MSDN-Messenger-Hotline@hotmail.de


这篇关于FindWindow& ShowWindow API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆