{"id":162,"date":"2022-05-27T22:14:19","date_gmt":"2022-05-27T19:14:19","guid":{"rendered":"http:\/\/www.cuneytbayrak.com\/?p=162"},"modified":"2025-02-21T00:37:37","modified_gmt":"2025-02-20T21:37:37","slug":"vba-listboxi-fare-topu-ile-hareket-ettirmek","status":"publish","type":"post","link":"http:\/\/www.cuneytbayrak.com\/?p=162","title":{"rendered":"VBA ListBox\u2019\u0131 Fare Topu \u0130le Hareket Ettirmek"},"content":{"rendered":"<p>UserForm i\u00e7ine yaz\u0131lacak kodlar\u2026\u2026<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text\/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)\r\nHookListBoxScroll\r\nEnd Sub\r\n \r\nPrivate Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)\r\nUnhookListBoxScroll\r\nEnd Sub<\/pre>\n<\/div>\n<p>Module alan\u0131na yaz\u0131lacak kodlar\u2026.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text\/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">Option Explicit\r\n \r\nPrivate Type POINTAPI\r\nX As Long\r\nY As Long\r\nEnd Type\r\n \r\nPrivate Type MOUSEHOOKSTRUCT\r\npt As POINTAPI\r\nhwnd As Long\r\nwHitTestCode As Long\r\ndwExtraInfo As Long\r\nEnd Type\r\n \r\nPrivate Declare Function FindWindow Lib \"user32\" _\r\nAlias \"FindWindowA\" ( _\r\nByVal lpClassName As String, _\r\nByVal lpWindowName As String) As Long\r\n \r\nPrivate Declare Function GetWindowLong Lib \"user32.dll\" _\r\nAlias \"GetWindowLongA\" ( _\r\nByVal hwnd As Long, _\r\nByVal nIndex As Long) As Long\r\n \r\nPrivate Declare Function SetWindowsHookEx Lib \"user32\" _\r\nAlias \"SetWindowsHookExA\" ( _\r\nByVal idHook As Long, _\r\nByVal lpfn As Long, _\r\nByVal hmod As Long, _\r\nByVal dwThreadId As Long) As Long\r\n \r\nPrivate Declare Function CallNextHookEx Lib \"user32\" ( _\r\nByVal hHook As Long, _\r\nByVal nCode As Long, _\r\nByVal wParam As Long, _\r\nlParam As Any) As Long\r\n \r\nPrivate Declare Function UnhookWindowsHookEx Lib \"user32\" ( _\r\nByVal hHook As Long) As Long\r\n \r\nPrivate Declare Function PostMessage Lib \"user32.dll\" _\r\nAlias \"PostMessageA\" ( _\r\nByVal hwnd As Long, _\r\nByVal wMsg As Long, _\r\nByVal wParam As Long, _\r\nByVal lParam As Long) As Long\r\n \r\nPrivate Declare Function WindowFromPoint Lib \"user32\" ( _\r\nByVal xPoint As Long, _\r\nByVal yPoint As Long) As Long\r\n \r\nPrivate Declare Function GetCursorPos Lib \"user32.dll\" ( _\r\nByRef lpPoint As POINTAPI) As Long\r\n \r\nPrivate Const WH_MOUSE_LL As Long = 14\r\nPrivate Const WM_MOUSEWHEEL As Long = &amp;H20A\r\nPrivate Const HC_ACTION As Long = 0\r\nPrivate Const GWL_HINSTANCE As Long = (-6)\r\n \r\nPrivate Const WM_KEYDOWN As Long = &amp;H100\r\nPrivate Const WM_KEYUP As Long = &amp;H101\r\nPrivate Const VK_UP As Long = &amp;H26\r\nPrivate Const VK_DOWN As Long = &amp;H28\r\nPrivate Const WM_LBUTTONDOWN As Long = &amp;H201\r\n \r\nPrivate mLngMouseHook As Long\r\nPrivate mListBoxHwnd As Long\r\nPrivate mbHook As Boolean\r\n \r\nSub HookListBoxScroll()\r\nDim lngAppInst As Long\r\nDim hwndUnderCursor As Long\r\nDim tPT As POINTAPI\r\nGetCursorPos tPT\r\nhwndUnderCursor = WindowFromPoint(tPT.X, tPT.Y)\r\nIf mListBoxHwnd &lt;&gt; hwndUnderCursor Then\r\nUnhookListBoxScroll\r\nmListBoxHwnd = hwndUnderCursor\r\nlngAppInst = GetWindowLong(mListBoxHwnd, GWL_HINSTANCE)\r\nPostMessage mListBoxHwnd, WM_LBUTTONDOWN, 0&amp;, 0&amp;\r\nIf Not mbHook Then\r\nmLngMouseHook = SetWindowsHookEx( _\r\nWH_MOUSE_LL, AddressOf MouseProc, lngAppInst, 0)\r\nmbHook = mLngMouseHook &lt;&gt; 0\r\nEnd If\r\nEnd If\r\nEnd Sub\r\n \r\nSub UnhookListBoxScroll()\r\nIf mbHook Then\r\nUnhookWindowsHookEx mLngMouseHook\r\nmLngMouseHook = 0\r\nmListBoxHwnd = 0\r\nmbHook = False\r\nEnd If\r\nEnd Sub\r\n \r\nPrivate Function MouseProc( _\r\nByVal nCode As Long, ByVal wParam As Long, _\r\nByRef lParam As MOUSEHOOKSTRUCT) As Long\r\nOn Error GoTo errH 'Resume Next\r\nIf (nCode = HC_ACTION) Then\r\nIf WindowFromPoint(lParam.pt.X, lParam.pt.Y) = mListBoxHwnd Then\r\nIf wParam = WM_MOUSEWHEEL Then\r\nMouseProc = True\r\nIf lParam.hwnd &gt; 0 Then\r\nPostMessage mListBoxHwnd, WM_KEYDOWN, VK_UP, 0\r\nElse\r\nPostMessage mListBoxHwnd, WM_KEYDOWN, VK_DOWN, 0\r\nEnd If\r\nPostMessage mListBoxHwnd, WM_KEYUP, VK_UP, 0\r\nExit Function\r\nEnd If\r\nElse\r\nUnhookListBoxScroll\r\nEnd If\r\nEnd If\r\nMouseProc = CallNextHookEx( _\r\nmLngMouseHook, nCode, wParam, ByVal lParam)\r\nExit Function\r\nerrH:\r\nUnhookListBoxScroll\r\nEnd Function<\/pre>\n<\/div>\n<p>Kolay gele&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UserForm i\u00e7ine yaz\u0131lacak kodlar\u2026\u2026 Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) HookListBoxScroll End Sub Private Sub UserForm_QueryClose(Cancel As Integer,&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.cuneytbayrak.com\/?p=162\">Devam\u0131n\u0131 Oku<span class=\"screen-reader-text\">VBA ListBox\u2019\u0131 Fare Topu \u0130le Hareket Ettirmek<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[5],"tags":[40],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-excel-vba","tag-listboxmousemove","excerpt"],"_links":{"self":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=162"}],"version-history":[{"count":1,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":163,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions\/163"}],"wp:attachment":[{"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cuneytbayrak.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}