LoadMenu:HMENU LoadMenu(
HINSTANCE hInstance, // handle to module
LPCTSTR lpMenuName // menu name or resource identifier
);
其中参数 lpMenuName是用MAKEINTRESOURCE产生的,而
#define MAKEINTRESOURCEA(i) (LPSTR)((DWORD)((WORD)(i)))
#define MAKEINTRESOURCEW(i) (LPWSTR)((DWORD)((WORD)(i)))
#ifdef UNICODE
#define MAKEINTRESOURCE MAKEINTRESOURCEW
#else
#define MAKEINTRESOURCE MAKEINTRESOURCEA
#endif // !UNICODE
vc中就是这么做的,那么在vb中呢,关键是要翻译宏MAKEINTRESOURCE,一些api的声明工具会这样声明LoadMenu
Private Declare Function LoadMenu Lib "user32.dll" Alias "LoadMenuA" (ByVal hInstance As Long, ByVal lpString As String) As Long
最后一个参数是string,然后,由宏MAKEINTRESOURCE的写法可知,这个宏虽然是将WORD转为了LPSTR(LPWSTR),但实质数据并没有变,所以在vb中,第二个参数用Long其实是一样的,所以应该这样改,
Private Declare Function LoadMenu Lib "user32.dll" Alias "LoadMenuA" (ByVal hInstance As Long, ByVal lpString As Long) As Long
一切问题解决,(可能还有些问题吧,不然不会有宏MAKEINTRESOURCE)
vb例子:
Option Explicit
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function LoadMenu Lib "user32.dll" Alias "LoadMenuA" (ByVal hInstance As Long, ByVal lpString As Long) As Long
Private Declare Function SetMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal hMenu As Long) As Long
Private Sub Command1_Click()
Dim tMenu&
tMenu = LoadMenuVB2(24641, "SHDOCLC.DLL")
SetMenu Me.hwnd, tMenu
End Sub
Public Function LoadMenuVB2(id&, slib$) As Long
Dim hinstSHDOCLC&
Dim hMenu&
hinstSHDOCLC = LoadLibrary(slib)
LoadMenuVB2 = LoadMenu(hinstSHDOCLC, ByVal id)
End Function
(好像还要FreeLibrary,呵呵)