|
-
Jan 3rd, 2013, 11:35 AM
#2
Re: LoadImage issue
In my XP system, your code works as expected. I see the icon that's missing from your screenshot whether I run from the IDE or compiled. You might want to try this modification to your LoadFromResource routine.
Code:
Public Function LoadFromResource(ByRef ResName As Variant) As Boolean
'Resource file has to be added to this library project!
'pic has to be static, to not be destroyed if the routine quits
Static Pic As StdPicture
Dim lpszName As Long
'The icon will be destroyed if you load a new one or if the class is terminated
Call FreeIconMemory
If App.LogMode Then
Select Case VarType(ResName)
Case vbString: lpszName = StrPtr(ResName)
Case vbInteger: lpszName = CLng(ResName)
Case Else: Err.Raise 5& 'Invalid procedure call or argument
End Select
m_hIcon = LoadImage(App.hInstance, lpszName, IMAGE_ICON, 32&, 32&, LR_SHARED)
Else
On Error Resume Next
Set Pic = LoadResPicture(ResName, vbResIcon)
On Error GoTo 0
If Pic Is Nothing Then m_hIcon = 0& Else m_hIcon = Pic.Handle
End If
LoadFromResource = m_hIcon <> 0&
End Function
According to MSDN, the MAKEINTRESOURCE macro returns the specified value in the low-order word and zero in the high-order word. Although it returns a C/C++ string, it is technically not the same as a VB string (LPTSTR vs BSTR). However, both data types are really just pointers to the real strings. Since 32-bit pointers are of the same size as a Long data type, what MAKEINTRESOURCE(intResID) return is the same as MAKELONG(intResID, 0), which can be further simplified as just intResID. A positive Integer coerced to a Long will contain 0 in the high word.
LoadIcon is an older and simpler API than LoadImage. LoadIconMetric, on the other hand, is not available on systems earlier than Vista. LoadImage is the most versatile of the three and is the one recommended by Microsoft.
Last edited by Bonnie West; Jan 3rd, 2013 at 11:47 AM.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
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
|