|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大佬帮忙 帮我讲讲好么 谢谢了
#include <windows.h>
#include <strsafe.h>
#include "symets.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstcance, PSTR lpCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
//窗口类名
WCHAR szClassName[] = TEXT("FristWindow");
//初始化窗口类
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hInstance = hInstance;
wndclass.lpszClassName = szClassName;
wndclass.lpszMenuName = NULL;
//注册窗口类
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("本程序只能在 WINDOWS NT 框架上运行!!!"), TEXT("提示信息:"), MB_OK|MB_ICONERROR);
return 0;
}
//创建窗口
hwnd = CreateWindow(szClassName, TEXT("FristWindow"), WS_OVERLAPPEDWINDOW|WS_VSCROLL, 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;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
TEXTMETRIC tm;
SCROLLINFO si;
static int xChar, yChar, xUpper;
static int xClient, yClient, yPos;
int iBeginPaint, iEndPaint;
WCHAR szBuffer[128];
switch (msg)
{
case WM_CREATE:
//获得字体大小
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
xChar = tm.tmAveCharWidth;
yChar = tm.tmHeight+tm.tmExternalLeading;
xUpper = (int)(tm.tmPitchAndFamily&1?3:2)*xChar/2;
ReleaseDC(hwnd, hdc);
break;
case WM_SIZE:
//获取客户区大小
xClient = LOWORD(lParam);
yClient = HIWORD(lParam);
//设置垂直滚动条信息
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
si.nPage = yClient / yChar;
si.nMax = NUMLINES - 1;
si.nMin = 0;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
yPos = si.nPos;
iBeginPaint = max(0, yPos + ps.rcPaint.top / yChar);
iEndPaint = min(NUMLINES, yPos + ps.rcPaint.bottom / yChar);
for (int i = iBeginPaint; i < iEndPaint; i++)
{
TextOut(hdc, 50*xUpper,(i-yPos)*yChar,sysmetrics[i].szLabel,lstrlen(sysmetrics[i].szLabel));
}
EndPaint(hwnd, &ps);
break;
case WM_VSCROLL:
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwnd, SB_VERT, &si);
yPos = si.nPos;
switch (LOWORD(wParam))
{
case SB_LINEUP:
si.nPos -= 1;
break;
case SB_LINEDOWN:
si.nPos += 1;
break;
case SB_PAGEUP:
si.nPos -= si.nPage;
break;
case SB_PAGEDOWN:
si.nPos += si.nPage;
break;
case SB_THUMBPOSITION:
si.nPos = si.nTrackPos;
break;
}
si.fMask = SIF_POS;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
GetScrollInfo(hwnd, SB_VERT, &si);
if (yPos != si.nPos)
{
ScrollWindow(hwnd, 0, yChar*(yPos - si.nPos), NULL, NULL);
UpdateWindow(hwnd);
}
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
|
|