📄 memory.c
字号:
case IDBTN_MAP:
if (MapFileHandle = CreateMapFile(gszFile))
fSuccess = TRUE;
else
fSuccess = FALSE;
break;
default:
MapFileHandle = (HANDLE) 0xFFFFFFFF;
fSuccess = TRUE;
break;
}
if (fSuccess)
{
EnableMenuItem(hServerMenu, MM_OPT_1, MF_GRAYED);
EnableMenuItem(hServerMenu, MM_OPT_2, MF_ENABLED);
SetWindowText(hTextWnd,
GetStringRes(IDS_SEL_CREATE_FILE_MAPPING));
}
else
{
SetWindowText(hTextWnd,
GetStringRes (IDS_ERR_MAPFILE_FAILED));
}
return 0L;
}
case MM_OPT_2:
{ //Create File Mapping
// This option should be disabled until MM_OPT_1 has been chosen.
SetWindowText(hTextWnd,
GetStringRes(IDS_CREATE_MAPPING));
if (MapFileHandle)
switch (DialogBox(ghModule, "MapName", hwnd, (DLGPROC)MapFileName))
{
case IDBTN_OK:
if (hMem1 = CreateMap(MapFileHandle, gszMapName))
fSuccess = TRUE;
else
fSuccess = FALSE;
break;
default:
fSuccess = FALSE;
break;
}
else
fSuccess = FALSE;
if (fSuccess)
{
EnableMenuItem(hServerMenu, MM_OPT_2, MF_GRAYED);
EnableMenuItem(hServerMenu, MM_OPT_3, MF_ENABLED);
SetWindowText(hTextWnd,
GetStringRes (IDS_SEL_MAP_VIEW));
}
else
{
SetWindowText(hTextWnd,
GetStringRes (IDS_ERR_MAPPING_FAILED));
}
return 0L;
}
case MM_OPT_3:
{ //Map View of File
SetWindowText(hTextWnd, GetStringRes (IDS_MAPPING_VIEW));
if (hMem1 && (pShrMem1 = (LPVOID)MapView(hMem1)))
{
EnableMenuItem(hServerMenu, MM_OPT_3, MF_GRAYED);
EnableMenuItem(hServerMenu, MM_OPT_4, MF_ENABLED);
SetWindowText(hTextWnd, GetStringRes (IDS_SEL_ACCESS));
}
else
{
SetWindowText(hTextWnd, GetStringRes(IDS_ERR_MAPVIEW_FAILED));
}
return 0L;
}
case MM_OPT_4:
{ //Access
RECT rcl;
SetWindowText(hTextWnd,
GetStringRes (IDS_ACCESSING_SERVER_WRITE));
if (pShrMem1)
{
GetClientRect(hwnd, &rcl);
hEdit = CreateWindow("edit", (LPSTR) NULL,
WS_CHILD | WS_VISIBLE |
WS_HSCROLL | WS_VSCROLL |
WS_BORDER | ES_LEFT |
ES_MULTILINE | ES_AUTOHSCROLL |
ES_AUTOVSCROLL,
0,0, rcl.right - rcl.left,
rcl.bottom - rcl.top -
GetWindowLong(hTextWnd, GWL_USERDATA),
hwnd, (HMENU)1, ghModule, (LPVOID)NULL);
if (hEdit)
{
EnableMenuItem(hServerMenu, MM_OPT_4, MF_GRAYED);
SetFocus(hEdit);
fSuccess = TRUE;
}
else
fSuccess = FALSE;
}
else
fSuccess = FALSE;
if (!fSuccess)
{
MessageBox(ghwndMain,
GetStringRes(IDS_ERR_ACCESS_WRITE_FAILED),
NULL, MB_OK);
SetWindowText(hTextWnd,
GetStringRes (IDS_ERR_ACCESS_WRITE_FAILED));
}
return 0L;
}
} // End of switch (LOWORD(wParam))
switch (HIWORD(wParam))
{
case EN_UPDATE:
{
if (hEdit && (hEdit == (HWND)lParam))
{
bDirty = TRUE;
}
return 0L;
}
}
}
case WM_TIMER:
if (bDirty && IsWindow(hEdit))
{
int iCnt;
iCnt = SendMessage(hEdit, WM_GETTEXT, (WPARAM)4000, (LPARAM)pShrMem1);
if (iCnt)
{
bDirty = FALSE;
}
}
return 0L;
case WM_MDIACTIVATE:
if ((HWND) lParam == hwnd)
{
SendMessage(GetParent(hwnd), WM_MDISETMENU,
(DWORD) hServerMenu,
(LONG) hServerMenuWindow) ;
DrawMenuBar(GetParent(GetParent(hwnd))) ;
}
return 0;
case WM_SIZE:
if (hEdit)
MoveWindow(hEdit, 0, 0,
LOWORD(lParam),
HIWORD(lParam)-GetWindowLong(hTextWnd, GWL_USERDATA),
TRUE);
MoveWindow(hTextWnd, 0,
HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
LOWORD(lParam),
HIWORD(lParam), TRUE);
return DefMDIChildProc(hwnd, message, wParam, lParam);
case WM_CREATE:
{
PPERWNDINFO pWndInfo;
PNODE pHead;
HANDLE hHead, hTmp;
RECT rect;
GetClientRect(hwnd, &rect);
hTextWnd = CreateWindow("Text", NULL,
WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
hwnd,
(HMENU) 2,
ghModule,
NULL);
EnableMenuItem(hServerMenu, MM_OPT_1, MF_ENABLED);
SetWindowText(hTextWnd, GetStringRes (IDS_SEL_CREATE_FILE));
// now find match
hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
if (hHead && (pHead = (PNODE)LocalLock(hHead)))
{
while ((pHead->ChildWnd.hThisWnd != hwnd) && (pHead->hNext))
{
hTmp = hHead;
hHead = pHead->hNext;
LocalUnlock(hTmp);
pHead = (PNODE)LocalLock(hHead);
}
if (pHead->ChildWnd.hThisWnd == hwnd)
{
pWndInfo = &pHead->ChildWnd;
GetClientRect(pWndInfo->hThisWnd, &pWndInfo->rcClient);
}
LocalUnlock(hHead);
}
return DefMDIChildProc(hwnd, message, wParam, lParam);
}
case WM_CLOSE:
{
PPERWNDINFO pWndInfo;
PNODE pHead, pTrail;
HANDLE hHead, hTmp;
EnableMenuItem(hServerMenu, MM_OPT_2, MF_GRAYED);
EnableMenuItem(hServerMenu, MM_OPT_3, MF_GRAYED);
EnableMenuItem(hServerMenu, MM_OPT_4, MF_GRAYED);
SendMessage(GetParent(hwnd), WM_MDISETMENU, (DWORD)hMenu, (LONG)hMenuWindow);
DrawMenuBar(GetParent(GetParent(hwnd))) ;
// Unmap view, close mapping and file!
if (pShrMem1)
{
UnmapViewOfFile (pShrMem1);
pShrMem1 = NULL;
}
if (hMem1)
{
CloseHandle (hMem1);
hMem1 = NULL;
}
if (MapFileHandle && MapFileHandle != INVALID_HANDLE_VALUE)
{
CloseHandle (MapFileHandle);
MapFileHandle = NULL;
}
// now find match
hHead = (HANDLE) GetWindowLong(ghwndMain, 0);
if ((hHead) && (pHead = (PNODE)LocalLock(hHead)))
{
pTrail = pHead;
while ((pHead->ChildWnd.hThisWnd != hwnd) && (pHead->hNext))
{
hTmp = hHead;
pTrail = pHead;
hHead = pHead->hNext;
LocalUnlock(hTmp);
pHead = (PNODE) LocalLock(hHead);
}
if (pHead->ChildWnd.hThisWnd == hwnd)
{
pWndInfo = &pHead->ChildWnd;
if (pTrail == pHead)
SetWindowLong(ghwndMain, 0, (LONG) pHead->hNext);
else
pTrail->hNext = pHead->hNext;
LocalUnlock(hHead);
LocalFree(hHead);
}
else
{
LocalUnlock(hHead);
}
}
return DefMDIChildProc(hwnd, message, wParam, lParam);
}
case WM_DESTROY:
KillTimer(hwnd, 1);
return 0L;
case WM_PAINT:
return DefMDIChildProc(hwnd, message, wParam, lParam);
default:
return DefMDIChildProc(hwnd, message, wParam, lParam);
}
}
/***************************************************************************\
* ClientWndProc
*
\***************************************************************************/
long APIENTRY ClientWndProc( HWND hwnd,
UINT message,
DWORD wParam,
LONG lParam)
{
static HANDLE hMem1 = NULL;
static LPVOID pShrMem1 = NULL;
static HANDLE hEdit;
static HANDLE hTextWnd;
BOOL fSuccess = FALSE;
switch (message)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case MM_OPT_5:
{ //Open File Mapping
SetWindowText(hTextWnd, GetStringRes (IDS_OPENING_FILE));
switch (DialogBox(ghModule, "MapName", hwnd, (DLGPROC)MapFileName))
{
case IDBTN_OK:
if (hMem1 = OpenMap(gszMapName))
fSuccess = TRUE;
else
fSuccess = FALSE;
break;
default:
fSuccess = FALSE;
break;
}
if (fSuccess)
{
EnableMenuItem(hClientMenu, MM_OPT_5, MF_GRAYED);
EnableMenuItem(hClientMenu, MM_OPT_6, MF_ENABLED);
SetWindowText(hTextWnd, GetStringRes (IDS_SEL_MAP_VIEW));
}
else
{
SetWindowText(hTextWnd,
GetStringRes (IDS_ERR_OPEN_MAPPING_FAILED));
}
return 0L;
}
case MM_OPT_6:
{ //Map View of File
SetWindowText(hTextWnd, GetStringRes (IDS_MAPPING_VIEW));
if (hMem1 && (pShrMem1 = (LPVOID) MapView(hMem1)))
{
EnableMenuItem(hClientMenu, MM_OPT_6, MF_GRAYED);
EnableMenuItem(hClientMenu, MM_OPT_7, MF_ENABLED);
SetWindowText(hTextWnd, GetStringRes (IDS_SEL_ACCESS_READ));
}
else
{
SetWindowText(hTextWnd,
GetStringRes(IDS_ERR_MAPVIEW_FAILED));
}
return 0L;
}
case MM_OPT_7:
{ //Access
RECT rcl;
SetWindowText(hTextWnd,
GetStringRes(IDS_ACCESSING_SERVER_READ));
fSuccess = FALSE; // assume failure.
if (pShrMem1)
{
GetClientRect(hwnd, &rcl);
hEdit = CreateWindow("edit", NULL,
WS_CHILD | WS_VISIBLE |
WS_HSCROLL | WS_VSCROLL |
WS_BORDER | ES_LEFT |
ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY | ES_AUTOVSCROLL,
0,0, rcl.right-rcl.left,
rcl.bottom-rcl.top-GetWindowLong(hTextWnd, GWL_USERDATA),
hwnd, (HMENU) 1, ghModule, NULL);
if (hEdit)
{
SetFocus(hEdit);
fSuccess = TRUE;
}
}
if (fSuccess)
{
SendMessage(hEdit, WM_SETTEXT, 0L, (LONG)pShrMem1);
SetTimer(hwnd, 2, 1000, NULL);
EnableMenuItem(hClientMenu, MM_OPT_7, MF_GRAYED);
EnableMenuItem(hClientMenu, MM_OPT_8, MF_ENABLED);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -