Click to See Complete Forum and Search --> : WM_VSCROLL Problem


dwb11
June 12th, 2009, 10:01 AM
Hello,
I am having a problem getting my program to execute any code under my WM_VSCROLL case statement. I posted some code that sends a message that I think WM_VSCROLL should pickup, but is not. When I run my code I can see the third listbox scrolling down every time I change the selection in the first listbox, but I don't get a messagebox. What I am trying to do is have when a user scrolls through one of the listboxes I want the other two to scroll with it accordingly so it appears as one to the user. WM_VSCROLL is the message I want to listen to when a user interacts with a scrollbar, correct? Thank you for your time.


LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND hwndTrack1,hwndTrack2,hwndTrack3;
switch(msg)
{
case WM_CREATE:
{
hwndTrack1=CreateWindow(TEXT("listbox"),NULL,
WS_CHILD | WS_VISIBLE | LBS_NOTIFY ,
180, 10, 110, 200, hwnd, (HMENU) IDM_TRACK1, g_hinst, NULL);
hwndTrack2=CreateWindow(TEXT("listbox"),NULL,
WS_CHILD | WS_VISIBLE | LBS_NOTIFY ,
290, 10, 110, 200, hwnd, (HMENU) IDM_TRACK2, g_hinst, NULL);
hwndTrack3=CreateWindow(TEXT("listbox"),NULL,
WS_CHILD | WS_VISIBLE | LBS_NOTIFY|WS_VSCROLL ,
400, 10, 110, 200, hwnd, (HMENU) IDM_TRACK3, g_hinst, NULL);
for(int i=0;i<20;i++)
{
SendMessage(hwndTrack1,LB_ADDSTRING,0,(LPARAM) TEXT("JUNK"));
SendMessage(hwndTrack2,LB_ADDSTRING,0,(LPARAM) TEXT("JUNK"));
SendMessage(hwndTrack3,LB_ADDSTRING,0,(LPARAM) TEXT("JUNK"));
}
break;
}
case WM_COMMAND:
{
if(HIWORD(wParam)==CBN_SELCHANGE)
{
if(LOWORD(wParam)==IDM_TRACK1)
{
SendMessage(hwndTrack3,WM_VSCROLL,SB_LINEDOWN,0);
}
}
break;
}
case WM_VSCROLL:
{
MessageBox(NULL,TEXT("CLICKED"),TEXT("CLICKED"),MB_OK);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}

olivthill2
June 12th, 2009, 11:45 AM
You don't see the MessageBox, because WM_VSCROLL is sent to the ListBox. It is not sent to the parent Window of the ListBox, even though you have LBS_NOTIFY.

Here is a modified version of your program, and you will see the MessageBox:
#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


LRESULT CALLBACK ListProc3(HWND, UINT, WPARAM, LPARAM);
WNDPROC OriginalListProc3;

LRESULT CALLBACK ListProc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_VSCROLL) {
MessageBox(NULL,"CLICKED LB","CLICKED LB", MB_OK);
return 0;
}
return CallWindowProc(OriginalListProc3, hwnd, message, wParam, lParam);
}

/* This function is called by the Windows function DispatchMessage() */
#define IDM_TRACK1 2001
#define IDM_TRACK2 2002
#define IDM_TRACK3 2003
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndTrack1,hwndTrack2,hwndTrack3;
switch (message) /* handle the messages */
{
case WM_CREATE:
{
hwndTrack1=CreateWindow(TEXT("listbox"), NULL,
WS_CHILD | WS_VISIBLE | LBS_NOTIFY ,
180, 10, 110, 200, hwnd, (HMENU) IDM_TRACK1,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hwndTrack2=CreateWindow(TEXT("listbox"), NULL,
WS_CHILD | WS_VISIBLE | LBS_NOTIFY ,
290, 10, 110, 200, hwnd, (HMENU) IDM_TRACK2,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hwndTrack3=CreateWindow(TEXT("listbox"), NULL,
WS_CHILD | WS_VISIBLE | LBS_NOTIFY|WS_VSCROLL ,
400, 10, 110, 200, hwnd, (HMENU) IDM_TRACK3,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
OriginalListProc3 = (WNDPROC)SetWindowLong(hwndTrack3, GWL_WNDPROC, (LPARAM) ListProc3);
for(int i=0;i<20;i++)
{
SendMessage(hwndTrack1,LB_ADDSTRING,0,(LPARAM) TEXT("JUNK"));
SendMessage(hwndTrack2,LB_ADDSTRING,0,(LPARAM) TEXT("JUNK"));
SendMessage(hwndTrack3,LB_ADDSTRING,0,(LPARAM) TEXT("JUNK"));
}
SendMessage(hwndTrack1, LB_SETCURSEL, (WPARAM)(0), (LPARAM)(0));
SendMessage(hwndTrack2, LB_SETCURSEL, (WPARAM)(0), (LPARAM)(0));
SendMessage(hwndTrack3, LB_SETCURSEL, (WPARAM)(0), (LPARAM)(0));
}
break;
case WM_COMMAND:
{
if(HIWORD(wParam)==CBN_SELCHANGE)
{
if(LOWORD(wParam)==IDM_TRACK1)
{
SendMessage(hwndTrack3,WM_VSCROLL,SB_LINEDOWN,0);
}
}
break;
}
case WM_VSCROLL:
{
MessageBox(NULL,"CLICKED Parent","CLICKED Parent",MB_OK);
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

dwb11
June 12th, 2009, 04:14 PM
Never mind. Issue resolved. Thanks for your help olivthill2.