#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,WPARAM wParam,LPARAM lParam)
{
HINSTANCE hInstance;
static int cxClient,cyClient;
int i;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static WCHAR bzBuffer[10];
static HWND Hwndlabel[3],Pingtai,Hwndscrollbar[3],HwndValue[3];
TCHAR* szColorLablel[]={TEXT("Red"),TEXT("Green"),TEXT("Blue")};
static TEXTMETRIC tm;
static SCROLLINFO scroll;
static int color[3];
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[i]=CreateWindow(TEXT("static"),szColorLablel[i],WS_CHILD|WS_VISIBLE|SS_CENTER,0,0,0,0,hwnd,(HMENU)(i),hInstance,NULL);
Hwndscrollbar[i]=CreateWindow(TEXT("scrollbar"),NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP|SBS_VERT,0,0,0,0,hwnd,(HMENU)(i+3),hInstance,NULL);
HwndValue[i]=CreateWindow(TEXT("static"),TEXT("0"),WS_CHILD|WS_VISIBLE|SS_CENTER,0,0,0,0,hwnd,(HMENU)(i+6),hInstance,NULL);
SetScrollInfo(Hwndscrollbar[i],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[i],(4*i+1)*cxClient/28,tm.tmHeight/2,cxClient / 7, tm.tmHeight, TRUE);
MoveWindow(Hwndscrollbar[i],(4*i+2)*cxClient/28,tm.tmHeight*1.5,cxClient/14,cyClient-tm.tmHeight*4,TRUE);
MoveWindow(HwndValue[i],(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[i]=min(255,color[i]+15);
break;
case SB_PAGEUP:
color[i]=max(0,color[i]-15);
break;
case SB_LINEUP:
color[i]=max(0,color[i]-1);
break;
case SB_LINEDOWN:
color[i]=min(255,color[i]+1);
break;
case SB_THUMBTRACK:
scroll.cbSize=sizeof(SCROLLINFO);
scroll.fMask=SIF_ALL;
GetScrollInfo((HWND)lParam,SB_CTL,&scroll);
color[i] =scroll.nTrackPos;
break;
}
scroll.cbSize=sizeof(SCROLLINFO);
scroll.fMask=SIF_POS;
scroll.nPos=color[i];
SetScrollInfo((HWND)lParam,SB_CTL,&scroll,TRUE);
StringCchPrintf(bzBuffer,10,TEXT("%d"),color[i]);
SetWindowText(HwndValue[i],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