怎么让滚动条动起来?
xieqi 2004-11-09 04:52:23 我创建了滚动条,也接受了滚动条消息。但我不知道该怎么让滚动条上移,或下移。
代码如下:
================================
#include "windows.h"
HINSTANCE hInst;
HWND hWndMain;
LRESULT APIENTRY MainWndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitInstance(HINSTANCE,int);
BOOL InitApplication(HINSTANCE);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
if (!InitApplication (hInstance))
{
return FALSE;
}
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// SendMessage(hWndMain,WM_COMMAND,IDM_DRAW,0L);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
BOOL InitApplication (HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)MainWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, "ScrollBarIcon");
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = "";
wcex.lpszClassName = "SCROLL";
wcex.hIconSm = LoadIcon(hInstance, "ScrollBarIcon");
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
hWndMain = CreateWindow("SCROLL", "SCROLLBAR1", WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWndMain)
{
return FALSE;
}
ShowWindow(hWndMain, nCmdShow);
UpdateWindow(hWndMain);
return TRUE;
}
LRESULT APIENTRY MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char * szHello;
szHello="如何使滚动条动起来啊?";
switch(message)
{
case WM_VSCROLL:
switch(LOWORD(wParam))
{
case SB_LINEUP:
MessageBox(NULL,"你点中了 上 移滚动条,但是滚动条不响应","提示",MB_OK);//在这里加什么代码让滚动条上移
break;
case SB_LINEDOWN:
MessageBox(NULL,"你点中了 下 移滚动条,但是滚动条不响应","提示",MB_OK);//在这里加什么代码让滚动条下移
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return(0);
}
====================================
点中滚动条后会提示你点中了,但我怎么让他上移下移呢?