📄 mainwnd.c
字号:
WndArr[i]->y,
WndArr[i]->Width,
WndArr[i]->Height,
TRUE);
}
CopyMemory(wndOldPos,
&wndNewPos,
sizeof(RECT));
}
}
static VOID
MainWndResetFloatingWindows(PMAIN_WND_INFO Info)
{
RECT rect;
if (GetWindowRect(Info->hMdiClient,
&rect))
{
/* tools datum */
MoveWindow(Info->fltTools->hSelf,
rect.left + 5,
rect.top + 5,
Info->fltTools->Width,
Info->fltTools->Height,
TRUE);
/* colors datum */
MoveWindow(Info->fltColors->hSelf,
rect.left + 5,
rect.bottom - Info->fltColors->Height - 5,
Info->fltColors->Width,
Info->fltColors->Height,
TRUE);
/* history datum */
MoveWindow(Info->fltHistory->hSelf,
rect.right - Info->fltHistory->Width - 5,
rect.top + 5,
Info->fltHistory->Width,
Info->fltHistory->Height,
TRUE);
}
}
static VOID
MainWndCreateFloatWindows(PMAIN_WND_INFO Info)
{
RECT rect;
HMENU hMenu;
UINT Res;
PFLT_WND WndArr[NUM_FLT_WND]; /* temp array for looping */
INT i;
Info->fltTools = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(FLT_WND));
Info->fltColors = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(FLT_WND));
Info->fltHistory = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(FLT_WND));
/* set window dimensions */
Info->fltTools->Width = 53;
Info->fltTools->Height = 300;
Info->fltColors->Width = 200;
Info->fltColors->Height = 200;
Info->fltHistory->Width = 150;
Info->fltHistory->Height = 150;
if (! GetWindowRect(Info->hMdiClient,
&rect))
{
return;
}
/* Set window datums */
Info->fltTools->x = rect.left + 5;
Info->fltTools->y = rect.top + 5;
Info->fltColors->x = rect.left + 5;
Info->fltColors->y = rect.bottom - Info->fltColors->Height - 5;
Info->fltHistory->x = rect.right - Info->fltHistory->Width - 5;
Info->fltHistory->y = rect.top + 5;
/* save pointers into array incrementing within the loop*/
WndArr[0] = Info->fltTools;
WndArr[1] = Info->fltColors;
WndArr[2] = Info->fltHistory;
for (i = 0, Res = IDS_FLT_TOOLS; Res < IDS_FLT_TOOLS + NUM_FLT_WND; Res++, i++)
{
if (! AllocAndLoadString(&WndArr[i]->lpName,
hInstance,
Res))
{
WndArr[i]->lpName = NULL;
}
WndArr[i]->hSelf = CreateWindowEx(WS_EX_TOOLWINDOW,
TEXT("ImageSoftFloatWndClass"),
WndArr[i]->lpName,
WS_POPUPWINDOW | WS_DLGFRAME | WS_VISIBLE,
WndArr[i]->x,
WndArr[i]->y,
WndArr[i]->Width,
WndArr[i]->Height,
Info->hSelf,
NULL,
hInstance,
WndArr[i]);
ShowWindow(WndArr[i]->hSelf, SW_HIDE);
}
hMenu = GetMenu(Info->hSelf);
if (Info->fltTools->hSelf != NULL)
{
if (FloatToolbarCreateToolsGui(Info))
{
CheckMenuItem(hMenu,
ID_TOOLS,
MF_CHECKED);
ShowHideWindow(Info->fltTools->hSelf);
}
}
if (Info->fltColors->hSelf != NULL)
{
if (FloatToolbarCreateColorsGui(Info))
{
}
}
if (Info->fltHistory->hSelf != NULL)
{
if (FloatToolbarCreateHistoryGui(Info))
{
}
}
}
static VOID
MainWndDestroyFloatWindows(PMAIN_WND_INFO Info)
{
if (Info->fltTools != NULL)
HeapFree(ProcessHeap, 0, Info->fltTools);
if (Info->fltColors != NULL)
HeapFree(ProcessHeap, 0, Info->fltColors);
if (Info->fltHistory != NULL)
HeapFree(ProcessHeap, 0, Info->fltHistory);
}
static const DOCKBAR_ITEM_CALLBACKS MainWndDockBarCallbacks = {
MainWndCreateToolbarClient,
MainWndDestroyToolbarClient,
MainWndToolbarInsertBand,
MainWndToolbarDockBand,
MainWndToolbarChevronPushed,
};
static VOID
CreateToolbars(PMAIN_WND_INFO Info)
{
UINT i;
for (i = 0; i < sizeof(MainDockBars) / sizeof(MainDockBars[0]); i++)
{
/* FIXME - lookup whether to display the toolbar */
TbdAddToolbar(&Info->ToolDocks,
&MainDockBars[i],
Info,
&MainWndDockBarCallbacks);
}
MainWndCreateFloatWindows(Info);
}
static VOID CALLBACK
MainWndResize(PVOID Context,
WORD cx,
WORD cy)
{
RECT rcClient = {0};
RECT rcStatus = {0};
HDWP dwp;
INT DocksVisible;
PMAIN_WND_INFO Info = (PMAIN_WND_INFO)Context;
/* Calculate the MDI client rectangle */
rcClient.right = cx;
rcClient.bottom = cy;
if (Info->hStatus != NULL)
{
GetWindowRect(Info->hStatus,
&rcStatus);
rcClient.bottom -= (rcStatus.bottom - rcStatus.top);
}
/* Adjust the client rect if docked toolbars are visible */
DocksVisible = TbdAdjustUpdateClientRect(&Info->ToolDocks,
&rcClient);
dwp = BeginDeferWindowPos(2 + DocksVisible);
if (dwp != NULL)
{
/* Update the toolbar docks */
if (DocksVisible != 0)
{
dwp = TbdDeferDocks(dwp,
&Info->ToolDocks);
if (dwp == NULL)
return;
}
/* Update the MDI client */
if (Info->hMdiClient != NULL)
{
dwp = DeferWindowPos(dwp,
Info->hMdiClient,
NULL,
rcClient.left,
rcClient.top,
rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top,
SWP_NOZORDER);
if (dwp == NULL)
return;
}
/* Update the status bar */
if (Info->hStatus != NULL)
{
dwp = DeferWindowPos(dwp,
Info->hStatus,
NULL,
0,
cy - (rcStatus.bottom - rcStatus.top),
cx,
rcStatus.bottom - rcStatus.top,
SWP_NOZORDER);
if (dwp == NULL)
return;
}
EndDeferWindowPos(dwp);
}
}
static VOID
InitMainWnd(PMAIN_WND_INFO Info)
{
CLIENTCREATESTRUCT ccs;
INT statwidths[] = {110, -1};
/* FIXME - create controls and initialize the application */
/* create the status bar */
Info->hStatus = CreateWindowEx(0,
STATUSCLASSNAME,
NULL,
WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | CCS_NOPARENTALIGN | SBARS_SIZEGRIP,
0,
0,
0,
0,
Info->hSelf,
(HMENU)IDC_STATUSBAR,
hInstance,
NULL);
if (Info->hStatus != NULL)
SendMessage(Info->hStatus,
SB_SETPARTS,
sizeof(statwidths)/sizeof(int),
(LPARAM)statwidths);
/* create the MDI client window */
ccs.hWindowMenu = GetSubMenu(GetMenu(Info->hSelf),
ID_MDI_WINDOWMENU);
ccs.idFirstChild = ID_MDI_FIRSTCHILD;
Info->hMdiClient = CreateWindowEx(WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE,
TEXT("MDICLIENT"),
NULL,
WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL,
0,
0,
0,
0,
Info->hSelf,
NULL,
hInstance,
&ccs);
TbdInitializeDocks(&Info->ToolDocks,
Info->hSelf,
Info,
MainWndResize);
CreateToolbars(Info);
/* initialize file open/save structure */
FileInitialize(Info->hSelf);
}
static VOID
MainWndCommand(PMAIN_WND_INFO Info,
WORD CmdId,
HWND hControl)
{
static TCHAR szFileName[MAX_PATH];
static TCHAR szImageName[MAX_PATH];
UNREFERENCED_PARAMETER(hControl);
switch (CmdId)
{
case ID_NEW:
{
MessageBox(NULL, _T("Not yet implemented"), NULL, 0);
}
break;
case ID_OPEN:
{
OPEN_IMAGE_EDIT_INFO OpenInfo;
if (DoOpenFile(Info->hSelf,
szFileName, /* full file path */
szImageName)) /* file name */
{
OpenInfo.CreateNew = FALSE;
OpenInfo.Open.lpImagePath = szFileName;
OpenInfo.lpImageName = szImageName;
CreateImageEditWindow(Info,
&OpenInfo);
/* FIXME: move flt wnd's if scroll bars show
MainWndResetFloatingWindows(Info->hMdiClient); */
}
}
break;
case ID_TOOLS:
{
HMENU hMenu = GetMenu(Info->hSelf);
if (hMenu != NULL)
{
UINT uCheck = MF_CHECKED;
if (ShowHideWindow(Info->fltTools->hSelf))
uCheck = MF_UNCHECKED;
CheckMenuItem(hMenu,
ID_TOOLS,
uCheck);
}
}
break;
case ID_COLOR:
{
HMENU hMenu = GetMenu(Info->hSelf);
if (hMenu != NULL)
{
UINT uCheck = MF_CHECKED;
if (ShowHideWindow(Info->fltColors->hSelf))
uCheck = MF_UNCHECKED;
CheckMenuItem(hMenu,
ID_COLOR,
uCheck);
}
}
break;
case ID_HISTORY:
{
HMENU hMenu = GetMenu(Info->hSelf);
if (hMenu != NULL)
{
UINT uCheck = MF_CHECKED;
if (ShowHideWindow(Info->fltHistory->hSelf))
uCheck = MF_UNCHECKED;
CheckMenuItem(hMenu,
ID_HISTORY,
uCheck);
}
}
break;
case ID_BRIGHTNESS:
DialogBoxParam(hInstance,
MAKEINTRESOURCE(IDD_BRIGHTNESS),
Info->hSelf,
BrightnessProc,
(LPARAM)Info);
break;
case ID_CONTRAST:
/* FIXME : Create a window for contrast */
break;
case ID_BLACKANDWHITE:
{
if (Info->ImageEditors)
{
DisplayBlackAndWhite(Info->ImageEditors->hSelf,
Info->ImageEditors->hDCMem,
Info->ImageEditors->hBitmap);
}
}
break;
case ID_INVERTCOLORS:
{
if (Info->ImageEditors)
{
DisplayInvertedColors(Info->ImageEditors->hSelf,
Info->ImageEditors->hDCMem,
Info->ImageEditors->hBitmap);
}
}
break;
case ID_BLUR:
{
if (Info->ImageEditors)
{
DisplayBlur(Info->ImageEditors->hSelf,
Info->ImageEditors->hDCMem,
Info->ImageEditors->hBitmap);
}
}
break;
case ID_SHARPEN:
{
if (Info->ImageEditors)
{
DisplaySharpness(Info->ImageEditors->hSelf,
Info->ImageEditors->hDCMem,
Info->ImageEditors->hBitmap);
}
}
break;
case ID_EXIT:
SendMessage(Info->hSelf,
WM_CLOSE,
0,
0);
break;
/* Window Menu */
case ID_WINDOW_TILE_HORZ:
SendMessage(Info->hMdiClient,
WM_MDITILE,
MDITILE_HORIZONTAL,
0);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -