📄 mian.cpp
字号:
{ case TTN_NEEDTEXT:
{
LPTOOLTIPTEXT lpToolTipText;
char szBuf[MAX_PATH];
// Display the ToolTip text.
lpToolTipText = (LPTOOLTIPTEXT)lParam;
LoadString (Instance, lpToolTipText->hdr.idFrom, szBuf, sizeof (szBuf));
// string ID == cmd ID
// SendMessage(StatusBar, SB_SETTEXT, 0, (LPARAM)szBuf);
lpToolTipText->lpszText = szBuf;
//SendMessage(StatusBar, SB_SETTEXT, 0, (LPARAM)"彬彬的例子");
break;
}
case TBN_QUERYINSERT:
case TBN_QUERYDELETE:
lptbn = (LPTBNOTIFY)lParam;
nItem = lptbn->iItem;
return TRUE;//全部可以删
return (nItem == 0)? FALSE : TRUE;//第一个不能删
break;
case TBN_TOOLBARCHANGE: /* Done dragging a bitmap to the toolbar. */
SendMessage(hWinToolbar, TB_AUTOSIZE, 0L, 0L);
break;
case TBN_GETBUTTONINFO:
lptbn = (LPTBNOTIFY)lParam;
nItem = lptbn->iItem;
lptbn->tbButton.iBitmap = tbButtons[nItem].iBitmap;
lptbn->tbButton.idCommand = tbButtons[nItem].idCommand;
lptbn->tbButton.fsState = tbButtons[nItem].fsState;
lptbn->tbButton.fsStyle = tbButtons[nItem].fsStyle;
lptbn->tbButton.dwData = tbButtons[nItem].dwData;
lptbn->tbButton.iString = tbButtons[nItem].iString;
return((nItem<sizeof(tbButtons)/sizeof(tbButtons[0]))? TRUE : FALSE);
break;
case TBN_RESET:
int i, b;
b = SendMessage(hWinToolbar, TB_BUTTONCOUNT, 0, 0);
for (i = 0; i < b; i++)
SendMessage(hWinToolbar, TB_DELETEBUTTON, 0, 0);
SendMessage(hWinToolbar, TB_ADDBUTTONS, 12, (LPARAM)tbButtons);
break;
case TBN_CUSTHELP: /* Need to display custom help. */
MessageBox (hWnd, "This help is custom.", "系统提示", MB_OK);
break;
default:
break;
}
}
return FALSE;
}
void OpenStrFile(HWND hWnd,HWND hTree)
{
OPENFILENAME OpenFileName;
char szDirName[MAX_PATH]="";
char szFile[MAX_PATH]="\0";
char szFileTitle [MAX_PATH]="\0";
// OPENFILENAME 结构的过滤器规格说明。
// char szFilter[]={"ctr文件(*.ctr)\0*.ctr\0文本文件(*.txt)\0*.txt\0所有文件\0*.*\0"};
char szFilter[]={"ctr文件(*.ctr)\0*.ctr\0"};
OpenFileName.lStructSize=sizeof(OPENFILENAME);
OpenFileName.hwndOwner=hWnd;
OpenFileName.hInstance=Instance;
OpenFileName.lpstrFilter=szFilter;
OpenFileName.lpstrCustomFilter=(LPTSTR)NULL;
OpenFileName.nMaxCustFilter=0L;
OpenFileName.nFilterIndex=1L;
OpenFileName.lpstrFile=szFile;
OpenFileName.nMaxFile=sizeof(szFile);
OpenFileName.lpstrFileTitle=szFileTitle;
OpenFileName.nMaxFileTitle=sizeof(szFileTitle);
OpenFileName.lpstrInitialDir=NULL;
OpenFileName.lpstrTitle="请选取一个文本文件";
OpenFileName.nFileOffset=0;
OpenFileName.nFileExtension=0;
OpenFileName.lpstrDefExt="*.txt";
OpenFileName.lCustData=0;
OpenFileName.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
if(GetOpenFileName(&OpenFileName))
{
AddStr(hTree,OpenFileName.lpstrFile);
/*
HANDLE hFile;
DWORD dwFileSize,dwBytesRead;
char * lpBufPtr;
// 打开指定的文件。
hFile=CreateFile
(
OpenFileName.lpstrFile,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE)NULL
);
if(hFile!=INVALID_HANDLE_VALUE)
{
//检取文件字节大小。
dwFileSize=GetFileSize(hFile,NULL);
if(dwFileSize!=0xFFFFFFFF)
{
// 分配用来读入文件的缓冲区。
lpBufPtr=(char *)malloc(dwFileSize);
if(lpBufPtr!=NULL)
{
// 把文件内容读入缓冲区。
ReadFile(hFile,(LPVOID)lpBufPtr,dwFileSize,&dwBytesRead,NULL);
if (dwBytesRead!=0)
{
//把文件内容装入多行编辑控件中,
SendMessage(hWndEdit,WM_SETTEXT,0,(LPARAM)lpBufPtr);
SetWindowText(hWnd,OpenFileName.lpstrFile);
}
else
MessageBox (hWnd,"读入字节数为零。",NULL,MB_OK|MB_ICONEXCLAMATION);
free(lpBufPtr);
}
else
MessageBox(NULL,"内存分配失败!",NULL,MB_OK|MB_ICONEXCLAMATION);
}
else
MessageBox(NULL,"检取文件大小失败",NULL,MB_OK|MB_ICONEXCLAMATION);
CloseHandle(hFile) ;
}
else
MessageBox(hWnd, "打开文件失败",NULL,MB_OK|MB_ICONEXCLAMATION);
*/ }
}
int CALLBACK WndProc(HWND hWnd, unsigned wMessage,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
// TCHAR nodeStr[10]= {0};
// wsprintf(nodeStr,"%d",lf.lfHeight);
switch (wMessage)
{
HANDLE_MSG(hWnd, WM_DESTROY, Cls_OnDestroy);
HANDLE_MSG(hWnd, WM_CREATE, Cls_OnCreate);
/* case WM_CREATE:
CenterWindow(hWnd);
//CreateRebar(hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;*/
// case WM_INITDIALOG:
// return (DefWindowProc(hWnd, wMessage, wParam, lParam));
case WM_COMMAND:
HTREEITEM htrNext;
switch (LOWORD(wParam)) //接受消息循环的函数,采用switch 处理各种消息
{
case IDM_PRVPAGE:
ScrollCheck=FALSE;
KillTimer(hStr,ID_TIMER);
htrNext=TreeView_GetNextItem(hTree,TreeView_GetSelection(hTree),TVGN_PREVIOUS);
if(htrNext)
{
TreeView_Expand(hTree,htrNext,TVE_EXPAND);
TreeView_SelectItem(hTree,htrNext);
}
break;
case IDM_NEXTPAGE:
ScrollCheck=FALSE;
KillTimer(hStr,ID_TIMER);
htrNext=TreeView_GetNextItem(hTree,TreeView_GetSelection(hTree),TVGN_NEXT);
if(htrNext)
{
TreeView_Expand(hTree,htrNext,TVE_EXPAND);
TreeView_SelectItem(hTree,htrNext);
}
break;
case IDM_FILEOPEN:
OpenStrFile(hWnd,hTree);
break;
case IDM_ZOOMIN:
if(lf.lfHeight>=4)
{
lf.lfHeight-=4;
g_hfFont = CreateFontIndirect(&lf);
SetScrollLength();
PrintStr();
}
break;
case IDM_ZOOMOUT:
// SetWindowText(hWnd,nodeStr);
if(lf.lfHeight<0)
lf.lfHeight=-lf.lfHeight;
if(lf.lfHeight<=40)
{
lf.lfHeight+=4;
g_hfFont = CreateFontIndirect(&lf);
SetScrollLength();
PrintStr();
}
break;
case IDM_FONT:
CHOOSEFONT fnt;
fnt.lStructSize = sizeof(CHOOSEFONT);
fnt.hwndOwner = hWnd;
fnt.hDC = NULL;
fnt.lpLogFont = &lf;
fnt.Flags = CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS|CF_EFFECTS;
fnt.rgbColors = fgcolor;//RGB(0,255,255);
fnt.lCustData = 0L;
fnt.nFontType = SCREEN_FONTTYPE;
fnt.nSizeMin = 0;
fnt.nSizeMax = 0;
if(ChooseFont(&fnt))
{
g_hfFont = CreateFontIndirect(&lf);
// SetWindowText(hWnd,nodeStr);
if(g_hfFont)
{
fgcolor=fnt.rgbColors;
SetScrollLength();
PrintStr();
}
/* HFONT hf = CreateFontIndirect(&lf);
if(hf)
{
g_hfFont = hf;
//MessageBox(hWnd,"","",MB_OK);
SetScrollLength();
PrintStr();
}
// DeleteObject(hf);*/
}
break;
case IDM_BGCOLOR:
CHOOSECOLOR info;
memset(&info,0,sizeof(info));
//將資料結構先歸零
info.lStructSize=sizeof(info);
info.lpCustColors=colors;
info.hwndOwner=hWnd;
if(ChooseColor(&info)==TRUE){
bgcolor = info.rgbResult; //取得顏色
InvalidateRect(hWnd, NULL, TRUE);
//更新畫面
}
break;
case IDM_EXIT:
delete MySTRTree;
DeleteObject(g_hfFont);
DestroyMenu(hMenu);
DestroyMenu(hRMenu);
PostQuitMessage(0);
break;
case IDM_ABOUT:
MessageBox(hWnd,"迷你阅读器 version 1.0 \n\n\t老彬工作室\t \n","关于",64);
break;
}
DeleteObject(htrNext);
break;
case WM_SYSCOMMAND:
switch (LOWORD(wParam)) //接受消息循环的函数,采用switch 处理各种消息
{
case IDM_ABOUT:
MessageBox(hWnd,"迷你阅读器 version 1.0 \n\n\t老彬工作室\t \n","关于",64);
break;
default:
return DefWindowProc (hWnd, wMessage, wParam, lParam);
}
break;
case WM_NOTIFY:
return DoNotify(hWnd, wParam, lParam);
case WM_ERASEBKGND:
//PrintStr();
FillBar(hWnd);
break;
case WM_PAINT:
hdc = BeginPaint (hWnd, &ps);
FillBar(hWnd);
/* HDC hStrDC=GetDC(hStr);
TextOut(hStrDC,0,0,TEXT("ok"),2);
SetBkColor( hStrDC, RGB(0,0,0));
SetTextColor(hStrDC, RGB(255,255,255));
ReleaseDC(hStr,hStrDC);*/
// PrintStr();
// EndPaint (hWnd, &ps);
break;
//return 0;
case WM_LBUTTONDOWN:
split=TRUE;
SetCapture(hWnd);
return 0;
case WM_MOUSEMOVE:
Splitter(hWnd,lParam);
// TCHAR nodeStr[10]= {0};
// wsprintf(nodeStr,"%d",numline);
// MessageBox(hStr,nodeStr,"",MB_OK);
// SetWindowText(hWnd,nodeStr);
return 0;
case WM_LBUTTONUP:
split=FALSE;
ReleaseCapture();
return 0;
case WM_SIZE:
// MoveTree(hWnd);
//MoveRebar(hWnd);
// SendMessage(hWinToolbar,TB_AUTOSIZE,0,0);
Resizer(hWnd,lParam);
// SetScrollLength();
//SendMessage(hStr,WM_PAINT,0,0);
InvalidateRect(hWnd,NULL,FALSE);
return 0;
default:
return DefWindowProc (hWnd, wMessage, wParam, lParam);
}
return (0);// return (DefWindowProc(hWnd, wMessage, wParam, lParam));
}
HWND InitWindow(void)
{
WNDCLASS wndclass;
HWND hWnd;
RECT rc;
int xMaxAppWindow;
int yMaxAppWindow;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC) WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = Instance;
wndclass.hIcon = LoadIcon (Instance, MAKEINTRESOURCE(IDI_MAIN));//NULL;
wndclass.hCursor = LoadCursor (NULL, IDC_SIZEWE);//IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);//COLOR_APPWORKSPACE+1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szClassName;
if (!RegisterClass (&wndclass)) return NULL;
SystemParametersInfo(SPI_GETWORKAREA,0,&rc,0);
xMaxAppWindow=(rc.right-rc.left)*3/4;
yMaxAppWindow=(rc.bottom-rc.top)*2/3;
/* Create the app. window */
hWnd = CreateWindowEx(0,
szClassName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
xMaxAppWindow,
yMaxAppWindow,
NULL,
hMenu,
Instance,
NULL);
hSysMenu=GetSystemMenu(hWnd,FALSE);
AppendMenu(hSysMenu,MF_SEPARATOR,0,NULL);
AppendMenu(hSysMenu,0,IDM_ABOUT,szMenuAbout);
return hWnd;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int nCmdShow)
{
MSG msg;
HWND hWnd;
Instance = hInstance;
hMenu=LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
if((hWnd=InitWindow())==NULL) return FALSE;
ShowWindow (hWnd, nCmdShow);
if(szCmdLine!=NULL && szCmdLine[0]!='\0')
{
int cmdlinelen;
int n=0;
cmdlinelen=strlen(szCmdLine);
char *szShare=NULL;
char lpCmdLine[256];
if(strncmp(szCmdLine,"\"",1)==0) {
szShare=szCmdLine+1;
while ((*szShare)!='\"')
{
lpCmdLine[n++]=*szShare;
szShare++;
}
lpCmdLine[n]='\0';
AddStr(hTree,lpCmdLine);
}
else
AddStr(hTree,szCmdLine);
//MessageBox(hWnd,lpCmdLine,"",MB_OK);
}
/* Enter message loop */
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -