Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1819|回复: 5
打印 上一主题 下一主题

VB.NET GetWindowRect() API疑问

[复制链接]

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

跳转到指定楼层
1#
发表于 2011-2-28 03:38 PM |只看该作者 |倒序浏览
  1. Dim r As RECT
  2.         Dim b As Boolean = GetWindowRect(GetForegroundWindow(), r)
复制代码
GetForegroundWindow是 API Return Hwnd
GetWindowRect Parameter (hwnd as long,r as RECT) as boolean
出现不明exception,哪里错?




收藏收藏0

2

主题

0

好友

251

积分

支柱会员

Rank: 4Rank: 4Rank: 4Rank: 4

2#
发表于 2011-2-28 09:22 PM |只看该作者
在这里那么久了,麻烦code也给完整点,不然怎么帮你。

  1. Module Module1
  2.     Public Structure RECT
  3.         Dim Left As Integer
  4.         Dim Top As Integer
  5.         Dim Right As Integer
  6.         Dim Bottom As Integer
  7.     End Structure

  8.     Public Declare Function GetWindowRect Lib "user32" (ByVal HWND As Integer, ByRef lpRect As RECT) As Integer
  9.     Public Declare Function GetForegroundWindow Lib "user32" () As IntPtr

  10.     Sub Main()
  11.         Dim R As RECT
  12.         Dim yesno As Boolean
  13.         yesno = GetWindowRect(GetForegroundWindow(), R)
  14.         Console.WriteLine(R.Top & "and" & R.Left & "and" & R.Bottom & "and" & R.Right)
  15.         Console.WriteLine(yesno)
  16.         Console.ReadLine()
  17.     End Sub

  18. End Module
复制代码


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

3#
发表于 2011-2-28 10:01 PM |只看该作者
code给太完整麻烦人去看整个code
我这里的整个code两百多行==

等下我试看你的code


回复

使用道具 举报

2

主题

0

好友

251

积分

支柱会员

Rank: 4Rank: 4Rank: 4Rank: 4

4#
发表于 2011-2-28 10:16 PM |只看该作者
我的Console.WriteLine(myVariable)出现不明错误,谁来帮帮我?


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

5#
发表于 2011-3-1 02:39 PM |只看该作者
我只是想知道我的parameter有没有错,有时API一点点错他就出现exception
因为exception好像跟我讲parameter有错,找了很久都找不到
我刚刚弄了GUI的,

Imports System.Runtime.InteropServices

Public Class Form1
    Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, ByVal rectangle As RECT) As Boolean     'rectangle = receive handle's rectangle RECT,boolean = sucess or fail
    Structure RECT
        Dim x1 As Long
        Dim y1 As Long
        Dim x2 As Long
        Dim y2 As Long
    End Structure

    <DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
    Public Shared Function GetForegroundWindow() As IntPtr
    End Function
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim r As RECT
        Dim b As Boolean = GetWindowRect(GetForegroundWindow(), r) ’<- 这里exception
        ListBox1.Items.Add(GetForegroundWindow.ToString & " - " & r.x1 & "," & r.y1 & " | " & r.x2 & "," & r.y2 & "(" & b & ")")

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

A call to PInvoke function 'GetWindowRectangle!GetWindowRectangle.Form1::GetWindowRect' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

6#
发表于 2011-3-1 02:46 PM |只看该作者
啊有了我的api declare 错误 谢谢
不好意思给不够完整 @@


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-26 07:28 PM , Processed in 0.120245 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部