| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 330 人关注过本帖
标题:VB 问题! 求教 求指导 进!
只看楼主 加入收藏
showcdk
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-5-14
结帖率:80%
收藏
已结贴  问题点数:40 回复次数:3 
VB 问题! 求教 求指导 进!
问题1:是 程序运行时 form 被鼠标按住拖动时 程序就会停留 鼠标放下 就又执行 !有办法 解决吗?
问题2:是列表框问题, (想要的是XXX.AddItem "X"时 下的显示在最底层),假设我的列表框项目容纳4个项目时 后面每次XXX.AddItem "X" 时 在项目超过4的情况下 他是变为垂直滚动条往下继续显示 ,这是我想要的 但是 问题就出在这里,就是显示列表框前4个项目后面添加的是在最下面 每XXX.AddItem "X" 时 鼠标都得往垂直滚动条标志那点 才知道他是显示什么!
 能不能让滚动条直接在最底层 显示过的 往上可以看,!
 请帮忙下 谢谢
2011-05-25 20:44
showcdk
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-5-14
收藏
得分:0 
补充下问题1, 拖动时 程序可以跟我拖动没关系吗?
2011-05-25 20:46
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:40 
问题1:因为VB的只能是单执行绪~所以理论上此题无解~除非调用API解决~

刚好这里有个类范例可以解决问题~看不懂不要问我~因为我也看不懂

module:
程序代码:
Option Explicit

'Public Const THREAD_PRIORITY_ERROR_RETURN = (MAXLONG)
Public Const THREAD_BASE_PRIORITY_MAX = 2
Public Const THREAD_BASE_PRIORITY_MIN = -2
Public Const THREAD_BASE_PRIORITY_LOWRT = 15
Public Const THREAD_BASE_PRIORITY_IDLE = -15

Public Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
Public Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
Public Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
Public Const THREAD_PRIORITY_NORMAL = 0
Public Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
Public Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
Public Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)

Public Const CREATE_SUSPENDED = &H4

'declares

Public Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long

Public Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CreateEvent& Lib "kernel32" Alias "CreateEventA" (ByVal lpEventAttributes As Long, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpname As String)
Public Declare Function SuspendThread Lib "kernel32" (ByVal hThread As Long) As Long

Public Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Public Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Public Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long


Class:
程序代码:
Option Explicit

Dim m_threadhandle As Long

Public m_thread_created As Boolean

Enum threadpriority
    th_normal = THREAD_PRIORITY_NORMAL
    th_abovenormal = THREAD_PRIORITY_ABOVE_NORMAL
    th_belownormal = THREAD_PRIORITY_BELOW_NORMAL
    th_idle = THREAD_PRIORITY_IDLE
    th_lowest = THREAD_PRIORITY_LOWEST
    th_critical = THREAD_PRIORITY_TIME_CRITICAL
    th_highest = THREAD_PRIORITY_HIGHEST
End Enum

Public Sub startthread(v_addressoffunction As Long, Optional v_immediately As Boolean = True, Optional v_setpriority As threadpriority = threadpriority.th_normal)
Attribute startthread.VB_Description = "This function takes the address of the  function that is to be executed in a seperate thread use address of operator in vb make sure the function does have  doevents statement in the loop"

Dim l_tid As Long

    If Not m_thread_created Then
    If v_addressoffunction > 0 Then
    'm_thread_created = True
     If v_immediately Then
      m_threadhandle = CreateThread(ByVal 0&, ByVal 0&, v_addressoffunction, ByVal 0&, 0&, l_tid)
     Else
    'use resume thread for execution
      m_threadhandle = CreateThread(ByVal 0&, ByVal 0&, v_addressoffunction, ByVal 0&, CREATE_SUSPENDED, l_tid)
     End If
    
        If m_threadhandle > 0 Then
          Call setpriority(v_setpriority)
          m_thread_created = True
        End If
    
     End If
    End If
End Sub

Public Sub stopthread()
Dim l_ret As Long
    If m_thread_created Then
        l_ret = TerminateThread(m_threadhandle, 0&)
        m_thread_created = False
    End If
End Sub

Public Sub pausethread()
Dim l_ret As Long
    If m_thread_created Then
        l_ret = SuspendThread(m_threadhandle)
    End If
End Sub

Public Sub ResumetheThread()
Dim l_ret As Long
    If m_thread_created Then
        l_ret = ResumeThread(m_threadhandle)
    End If
End Sub

Public Sub setpriority(Optional ByVal v_priority As threadpriority = threadpriority.th_normal)
Dim l_ret As Long
    If m_thread_created Then
        l_ret = SetThreadPriority(m_threadhandle, v_priority)
    End If
End Sub

Private Sub Class_Initialize()
    m_thread_created = False
End Sub

Private Sub Class_Terminate()
Dim l_ret As Long
    If m_threadhandle > 0 Then
        l_ret = TerminateThread(m_threadhandle, 0&)
    End If
End Sub

Public Sub setotherthreadpriority(ByVal v_threadid As Long, Optional ByVal v_priority As threadpriority = threadpriority.th_normal)
Dim l_ret As Long
    l_ret = SetThreadPriority(v_threadid, v_priority)
End Sub

Public Sub about()
Attribute about.VB_Description = "shows about"
Attribute about.VB_UserMemId = -552
    ShellAbout GetDesktopWindow(), "Multi threader dll", "Multi threader", 0&
End Sub


[ 本帖最后由 wube 于 2011-5-25 22:39 编辑 ]

不要選我當版主
2011-05-25 20:57
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
问题2:

程序代码:
Option Explicit

Private Sub Form_Load()
Dim i As Integer
    For i = 0 To 100
        List1.AddItem i
    Next i
    List1.TopIndex = i - 1
End Sub

不要選我當版主
2011-05-25 21:03
快速回复:VB 问题! 求教 求指导 进!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033774 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved