|
-
Feb 3rd, 2003, 02:54 PM
#1
2 problems: GetObjectAPI and GetCurrentObject
OK, i'm posting here, since no one seems to look at my thread in the API forum...
Problem 1:
VB Code:
Debug.Print "HDC " & GetDCEx(GetForegroundWindow, 0, DCX_WINDOW)
Debug.Print "HDC " & GetDCEx(GetDesktopWindow, 0, DCX_WINDOW)
Debug.Print "OBJ " & GetCurrentObject(GetDCEx(GetForegroundWindow, 0, DCX_WINDOW), OBJ_BITMAP)
Debug.Print "OBJ " & GetCurrentObject(GetDCEx(GetDesktopWindow, 0, DCX_WINDOW), OBJ_BITMAP)
This is what the previous code returns (on my computer):
HDC 2097221708
HDC 1610680699
OBJ 17104950
OBJ 17104950
How come the GetCurrentObject API returns the same object as the GetDesktopWindow's bitmap object ??
When I get the picture of the ForegroundWindow, it is actually the DesktopWindow, how come ?
Problem 2:
VB Code:
Dim dBitmap As Long, dBMP As BITMAP, HDC As Long, ret As Long
HDC = GetDC(GetForegroundWindow)
dBitmap = GetCurrentObject(HDC, OBJ_BITMAP)
If dBitmap <> 0 Then
ret = GetObjectAPI(dBitmap, Len(dBMP), dBMP)
Debug.Print ret, dBMP.bmHeight, dBMP.bmWidth
' .... the rest of the ode...
The GetObjectAPI ALWAYS returns 0, and dBMP variables are 0 also, how come ?
Last edited by CVMichael; Feb 4th, 2003 at 12:58 PM.
-
Feb 3rd, 2003, 02:58 PM
#2
Frenzied Member
Maybe
VB Code:
Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
or
VB Code:
Declare Function GetFocus Lib "user32" Alias "GetFocus" () As Long
instead.
-
Feb 3rd, 2003, 03:06 PM
#3
same thing for both...
With GetActiveWindow API:
HDC -1509881489
HDC 1107363695
OBJ 17104950
OBJ 17104950
With GetFocus API:
HDC 872483951
HDC 1342245950
OBJ 17104950
OBJ 17104950
-
Feb 3rd, 2003, 03:13 PM
#4
When you try it on your computer, do you get the same thing ?
I just wanna know if it's something wrong on my computer, or that's how it's supposed to be.
Here are the declarations, so you don't have to look for them.
VB Code:
Public Const DCX_WINDOW = &H1&
Public Const OBJ_BITMAP = 7
Public Declare Function GetCurrentObject Lib "gdi32" (ByVal HDC As Long, ByVal uObjectType As Long) As Long
Public Declare Function GetDCEx Lib "user32" (ByVal hwnd As Long, ByVal hrgnclip As Long, ByVal fdwOptions As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function GetFocus Lib "user32" () As Long
-
Feb 3rd, 2003, 03:13 PM
#5
Frenzied Member
I'm getting different results.
VB Code:
Private Const DCX_WINDOW As Long = &H1&
Private Const OBJ_BITMAP As Long = 7
Private Declare Function GetCurrentObject Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal uObjectType As Long) As Long
Private Declare Function GetDCEx Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hrgnclip As Long, _
ByVal fdwOptions As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetFocus Lib "user32" () As Long
Option Explicit
Private Sub Form_Load()
Debug.Print "GetForegroundWindow HDC " & GetDCEx(GetForegroundWindow, 0, DCX_WINDOW)
Debug.Print "GetDesktopWindow HDC " & GetDCEx(GetDesktopWindow, 0, DCX_WINDOW)
Debug.Print "GetActiveWindow HDC " & GetDCEx(GetDesktopWindow, 0, DCX_WINDOW)
Debug.Print
Debug.Print "GetForegroundWindow OBJ " & GetCurrentObject(GetDCEx(GetForegroundWindow, 0, DCX_WINDOW), OBJ_BITMAP)
Debug.Print "GetDesktopWindow OBJ " & GetCurrentObject(GetDCEx(GetDesktopWindow, 0, DCX_WINDOW), OBJ_BITMAP)
Debug.Print "GetActiveWindow OBJ " & GetCurrentObject(GetDCEx(GetActiveWindow, 0, DCX_WINDOW), OBJ_BITMAP)
Unload Me
End Sub
GetForegroundWindow HDC 0
GetDesktopWindow HDC 318838164
GetActiveWindow HDC 234951952
GetForegroundWindow OBJ 0
GetDesktopWindow OBJ 17104950
GetActiveWindow OBJ 0
Is "GetDCEx" necessary? Maybe just a plain old "GetDC" would fix something.
-
Feb 3rd, 2003, 03:16 PM
#6
yea, because GetDC returns only the client area of the window (the part that starts under the menu, up to the bottom of the window), and GetDCEx returns the whole window, with the menu and the title bar...
-
Feb 3rd, 2003, 03:19 PM
#7
I just noticed you have 0 on some returns
Don't output while you debug, and don't put it in form_Load(), or at least put Me.Show right after the Form_Load() line...
Then you will get the proper values
-
Feb 3rd, 2003, 03:31 PM
#8
Frenzied Member
Yea OK. Put it in Click event and results are different.
GetForegroundWindow HDC -1325329018
GetDesktopWindow HDC -922675887
GetActiveWindow HDC 1929450204
GetForegroundWindow OBJ 17104950
GetDesktopWindow OBJ 17104950
GetActiveWindow OBJ 17104950
I dunno then...
-
Feb 3rd, 2003, 03:34 PM
#9
You have the same values as me: 17104950
Strange....
Also, it seems that GetCurrentObject returns the object for the GetDesktopWindow whever the HDC is a VALID hdc, that's all it cares about...
How about my second problem, do you know what's wrong there ?
-
Feb 3rd, 2003, 03:47 PM
#10
Frenzied Member
You have pretty much the same thing from API-Guide. I can't see anything wrong with it other than that dBitmap might be screwy.
Dim PicInfo As BITMAP
GetObject Picture1.Image, Len(PicInfo), PicInfo
-
Feb 3rd, 2003, 03:54 PM
#11
"dBitmap might be screwy" you mean the structure is not the right length ? (cuz that's all it needs to return actually, just a buffer of 24 bytes length)
VB Code:
Public Type BITMAP '24 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
And I can't use Picture1.Image, because in my function I only get the HDC, and from it I get the object, and even there, I have problems...
Ahhh... i'm starting to hate this API thing, that don't even do what their supposed to do !!
-
Feb 3rd, 2003, 10:30 PM
#12
-
Feb 3rd, 2003, 10:40 PM
#13
Frenzied Member
I was reading about GetObject on Dan Appleman's API book. It says "The bmBits field of the BITMAP data structure is not valid when retrieving information for a bitmap; however, the bmBitrs field within the BITMAP structure contained in a DIBSECTINO structure will be valid."
Not sure if that helps you or not.
-
Feb 3rd, 2003, 10:45 PM
#14
I knew that bmBits field is not valid, but the others should be, the bmWidth, and bmHeight
And what did you write after the however ? (i don't get that part)
-
Feb 3rd, 2003, 11:02 PM
#15
Frenzied Member
Yea, kind of confusing. Took me 3 passes to understand.
DIBSECTION
The DIBSECTION type contains a BITMAP structure member. So I guess it's like "DIBSECTION_VARIABLE.BITMAP_MEMBER.bmBits" will be valid for use on the GetObject function.
Now how to get that loaded...
-
Feb 4th, 2003, 12:55 PM
#16
The DIBSECTION does not work also, I get the same results (or no results i should say) as with BITMAP...
I don't understand why no on else than Shawn N wants to help on this thread...
Did anyone try the code I pasted earlier ? do you get the same results ?
I am curious if it's a problem with my computer, or everyone has the same output ?
-
Feb 4th, 2003, 06:37 PM
#17
Frenzied Member
Originally posted by CVMichael
I don't understand why no on else than Shawn N wants to help on this thread...
Cause I'm extremely cool.
Anyways, think you could explain exactly what it is you're trying to do? Maybe there's another way to go about it...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|