滚动条控件问题
#include <windows.h>
#include "strsafe.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstantce,LPSTR lpCmdLine,int nShowCmd)
{
static TCHAR zifu[]=TEXT("我是字符串");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=TEXT("wodechuangkou2");
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.hInstance=hInstance;
wndclass.lpszMenuName=NULL;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("buxing"),TEXT("zhenbuxing"),MB_YESNO);
return 0;
}
hwnd=CreateWindow(
TEXT("wodechuangkou2"),
TEXT("我是个标题"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAMwParam,LPARAM lParam)
{
HINSTANCE hInstance;
static int cxClient,cyClient;
int i;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static WCHAR bzBuffer;
static HWND Hwndlabel,Pingtai,Hwndscrollbar,HwndValue;
TCHAR* szColorLablel[]={TEXT("Red"),TEXT("Green"),TEXT("Blue")};
static TEXTMETRIC tm;
static SCROLLINFO scroll;
static int color;
size_t leng;
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
hInstance=(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE);
Pingtai=CreateWindow(TEXT("static"),NULL,WS_CHILD|WS_VISIBLE|SS_WHITERECT,0,0,0,0,hwnd,(HMENU)9,hInstance,NULL);
scroll.cbSize=sizeof(SCROLLINFO);
scroll.fMask=SIF_ALL;
scroll.nMax=255;
scroll.nMin=0;
scroll.nPage=15;
scroll.nPos=0;
for(i=0;i<3;i++)
{
Hwndlabel=CreateWindow(TEXT("static"),szColorLablel,WS_CHILD|WS_VISIBLE|SS_CENTER,0,0,0,0,hwnd,(HMENU)(i),hInstance,NULL);
Hwndscrollbar=CreateWindow(TEXT("scrollbar"),NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP|SBS_VERT,0,0,0,0,hwnd,(HMENU)(i+3),hInstance,NULL);
HwndValue=CreateWindow(TEXT("static"),TEXT("0"),WS_CHILD|WS_VISIBLE|SS_CENTER,0,0,0,0,hwnd,(HMENU)(i+6),hInstance,NULL);
SetScrollInfo(Hwndscrollbar,SB_CTL,&scroll,TRUE);
}
break;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
MoveWindow(Pingtai,0,0,cxClient/2,cyClient,TRUE);
for(i=0;i<3;i++)
{
MoveWindow(Hwndlabel,(4*i+1)*cxClient/28,tm.tmHeight/2,cxClient / 7, tm.tmHeight, TRUE);
MoveWindow(Hwndscrollbar,(4*i+2)*cxClient/28,tm.tmHeight*1.5,cxClient/14,cyClient-tm.tmHeight*4,TRUE);
MoveWindow(HwndValue,(4*i+1)*cxClient/28,cyClient-tm.tmHeight*2.5,cxClient/7,tm.tmHeight,TRUE);
}
break;
case WM_VSCROLL:
i=GetWindowLong((HWND)lParam,GWL_ID)-3;
switch (LOWORD(wParam))
{
case SB_PAGEDOWN:
color=min(255,color+15);
break;
case SB_PAGEUP:
color=max(0,color-15);
break;
case SB_LINEUP:
color=max(0,color-1);
break;
case SB_LINEDOWN:
color=min(255,color+1);
break;
case SB_THUMBTRACK:
scroll.cbSize=sizeof(SCROLLINFO);
scroll.fMask=SIF_ALL;
GetScrollInfo((HWND)lParam,SB_CTL,&scroll);
color =scroll.nTrackPos;
break;
}
scroll.cbSize=sizeof(SCROLLINFO);
scroll.fMask=SIF_POS;
scroll.nPos=color;
SetScrollInfo((HWND)lParam,SB_CTL,&scroll,TRUE);
StringCchPrintf(bzBuffer,10,TEXT("%d"),color);
SetWindowText(HwndValue,bzBuffer);
break;
case WM_PAINT:
hdc=BeginPaint (hwnd,&ps);
GetClientRect (hwnd,&rect);
EndPaint (hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
//case WM_PAINT:
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
为什么滚动条托到最下面 不是255 是 241 @小甲鱼 滑块也有大小,要计算滑块的大小
页:
[1]