当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 应该用什么函数? ......
 ·高求助分关于98的屏蔽问题    »显示摘要«
    摘要: 有谁知道类似超级兔子安全视窗的软件哪里有免注册下的啊!!! ......


大家帮我看看这段程序,OpenProcess总是0,什么原因

Private   Declare   Function   FindWindow   Lib   "user32"   Alias   "FindWindowA"   (ByVal   lpClassName   As   String,   ByVal   lpWindowName   As   String)   As   Long  
  Private   Declare   Function   GetWindowThreadProcessId   Lib   "user32"   (ByVal   hwnd   As   Long,   lpdwProcessId   As   Long)   As   Long  
  Private   Declare   Function   OpenProcess   Lib   "kernel32"   (ByVal   dwDesiredAccess   As   Long,   ByVal   bInheritHandle   As   Long,   ByVal   dwProcessId   As   Long)   As   Long  
   
   
  Sub   Form_Load()  
          Dim   hwnd   As   Long  
          hwnd   =   FindWindow(vbNullString,   "计算器")  
          If   (hwnd   =   0)   Then  
                  MsgBox   "Window   not   found!"  
                  Exit   Sub  
          End   If  
   
          Dim   pid   As   Long  
          GetWindowThreadProcessId   hwnd,   pid  
   
          Dim   pHandle   As   Long  
          pHandle   =   OpenProcess(PROCESS_ALL_ACCESS,   False,   pid)  
          If   (pHandle   =   0)   Then  
                  MsgBox   "Couldnt   get   a   process   handle!"  
                  Exit   Sub  
          End   If  
  End   Sub  
   
  FindWindow和GetWindowThreadProcessId都能找到  
  惟独pHandle   =   OpenProcess(PROCESS_ALL_ACCESS,   False,   pid)  
  pHandle总是0  
  什么原因?

NO.1   作者: boywang

PROCESS_ALL_ACCESS没定义。

NO.2   作者: boywang

Option   Explicit  
   
  Private   Declare   Function   FindWindow   Lib   "user32"   Alias   "FindWindowA"   (ByVal   lpClassName   As   String,   ByVal   lpWindowName   As   String)   As   Long  
  Private   Declare   Function   GetWindowThreadProcessId   Lib   "user32"   (ByVal   hwnd   As   Long,   lpdwProcessId   As   Long)   As   Long  
  Private   Declare   Function   OpenProcess   Lib   "kernel32"   (ByVal   dwDesiredAccess   As   Long,   ByVal   bInheritHandle   As   Long,   ByVal   dwProcessId   As   Long)   As   Long  
  Private   Declare   Function   CloseHandle   Lib   "kernel32"   (ByVal   hObject   As   Long)   As   Long  
  Private   Const   STANDARD_RIGHTS_REQUIRED   =   &HF0000  
  Private   Const   SYNCHRONIZE   =   &H100000  
  Private   Const   PROCESS_VM_READ   =   &H10  
  Private   Const   PROCESS_QUERY_INFORMATION   =   &H400  
  Private   Const   PROCESS_ALL_ACCESS   =   STANDARD_RIGHTS_REQUIRED   Or   SYNCHRONIZE   Or   &HFFF  
   
   
  Sub   Form_Load()  
          Dim   hwnd   As   Long  
          hwnd   =   FindWindow(vbNullString,   "计算器")  
          If   (hwnd   =   0)   Then  
                  MsgBox   "Window   not   found!"  
                  Exit   Sub  
          End   If  
   
          Dim   pid   As   Long  
          GetWindowThreadProcessId   hwnd,   pid  
   
          Dim   pHandle   As   Long  
          pHandle   =   OpenProcess(PROCESS_ALL_ACCESS,   False,   pid)  
          If   (pHandle   =   0)   Then  
                  MsgBox   "Couldnt   get   a   process   handle!"  
                  Exit   Sub  
          Else  
                  MsgBox   CStr(pHandle)  
          End   If  
          CloseHandle   pHandle  
           
  End   Sub  
   
 

NO.3   作者: zyl910

Private   Const   STANDARD_RIGHTS_REQUIRED   As   Long   =   &HF0000  
  Private   Const   SYNCHRONIZE   As   Long   =   &H100000  
  Private   Const   PROCESS_ALL_ACCESS   As   Long   =   (STANDARD_RIGHTS_REQUIRED   Or   SYNCHRONIZE   Or   &HFFF)  
 

NO.4   作者: lihonggen0

Option   Explicit  
   
              Private   Declare   Function   WaitForSingleObject   Lib   "kernel32"   _  
                    (ByVal   hHandle   As   Long,   _  
                    ByVal   dwMilliseconds   As   Long)   As   Long  
   
              Private   Declare   Function   FindWindow   Lib   "user32"   _  
                    Alias   "FindWindowA"   _  
                    (ByVal   lpClassName   As   String,   _  
                    ByVal   lpWindowName   As   String)   As   Long  
   
              Private   Declare   Function   PostMessage   Lib   "user32"   _  
                    Alias   "PostMessageA"   _  
                    (ByVal   hwnd   As   Long,   _  
                    ByVal   wMsg   As   Long,   _  
                    ByVal   wParam   As   Long,   _  
                    ByVal   lParam   As   Long)   As   Long  
   
              Private   Declare   Function   IsWindow   Lib   "user32"   _  
                    (ByVal   hwnd   As   Long)   As   Long  
   
              Private   Declare   Function   OpenProcess   Lib   "kernel32"   _  
                    (ByVal   dwDesiredAccess   As   Long,   _  
                    ByVal   bInheritHandle   As   Long,   _  
                    ByVal   dwProcessId   As   Long)   As   Long  
               
              Private   Declare   Function   GetWindowThreadProcessId   Lib   "user32"   _  
                    (ByVal   hwnd   As   Long,   _  
                    lpdwProcessId   As   Long)   As   Long  
   
              Constants   that   are   used   by   the   API  
              Const   WM_CLOSE   =   &H10  
              Const   INFINITE   =   &HFFFFFFFF  
              Const   SYNCHRONIZE   =   &H100000  
   
              Private   Sub   Form_Load()  
                    Command1.Caption   =   "Start   the   Calculator"  
                    Command2.Caption   =   "Close   the   Calculator"  
              End   Sub  
   
              Private   Sub   Command1_Click()  
                    Shell   "calc.exe",   vbNormalNoFocus  
              End   Sub  
   
              Private   Sub   Command2_Click()  
                    Dim   hWindow   As   Long  
                    Dim   hThread   As   Long  
                    Dim   hProcess   As   Long  
                    Dim   lProcessId   As   Long  
                    Dim   lngResult   As   Long  
                    Dim   lngReturnValue   As   Long  
   
                    hWindow   =   FindWindow(vbNullString,   "Calculator")  
                    hThread   =   GetWindowThreadProcessId(hWindow,   lProcessId)  
                    hProcess   =   OpenProcess(SYNCHRONIZE,   0&,   lProcessId)  
                    lngReturnValue   =   PostMessage(hWindow,   WM_CLOSE,   0&,   0&)  
                    lngResult   =   WaitForSingleObject(hProcess,   INFINITE)  
                    DoEvents  
                    hWindow   =   FindWindow(vbNullString,   "计算器")  
                    If   IsWindow(hWindow)   =   1   Then  
                          MsgBox   "Handle   still   exists."  
                    Else  
                          MsgBox   "All   Program   Instances   Closed."  
                    End   If  
              End   Sub


    摘要: 例: 123456789 格式化为 123,456,789 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE