📄 wndproc.c
字号:
hPatternSelectDlg = CreateDialog(hInst, "PATTERN", hWnd, lpfnPatternSelect); WinAssert(hPatternSelectDlg); } break; case IDM_CLEAR_STATUS: /* forward to status window */ SendMessage(hWndEdit, WM_COMMAND, IDM_CLEAR_STATUS, 0L); break; case IDM_EDIT_SAVE_AS: { OFSTRUCT ofs; char szFilename[PATH_MAX] = ""; char *p;#ifdef WIN32 DWORD bytes_written; HANDLE hFile;#else HFILE hFile;#endif memset(&ofnTemp, 0, sizeof (ofnTemp)); memset(&ofs, 0, sizeof(ofs)); GetWindowText(hWndStatic, szFilename, PATH_MAX); for (p = szFilename; *p; p++) if (*p == '/') *p = '\\'; ofnTemp.lStructSize = sizeof (ofnTemp); ofnTemp.hwndOwner = hWndMain; ofnTemp.hInstance = hInst; ofnTemp.lpstrFilter = "All Files (*.*)\0*.*\0\0"; ofnTemp.nFilterIndex = 1; ofnTemp.lpstrFile = szFilename; ofnTemp.nMaxFile = PATH_MAX; ofnTemp.lpstrInitialDir = NULL; ofnTemp.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (GetSaveFileName (&ofnTemp)) { unsigned int txtlen; txtlen = (unsigned int)SendMessage(hWndEdit, WM_GETTEXTLENGTH, 0, 0); if (txtlen != 0) txtlen++; SendMessage(hWndEdit, WM_GETTEXT, txtlen, (LPARAM)pszBuffer);#ifndef WIN32 hFile = OpenFile(szFilename, &ofs, OF_CREATE); _lwrite (hFile, pszBuffer, lstrlen(pszBuffer)); _lclose (hFile);#else hFile = CreateFile(szFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(hFile, pszBuffer, lstrlen(pszBuffer), &bytes_written,NULL); CloseHandle(hFile);#endif SetWindowText(hWndStatic, szFilename); } } break; case IDM_EDIT_OPEN_FILE: { OFSTRUCT ofs; char szFilename[PATH_MAX] = "";#ifdef WIN32 DWORD bytes_written, dwSize; HANDLE hFile;#else HFILE hFile;#endif memset(&ofnTemp, 0, sizeof (ofnTemp)); memset(&ofs, 0, sizeof(ofs)); ofnTemp.lStructSize = sizeof (ofnTemp); ofnTemp.hwndOwner = hWndMain; ofnTemp.hInstance = hInst; ofnTemp.lpstrFilter = "All Files (*.*)\0*.*\0\0"; ofnTemp.nFilterIndex = 1; ofnTemp.lpstrFile = szFilename; ofnTemp.nMaxFile = PATH_MAX; ofnTemp.lpstrInitialDir = NULL; ofnTemp.Flags = OFN_FILEMUSTEXIST; if (GetOpenFileName (&ofnTemp)) { extern BOOL MapCRtoCRLF(LPSTR); SendMessage(hWndEdit, WM_COMMAND, IDM_CLEAR_STATUS, 0L);#ifndef WIN32 hFile = OpenFile(szFilename, &ofs, OF_READ); _lread (hFile, pszBuffer, (UINT)EDIT_BUF_SIZE); _lclose (hFile);#else hFile = CreateFile(szFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL); dwSize = GetFileSize(hFile, NULL); if (dwSize >= (dwEditBufSize - 1)) { HGLOBAL hTemp; GlobalUnlock(hEditor); hTemp = GlobalReAlloc(hEditor, dwSize + 0x1000, GMEM_MOVEABLE|GMEM_ZEROINIT); if (hTemp) { hEditor = hTemp; dwEditBufSize = dwSize + 0x1000; } else MessageBox(hWndMain, "Cannot allocate enough memory for file. Truncating file.", "Insufficient Memory", MB_ICONINFORMATION|MB_OK); pszBuffer = GlobalLock(hEditor); memset(pszBuffer, '\0', dwEditBufSize); } ReadFile(hFile, pszBuffer, dwSize, &bytes_written, NULL); CloseHandle(hFile);#endif /* Convert CR to CRLF and strip formfeeds */ MapCRtoCRLF(pszBuffer); SendMessage(hWndEdit, WM_SETTEXT, 0, (LPARAM)pszBuffer); SetWindowText(hWndStatic, szFilename); UpdateWindow(hWndEdit); } } break; case IDM_MAX_STATUS: { SendMessage(hStatusButton, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(5,5) ); break; } case IDM_SETFOCUS_ON_STATUS: /* posted from Action() following extract-to-Status */ SetFocus(hWndEdit); /* set focus on Status so user can scroll */ break; case IDM_ZIP_STATS: { char szCompFactor[10]; char sgn; char CompFactorStr[] = "%c%d%%"; char CompFactor100[] = "100%%"; if (lpumb->szFileName[0]) /* if file selected */ { if (lpUserFunctions->TotalSizeComp > lpUserFunctions->TotalSize) sgn = '-'; else sgn = ' '; if (lpUserFunctions->CompFactor == 100) sprintf(szCompFactor, CompFactor100); else sprintf(szCompFactor, CompFactorStr, sgn, lpUserFunctions->CompFactor); wsprintf(szTotalsLine, "Total Size\t\t%7lu\nCompressed Size\t%7lu\nRatio\t\t%6s\nTotal Files\t%7u", lpUserFunctions->TotalSize, lpUserFunctions->TotalSizeComp, szCompFactor, lpUserFunctions->NumMembers); MessageBox(hWndMain, szTotalsLine, lpumb->szFileName, MB_ICONINFORMATION | MB_OK); } } break; default: return DefWindowProc(hWnd, wMessage, wParam, lParam); } } /* bottom of not in help mode */ break; case WM_SETCURSOR: /* In help mode it is necessary to reset the cursor in response */ /* to every WM_SETCURSOR message.Otherwise, by default, Windows */ /* will reset the cursor to that of the window class. */ if (uf.fHelp) { SetCursor(hHelpCursor); break; } return DefWindowProc(hWnd, wMessage, wParam, lParam); case WM_INITMENU: if (uf.fHelp) { SetCursor(hHelpCursor); } return TRUE; case WM_ENTERIDLE: if ((LOWORD(wParam) == MSGF_MENU) && (GetKeyState(VK_F1) & 0x8000)) { uf.fHelp = TRUE; PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0L); } break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: if ( uf.fCanDragDrop ) DragAcceptFiles( hWnd, FALSE ); DeleteObject(hBrush); WinHelp(hWnd, szHelpFileName, HELP_QUIT, 0L); PostQuitMessage(0); break; case WM_DROPFILES: { WORD cFiles; /* Get the number of files that have been dropped */ cFiles = (WORD)DragQueryFile( (HDROP)wParam, (UINT)-1, lpumb->szBuffer, (UINT)256); /* Only handle one dropped file until MDI-ness happens */ if (cFiles == 1) { RECT rClient; DragQueryFile( (HDROP)wParam, 0, lpumb->szFileName, PATH_MAX); GetArchiveDir(lpumb->szDirName); /* get archive dir name */ if (uf.fUnzipToZipDir || /* unzipping to same directory as archive */ szUnzipToDirName[0] == '\0') /* or no default */ { /* strip off filename to make directory name */ lstrcpy(szUnzipToDirName, lpumb->szDirName); } lstrcpy(lpumb->szBuffer, lpumb->szDirName); /* get scratch copy */ DlgDirList (hWnd, lpumb->szBuffer, 0, 0, 0); /* change dir */ UpdateListBox(); /* fill in list box */#ifndef WIN32 SendMessage(hWndList, LB_SETSEL, 1, 0L);#else ListViewSetSel(0, TRUE);#endif UpdateButtons(); /* update state of buttons */ WinAssert(hWndList); GetClientRect( hWndList, &rClient ); OffsetRect( &rClient, 0, dyChar ); rClient.top = rClient.bottom; rClient.bottom = rClient.top + (2*dyChar); InvalidateRect( hWnd, &rClient, TRUE); SetCaption(hWnd); } DragFinish( (HDROP)wParam ); } break;#ifndef WIN32 case WM_PAINT: { PAINTSTRUCT ps; RECT rClient; DWORD dwBackColor; char szCompFactor[10]; char sgn; char CompFactorStr[] = "%c%d%%"; char CompFactor100[] = "100%%"; hDC = BeginPaint( hWnd, &ps ); if ( hDC ) { WinAssert(hWndList); UpdateWindow( hWndList ); hOldFont = SelectObject ( hDC, hFixedFont); WinAssert(hWnd); GetClientRect( hWnd, &rClient ); dwBackColor = SetBkColor(hDC,GetSysColor(COLOR_SCROLLBAR)); /* Move "header" down two lines for button room at top */ rClient.top = 2 * dyChar; rClient.left += dxChar/2; /* "Draw the header */ DrawText( hDC, (LPSTR)Headers[uf.fFormatLong], -1, &rClient, DT_NOPREFIX | DT_TOP); if (lpumb->szFileName[0]) /* if file selected */ { WinAssert(hWndList); GetClientRect( hWndList, &rClient ); /* Drop rectangle down 1 vertical char + 2 */ OffsetRect( &rClient, 0, dyChar+2); rClient.left += dxChar/2; /* Move totals "trailer" down two lines for button room */ rClient.top = rClient.bottom + (2 * dyChar) + (2 * GetSystemMetrics(SM_CYDLGFRAME)); rClient.bottom = rClient.top + dyChar; DrawText( hDC, (LPSTR)szTrailers[uf.fFormatLong], -1, &rClient, DT_NOPREFIX | DT_TOP); /* Display totals line at bottom of listbox */ rClient.top += dyChar; rClient.bottom += dyChar; if (lpUserFunctions->TotalSizeComp > lpUserFunctions->TotalSize) sgn = '-'; else sgn = ' '; if (lpUserFunctions->CompFactor == 100) sprintf(szCompFactor, CompFactor100); else sprintf(szCompFactor, CompFactorStr, sgn, lpUserFunctions->CompFactor); if (uf.fFormatLong) wsprintf(szTotalsLine, LongFileTrailer, lpUserFunctions->TotalSize, lpUserFunctions->TotalSizeComp, szCompFactor, lpUserFunctions->NumMembers, lpUserFunctions->NumMembers == 1 ? "":"s"); else wsprintf(szTotalsLine, ShortFileTrailer, lpUserFunctions->TotalSize, lpUserFunctions->NumMembers, lpUserFunctions->NumMembers == 1 ? "" : "s"); DrawText( hDC, szTotalsLine, -1, &rClient, DT_NOPREFIX | DT_TOP); } SetBkColor(hDC, dwBackColor); (void)SelectObject ( hDC, hOldFont); } EndPaint(hWnd, &ps); break; }#endif default: if (wMessage == uCommDlgHelpMsg) /* common dialog help message ID */ { WinHelp(hWnd, szHelpFileName, HELP_CONTEXT, dwCommDlgHelpId ); return 0; } return DefWindowProc(hWnd, wMessage, wParam, lParam); } ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -