如何用VC++6.0的SDK写一个简单的文本编辑器

cooldog1982 2005-01-09 09:33:12
如何用VC++6.0的SDK写一个简单的文本编辑器啊,请各位人兄帮帮忙,谢了!
...全文
211 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
alanblack 2005-01-10
  • 打赏
  • 举报
回复




case WM_SETFOCUS:

// create and show the caret

CreateCaret (hwnd, NULL, cxChar, cyChar) ;

SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;

ShowCaret (hwnd) ;

return 0 ;



case WM_KILLFOCUS:

// hide and destroy the caret

HideCaret (hwnd) ;

DestroyCaret () ;

return 0 ;



case WM_KEYDOWN:

switch (wParam)

{

case VK_HOME:

xCaret = 0 ;

break ;



case VK_END:

xCaret = cxBuffer - 1 ;

break ;



case VK_PRIOR:

yCaret = 0 ;

break ;



case VK_NEXT:

yCaret = cyBuffer - 1 ;

break ;



case VK_LEFT:

xCaret = max (xCaret - 1, 0) ;

break ;



case VK_RIGHT:

xCaret = min (xCaret + 1, cxBuffer - 1) ;

break ;



case VK_UP:

yCaret = max (yCaret - 1, 0) ;

break ;



case VK_DOWN:

yCaret = min (yCaret + 1, cyBuffer - 1) ;

break ;
alanblack 2005-01-10
  • 打赏
  • 举报
回复
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)

{

static DWORD dwCharSet = DEFAULT_CHARSET ;

static int cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer,

xCaret, yCaret ;

static TCHAR *pBuffer = NULL ;

HDC hdc ;

int x, y, i ;

PAINTSTRUCT ps ;

TEXTMETRIC tm ;



switch (message)

{

case WM_INPUTLANGCHANGE:

dwCharSet = wParam ;

// fall through

case WM_CREATE:

hdc = GetDC (hwnd) ;

SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,

dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;



GetTextMetrics (hdc, &tm) ;

cxChar = tm.tmAveCharWidth ;

cyChar = tm.tmHeight ;



DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;

ReleaseDC (hwnd, hdc) ;

// fall through

case WM_SIZE:

// obtain window size in pixels


if (message == WM_SIZE)

{

cxClient = LOWORD (lParam) ;

cyClient = HIWORD (lParam) ;

}

// calculate window size in characters



cxBuffer = max (1, cxClient / cxChar) ;

cyBuffer = max (1, cyClient / cyChar) ;



// allocate memory for buffer and clear it



if (pBuffer != NULL)

free (pBuffer) ;


pBuffer = (TCHAR *) malloc (cxBuffer * cyBuffer * sizeof (TCHAR)) ;



for (y = 0 ; y < cyBuffer ; y++)

for (x = 0 ; x < cxBuffer ; x++)

BUFFER(x,y) = ' ' ;


// set caret to upper left corner


xCaret = 0 ;

yCaret = 0 ;



if (hwnd == GetFocus ())

SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;


InvalidateRect (hwnd, NULL, TRUE) ;

return 0 ;

alanblack 2005-01-10
  • 打赏
  • 举报
回复
来自《Programming Windows》

#include <windows.h>


#define BUFFER(x,y) *(pBuffer + y * cxBuffer + x)


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

static TCHAR szAppName[] = TEXT ("Typer") ;

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 ("This program requires Windows NT!"),

szAppName, MB_ICONERROR) ;

return 0 ;

}

hwnd = CreateWindow (szAppName, TEXT ("Typing Program"),

WS_OVERLAPPEDWINDOW,

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 ;

}

2,586

社区成员

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

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