我从网上下载了一个修改类名的程序
发现在IDE环境下可以正常运行,并改变了窗口类名
但生成EXE后就行了,经过调试后发再问题出现在 GetClassInfoLong 上
IDE环境中返回正常,生成EXE后就返回0了
百度上一条相关信息也没有,只得求助大家了
先谢了!就是 Module1 模块中的这句出错!
If GetClassInfoLong(App.hInstance, (.lpClassName And &HFFFF0000), wc2) Then          '此处有错误源码下载: http://www.520wife.com/chageclassname.rar

解决方案 »

  1.   

    谢谢你的关注,很奇怪的问题,IDE环境中可以,生成EXE就不行了
    Public Sub WndHookProc_BeforeCreation(lpCWStruct As tCWSTRUCT)
        With g_oWCHooker
            With lpCWStruct
                '如果不目标窗口则退出此过程
                If InStr(StrFromPtr(.lpWindowName), TARGET_WINDOW_CAPTION) = 0 Then Exit Sub
                
                '----------------- 更改窗体类名 -----------------
                
                Dim wc As WNDCLASS
                Dim wc2 As WNDCLASS2
                Dim lClassAtom  As Long
                
                If GetClassInfoLong(App.hInstance, (.lpClassName And &HFFFF0000), wc2) Then          '此处生成EXE后就始终返回0
                    If GetClassInfo(App.hInstance, MY_CLASS_NAME, wc) Then
                        Call UnRegClass
                    End If
                    
                    With wc2
                        wc.cbClsextra = .cbClsextra
                        wc.cbWndExtra2 = .cbWndExtra2
                        wc.hbrBackground = .hbrBackground
                        wc.hCursor = .hCursor
                        wc.hIcon = .hIcon
                        wc.hInstance = .hInstance
                        wc.lpfnwndproc = .lpfnwndproc
                        wc.lpszMenuName = .lpszMenuName
                        wc.style = .style
                        wc.lpszClassName = MY_CLASS_NAME
                    End With
                    
                    lClassAtom = RegisterClass(wc)
                    
                    lClassAtom = (lClassAtom And &HFFFF&)
                    
                    MsgBox "a"
                    If lClassAtom Then
                        .lpClassName = lClassAtom
                    End If
                End If
            End With
        End With
    End Sub
      

  2.   

    错了,刚才上面是我修改的,原来的是样的
    If GetClassInfoLong(App.hInstance, (.lpClassName And &HFFFF&), wc2) Then
    '此处生成EXE后就始终返回0 

      

  3.   

    Private Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" (ByVal lpString As String) As Integer
    Private Declare Function FindAtom Lib "kernel32" Alias "FindAtomA" (ByVal lpString As String) As IntegerPrivate Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
    Private Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
    Private Declare Function GetClassInfo Lib "user32" Alias "GetClassInfoA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASS) As Long
    Private Declare Function GetClassInfoLong Lib "user32" Alias "GetClassInfoA" (ByVal hInstance As Long, ByVal hAtom As Long, lpWndClass As WNDCLASS2) As LongPrivate Type WNDCLASS2
        style As Long
        lpfnwndproc As Long
        cbClsextra As Long
        cbWndExtra2 As Long
        hInstance As Long
        hIcon As Long
        hCursor As Long
        hbrBackground As Long
        lpszMenuName As Long
        lpszClassName As Long
    End Type
    Private Type WNDCLASS
        style As Long
        lpfnwndproc As Long
        cbClsextra As Long
        cbWndExtra2 As Long
        hInstance As Long
        hIcon As Long
        hCursor As Long
        hbrBackground As Long
        lpszMenuName As Long
        lpszClassName As String
    End TypePublic Type tCWSTRUCT
        dwExStyle As Long
        lpClassName As Long
        lpWindowName As Long
        dwStyle As Long
        x As Long
        y As Long
        nWidth As Long
        nHeight As Long
        hWndParent As Long
        hMenu As Long
        hInstance As Long
        lpParam As Long
    End Type
    Public Const MY_CLASS_NAME As String = "我的类名"
      

  4.   

    GetLastError返回什么???
    还有你察看下.lpClassName值是多少
      

  5.   

    你察看到.lpClassName值用内存察看工具看这个值是否正确
      

  6.   

    IDE环境中 LastDllError 返回是 0,   .lpClassName 是 49733
    生成EXE后 LastDllError 返回是 1411,.lpClassName 是 49585
      

  7.   

    类别不存在,我感觉你在转换.lpClassName值时有问题 ,问题出在这上面因为.lpClassName是有值的
      

  8.   

    问题奇就奇在IDE环境下可以,编译EXE就不行了,郁闷啦!
      

  9.   

    上来了,你的问题很简单,怪你不够仔细啊。把这句改下就ok了“            If GetClassInfoLong(App.hInstance, (.lpClassName And &HFFFF0000), wc2) Then          '此处生成EXE后就始终返回0 ”改成 “             If GetClassInfoLong(.hInstance, (.lpClassName And &HFFFF0000), wc2) Then          '此处生成EXE后就始终返回0  ”
      

  10.   

    汗搞技术的用百度不用google?
      

  11.   

    你说的对,Google大蜘蛛果然速度够快
      

  12.   

    谢谢 chenhui530 ,真的太感谢太感谢了,你真的就是我的偶像 ^_^ !