cwnd控件中是否内置支持滚动条?

boman258 2005-02-24 01:24:07
if (yes)
如何使用?
else
怎样增加滚动条功能?
...全文
173 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
boman258 2005-02-28
  • 打赏
  • 举报
回复
谢谢各位,问题已经解决!
ttapi 2005-02-25
  • 打赏
  • 举报
回复
以前写得咚咚,希望对你有点帮助
// SimpleSnap.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "xxxx.h"

#include <windowsx.h>

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);

// window proceedures
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
// message handlers
void OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify);
void OnPaint(HWND hWnd);
BOOL OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct);
void OnDestroy(HWND hWnd);
void OnHScroll(HWND hWnd, HWND hWndCtl, UINT code, int pos);
void OnVScroll(HWND hWnd, HWND hWndCtl, UINT code, int pos);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SIMPLESNAP, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLESNAP);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLESNAP);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_SIMPLESNAP;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
HANDLE_MSG (hWnd, WM_CREATE, OnCreate);
HANDLE_MSG (hWnd, WM_COMMAND, OnCommand);
HANDLE_MSG (hWnd, WM_PAINT, OnPaint);
HANDLE_MSG (hWnd, WM_DESTROY, OnDestroy);
HANDLE_MSG (hWnd, WM_VSCROLL, OnVScroll);
HANDLE_MSG (hWnd, WM_HSCROLL, OnHScroll);
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}


void OnPaint(HWND hWnd)
{
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
}

BOOL OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
{
// ScrollBar_Show(hWnd, TRUE);
ShowScrollBar(hWnd, SB_BOTH, FALSE);
SetScrollRange(hWnd, SB_HORZ, 0, 1000, FALSE);
SetScrollRange(hWnd, SB_VERT, 0, 1000, FALSE);

return TRUE;
}

void OnDestroy(HWND hWnd)
{
PostQuitMessage(0);
}

void OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify)
{
HDC hdc;
int w, h;
char dbg[100];

// Parse the menu selections:
switch (id)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
}
}


void OnHScroll(HWND hWnd, HWND hWndCtl, UINT code, int pos)
{
int x;
RECT rc;

x = GetScrollPos(hWnd, SB_HORZ);
GetClientRect(hWnd, &rc);

if(code == SB_LINELEFT)
{
x -= 10;
rc.right = 10;
}
if(code == SB_LINERIGHT)
{
x += 10;
rc.left = 10;
}
if(code == SB_PAGELEFT)
{
x -= 100;
rc.right = 100;
}
if(code == SB_PAGERIGHT)
{
x += 100;
rc.left = 100;
}
if(code == SB_THUMBTRACK)
x = pos;
SetScrollPos(hWnd, SB_HORZ, x, TRUE);
// ScrollWindow(hWnd, x, 0, NULL, NULL);


InvalidateRect(hWnd, NULL, TRUE);
}

void OnVScroll(HWND hWnd, HWND hWndCtl, UINT code, int pos)
{
int y;
y = GetScrollPos(hWnd, SB_VERT);
if(code == SB_LINEUP)
y -= 10;
if(code == SB_LINEDOWN)
y += 10;
if(code == SB_PAGEUP)
y -= 100;
if(code == SB_PAGEDOWN)
y += 100;
if(code == SB_THUMBTRACK)
y = pos;

SetScrollPos(hWnd, SB_VERT, y, TRUE);
InvalidateRect(hWnd, NULL, TRUE);
}

boman258 2005-02-24
  • 打赏
  • 举报
回复
当然要维护了,不然要他干嘛
思危 2005-02-24
  • 打赏
  • 举报
回复
支持到什么程度。
显示CScrollBar很简单,但要是对其进行自动维护,CWnd是不行的,否则还要CScrollView干嘛
sjcode 2005-02-24
  • 打赏
  • 举报
回复
在CreateWindow里的style里加WS_VSCROLL
快乐鹦鹉 2005-02-24
  • 打赏
  • 举报
回复
缺省应该是支持滚动的
快乐鹦鹉 2005-02-24
  • 打赏
  • 举报
回复
CWnd控件????CWnd是窗口类吧

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧