求助需要一个同API写的滑动条的例子 求助 如上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #include <windows.h> #include "sysmets.h" LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("SysMets") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("Program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT ("Get System Metrics"), WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } 刚巧前段时间写了一个,其实msdn是有例子的#define TOTAL_LINE_CNT 10000#define MAX_SCROLL_VAL 100LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){PAINTSTRUCT ps;HDC hdc;char szTextBuf[128];TEXTMETRIC tm;static int iCharHigh;static int iLineCntInView;static int iCurStartLine;int iOldPos;int iOldStartLine;RECT rt;RECT textrt;int i; // loop counterSCROLLINFO si;switch (message) /* handle the messages */{case WM_CREATE:hdc = GetDC (hWnd);GetTextMetrics (hdc, &tm);iCharHigh = tm.tmHeight + tm.tmExternalLeading;ReleaseDC (hWnd, hdc);GetClientRect(hWnd, &rt);iLineCntInView = ( rt.bottom -rt.top ) / iCharHigh;iCurStartLine = 0;si.cbSize = sizeof(si);si.fMask = SIF_POS | SIF_RANGE;si.nPos = 0;si.nMin = 0;si.nMax = MAX_SCROLL_VAL;SetScrollInfo(hWnd, SB_VERT, &si, TRUE);break;case WM_VSCROLL:si.cbSize = sizeof (si);si.fMask = SIF_ALL;GetScrollInfo( hWnd, SB_VERT, &si );iOldStartLine = iCurStartLine;iOldPos = si.nPos;switch( LOWORD (wParam) ){case SB_PAGEUP:if ( iCurStartLine > iLineCntInView )iCurStartLine -= iLineCntInView;elseiCurStartLine = 0;break;case SB_PAGEDOWN:if ( iCurStartLine + iLineCntInView < TOTAL_LINE_CNT - iLineCntInView )iCurStartLine += iLineCntInView;elseiCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;case SB_LINEUP:if ( iCurStartLine > 0 )iCurStartLine --;break;case SB_LINEDOWN:if( iCurStartLine < TOTAL_LINE_CNT - iLineCntInView )iCurStartLine ++;elseiCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;case SB_THUMBTRACK:iCurStartLine = si.nTrackPos * ( TOTAL_LINE_CNT / MAX_SCROLL_VAL );if( iCurStartLine > TOTAL_LINE_CNT )iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;}if ( iCurStartLine != iOldStartLine ){si.nPos = iCurStartLine / ( TOTAL_LINE_CNT / MAX_SCROLL_VAL );if ( iOldPos != si.nPos ){si.fMask = SIF_POS;SetScrollInfo(hWnd, SB_VERT, &si, TRUE);}ScrollWindow(hWnd, 0, iCharHigh * (iOldStartLine - iCurStartLine), NULL, NULL);UpdateWindow(hWnd);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps);GetClientRect(hWnd, &rt);textrt = rt;for( textrt = rt, i = iCurStartLine; textrt.top < rt.bottom; textrt.top += iCharHigh, i ++ ){sprintf( szTextBuf, "%d", i );DrawText(hdc, szTextBuf, strlen(szTextBuf), &textrt, DT_CENTER);}EndPaint(hWnd, &ps);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; 谢谢了啊 我的英文不太好 CSDN上的例子也没有消息处理呢 给分了 dll能否主动调用exe的函数? 如何使窗口背景透明 关于在vc++6.0中用FTP传送文件的问题,请大虾赐教 有点难度的问题,高手进。 VC调用COM 真实郁闷死了,编译不过去啊 谢谢 一个关于DECLARE_SERIAL()的使用问题,急,请各位朋友帮忙 设置打印对话框(高分) 100分问个低级问题~~~求助 peon领分3 Winsock第二版不能再不同线程中调用,对不对?(空) 大虾们,listctrl问题!!! 求《Winsock 2网络编程实用教程》的随书光盘
#include "sysmets.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SysMets") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Get System Metrics"),
WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
#define MAX_SCROLL_VAL 100LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char szTextBuf[128];TEXTMETRIC tm;static int iCharHigh;
static int iLineCntInView;static int iCurStartLine;int iOldPos;
int iOldStartLine;
RECT rt;
RECT textrt;
int i; // loop counter
SCROLLINFO si;switch (message) /* handle the messages */
{
case WM_CREATE:hdc = GetDC (hWnd);
GetTextMetrics (hdc, &tm);
iCharHigh = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC (hWnd, hdc);GetClientRect(hWnd, &rt);
iLineCntInView = ( rt.bottom -rt.top ) / iCharHigh;iCurStartLine = 0;si.cbSize = sizeof(si);
si.fMask = SIF_POS | SIF_RANGE;
si.nPos = 0;
si.nMin = 0;
si.nMax = MAX_SCROLL_VAL;
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);break;case WM_VSCROLL:si.cbSize = sizeof (si);
si.fMask = SIF_ALL;
GetScrollInfo( hWnd, SB_VERT, &si );iOldStartLine = iCurStartLine;
iOldPos = si.nPos;
switch( LOWORD (wParam) )
{
case SB_PAGEUP:if ( iCurStartLine > iLineCntInView )
iCurStartLine -= iLineCntInView;
else
iCurStartLine = 0;break;case SB_PAGEDOWN:if ( iCurStartLine + iLineCntInView < TOTAL_LINE_CNT - iLineCntInView )
iCurStartLine += iLineCntInView;
else
iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;case SB_LINEUP:
if ( iCurStartLine > 0 )
iCurStartLine --;break;case SB_LINEDOWN:
if( iCurStartLine < TOTAL_LINE_CNT - iLineCntInView )
iCurStartLine ++;
else
iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;case SB_THUMBTRACK:
iCurStartLine = si.nTrackPos * ( TOTAL_LINE_CNT / MAX_SCROLL_VAL );
if( iCurStartLine > TOTAL_LINE_CNT )
iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;
break;}if ( iCurStartLine != iOldStartLine )
{
si.nPos = iCurStartLine / ( TOTAL_LINE_CNT / MAX_SCROLL_VAL );if ( iOldPos != si.nPos )
{
si.fMask = SIF_POS;
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
}ScrollWindow(hWnd, 0, iCharHigh * (iOldStartLine - iCurStartLine), NULL, NULL);
UpdateWindow(hWnd);}
break;case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);GetClientRect(hWnd, &rt);
textrt = rt;
for( textrt = rt, i = iCurStartLine; textrt.top < rt.bottom; textrt.top += iCharHigh, i ++ )
{
sprintf( szTextBuf, "%d", i );
DrawText(hdc, szTextBuf, strlen(szTextBuf), &textrt, DT_CENTER);
}EndPaint(hWnd, &ps);
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;