The code editor in the integrated development environment of Visual Basic 6.0 does not support the operation of the mouse wheel, which brings a lot of inconvenience to people who use VB, in order to support the mouse wheel operation, I have made a small program to help it implement it. Features.
The principle of this program implementation is to use the global hook intercept window message, and send a view scroll message to the VB editing window to the VB editing window to the VB editing window to the VB editing window.
First, establish an MFC DLL project, add the following function to the project:
The following functions are used to install the hook, which is stated in this form, mainly considering its scalability.
BOOL __DECLSPEC (DLLEXPORT) __ stdcall installhook (int Nidhook, Const Hinstance Hmod, DWORD DWTHREADID)
{
AFX_MANAGE_STATE (AFXGETSTATICModuleState ());
Bool Bresult;
Hinstance hinstance = null;
IF (hmod == null)
{
Hinstance = AfxGetInstanceHandle ();
Else
{
Hinstance = hmod;
}
Switch (Nidhook)
{
Case wh_callwndproc:
IF (g_hwinproc! = null)
{
BRESULT = True;
Break;
}
g_hwinproc = setwindowshookex (WH_CallWndProc, (HookProc) ProcessWndProc, Hinstance, DWTHREADID;
IF (g_hwinproc! = null)
{
BRESULT = True;
}
Break;
Case wh_getimentage:
IF (g_hmsgproc! = null)
{
BRESULT = True;
Break;
}
g_hmsgproc = setWindowsHookex (WH_GetMessage, (HookProc) ProcessMsgProc, Hinstance, DWTHREADID;
IF (g_hmsgproc! = null)
{
BRESULT = True;
}
Break;
DEFAULT:
BRESULT = FALSE;
Break;
}
Return BRESULT;
}
The following functions are used to uninstall the hook and correspond to the previous function.
BOOL __DECLSPEC (DLLEXPORT) __ stdcall uninstallhook (int Nidhook)
{
Bool Bresult;
Switch (Nidhook)
{
Case wh_callwndproc:
BRESULT = UnHookWindowsHookex (g_hwinproc);
g_hwinproc = NULL;
Break;
Case wh_getimentage:
BRESULT = UnHookWindowsHookex (g_hmsgproc);
g_hmsgproc = null;
Break;
DEFAULT:
BRESULT = True;
}
Return BRESULT;
}
The following function is the response function of the message sent by PostMessage, where the mouse roller event responds, so that the VB supports the roller.
LResult __Declspec (dllexport) __ stdcall callback processmsgproc
Int ncode, // hook code
WPARAM WPARAM, / / CURRENT-Process Flag
LParam Lparam // Address of Structure with Message Data)
{
AFX_MANAGE_STATE (AFXGETSTATICModuleState ());
INT n = 0;
Msg * pimentage = (msg *) lparam;
CWND * PWND = NULL;
CWND * pscroll = null;
Char BUF [256];
IF (pMessage-> message == wm_mousewheel && g_bvbhelper)
{
PWND = CWND :: fromHandle (PMessage-> HWnd);
IF (PWND! = null)
{
:: getClassName (PMessage-> HWND, BUF, 255);
CString SWNDCLASS (BUF);
IF (SWNDCLASS.COMPARE ("vbawindow") == 0)
{
Pscroll = PWND-> getWindow;
While (pscroll! = null)
{
:: getclassname (pscroll-> getsafehwnd (), buf, 255);
SWNDCLASS.FORMAT ("% s", buf);
IF (SWNDCLASS.COMPARE ("scrollbar") == 0 && (pscroll-> getStyle () & SBS_VERT))
{
Break;
}
Pscroll = pscroll-> getWindow (gw_hwndnext);
}
IF ((Short) HiWord (PMessage-> WPARAM <0)))
{
:: SendMessage (PMessage-> HWND, WM_VScroll, MakewParam (SB_Linedown, 0), (LPARAM) (pscroll == NULL? 0: pscroll-> getsafehwnd ()));
:: SendMessage (PMessage-> HWND, WM_VSCROLL, MAKEWPARAM (SB_ENDSCROLL, 0), (LPARAM) (pscroll == NULL? 0: pscroll-> getsafehwnd ()));
Else IF ((Short) HiWord (PMessage-> WPARAM> 0)))
{
:: SendMessage (PMessage-> HWND, WM_VScroll, MakewParam (SB_LineUp, 0), (LPARAM) (pscroll == NULL? 0: pscroll-> getsafehwnd ());
:: SendMessage (PMessage-> HWND, WM_VSCROLL, MAKEWPARAM (SB_ENDSCROLL, 0), (LPARAM) (pscroll == NULL? 0: pscroll-> getsafehwnd ()));
}
}
Return 0;
}
}
Return CallNexthookex (G_HwinProc, Ncode, WPARAM, LPARAM);
}
It is not difficult to see from the above code, the key to solving the problem is to intercept the required message (WM_MouseWheel) and transform the message into a response message (WM_VScroll) sent to the destination window. Among them, it is necessary to note that we use global hooks, so it will intercept all forms of messages, so it is necessary to judge the messages and forms in the program. For those who are not what we want, it is released. We want to handle it. Through the analysis of this problem, we can find that similar methods can be used to implement the minimization of certain programs, that is, when receiving the minimum message of a specific window, send the WM_SHOWINDOW message to it, and then in the notification area Generate a corresponding icon, if the user clicks the icon, the window is displayed.