Results 1 to 17 of 17

Thread: 2 problems: GetObjectAPI and GetCurrentObject

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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:
    1. Debug.Print "HDC " & GetDCEx(GetForegroundWindow, 0, DCX_WINDOW)
    2.     Debug.Print "HDC " & GetDCEx(GetDesktopWindow, 0, DCX_WINDOW)
    3.    
    4.     Debug.Print "OBJ " & GetCurrentObject(GetDCEx(GetForegroundWindow, 0, DCX_WINDOW), OBJ_BITMAP)
    5.     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:
    1. Dim dBitmap As Long, dBMP As BITMAP, HDC As Long, ret As Long
    2.    
    3.     HDC = GetDC(GetForegroundWindow)
    4.     dBitmap = GetCurrentObject(HDC, OBJ_BITMAP)
    5.    
    6.     If dBitmap <> 0 Then
    7.         ret = GetObjectAPI(dBitmap, Len(dBMP), dBMP)
    8.         Debug.Print ret, dBMP.bmHeight, dBMP.bmWidth
    9.  
    10. ' .... 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.

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Maybe

    VB Code:
    1. Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long

    or

    VB Code:
    1. Declare Function GetFocus Lib "user32" Alias "GetFocus" () As Long

    instead.
    Please rate my post.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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:
    1. Public Const DCX_WINDOW = &H1&
    2. Public Const OBJ_BITMAP = 7
    3.  
    4. Public Declare Function GetCurrentObject Lib "gdi32" (ByVal HDC As Long, ByVal uObjectType As Long) As Long
    5. Public Declare Function GetDCEx Lib "user32" (ByVal hwnd As Long, ByVal hrgnclip As Long, ByVal fdwOptions As Long) As Long
    6. Public Declare Function GetDesktopWindow Lib "user32" () As Long
    7. Public Declare Function GetForegroundWindow Lib "user32" () As Long
    8. Public Declare Function GetActiveWindow Lib "user32" () As Long
    9. Public Declare Function GetFocus Lib "user32" () As Long

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I'm getting different results.

    VB Code:
    1. Private Const DCX_WINDOW As Long = &H1&
    2. Private Const OBJ_BITMAP As Long = 7
    3.  
    4. Private Declare Function GetCurrentObject Lib "gdi32" ( _
    5.      ByVal hdc As Long, _
    6.      ByVal uObjectType As Long) As Long
    7.  
    8. Private Declare Function GetDCEx Lib "user32" ( _
    9.      ByVal hwnd As Long, _
    10.      ByVal hrgnclip As Long, _
    11.      ByVal fdwOptions As Long) As Long
    12.  
    13. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    14.  
    15. Private Declare Function GetForegroundWindow Lib "user32" () As Long
    16.  
    17. Private Declare Function GetActiveWindow Lib "user32" () As Long
    18.  
    19. Private Declare Function GetFocus Lib "user32" () As Long
    20.  
    21. Option Explicit
    22.  
    23. Private Sub Form_Load()
    24.  
    25.     Debug.Print "GetForegroundWindow HDC " & GetDCEx(GetForegroundWindow, 0, DCX_WINDOW)
    26.     Debug.Print "GetDesktopWindow HDC " & GetDCEx(GetDesktopWindow, 0, DCX_WINDOW)
    27.     Debug.Print "GetActiveWindow HDC " & GetDCEx(GetDesktopWindow, 0, DCX_WINDOW)
    28.     Debug.Print
    29.     Debug.Print "GetForegroundWindow OBJ " & GetCurrentObject(GetDCEx(GetForegroundWindow, 0, DCX_WINDOW), OBJ_BITMAP)
    30.     Debug.Print "GetDesktopWindow OBJ " & GetCurrentObject(GetDCEx(GetDesktopWindow, 0, DCX_WINDOW), OBJ_BITMAP)
    31.     Debug.Print "GetActiveWindow OBJ " & GetCurrentObject(GetDCEx(GetActiveWindow, 0, DCX_WINDOW), OBJ_BITMAP)
    32.  
    33.     Unload Me
    34.    
    35. 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.
    Please rate my post.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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...

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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

  8. #8
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    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...
    Please rate my post.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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 ?

  10. #10
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    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
    Please rate my post.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    "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:
    1. Public Type BITMAP '24 bytes
    2.     bmType As Long
    3.     bmWidth As Long
    4.     bmHeight As Long
    5.     bmWidthBytes As Long
    6.     bmPlanes As Integer
    7.     bmBitsPixel As Integer
    8.     bmBits As Long
    9. 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 !!

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Anyone ?

  13. #13
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    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.
    Please rate my post.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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)

  15. #15
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    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...
    Please rate my post.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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 ?

  17. #17
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    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...
    Please rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width