📄 misc.cxx
字号:
}
static PApplication * PApplicationInstance;
LRESULT PEXPORTED WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return PApplicationInstance->WndProc(hWnd,msg,wParam,lParam);
}
BOOL PEXPORTED DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return PApplicationInstance->DlgProc(hWnd,msg,wParam,lParam);
}
BOOL PEXPORTED FileDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return PApplicationInstance->FileDlgProc(hWnd,msg,wParam,lParam);
}
BOOL PEXPORTED PrintDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return PApplicationInstance->PrintDlgProc(hWnd, msg, wParam, lParam);
}
BOOL PEXPORTED FontDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return PApplicationInstance->FontDlgProc(hWnd,msg,wParam,lParam);
}
BOOL PEXPORTED ColourDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return PApplicationInstance->ColourDlgProc(hWnd, msg, wParam, lParam);
}
#define SET_DLG_PROC(proc) \
wndProcPtr[PApplication::proc##ProcType] = (WNDPROC)::proc##Proc
int PApplication::_main(void * arg)
{
PApplicationInstance = this;
hInstance = (HINSTANCE)arg;
SET_DLG_PROC(Wnd);
SET_DLG_PROC(Dlg);
SET_DLG_PROC(FileDlg);
SET_DLG_PROC(PrintDlg);
SET_DLG_PROC(FontDlg);
SET_DLG_PROC(ColourDlg);
Construct();
#if PMEMORY_CHECK
PMemoryHeap::SetIgnoreAllocations(TRUE);
#endif
ostream * debugStream = new PDebugStream;
PSetErrorStream(debugStream); // Use OutputDebugString() stream
PTrace::SetStream(debugStream);
#if PMEMORY_CHECK
PMemoryHeap::SetIgnoreAllocations(FALSE);
#endif
blowUpTimeout = 1000;
doubleClick = 250;
mainWindow = NULL;
receivedQuitMessage = FALSE;
hAccelerator = NULL;
mdiClient = NULL;
defaultHelpFile = GetFile();
defaultHelpFile.SetType(".hlp");
HDC hDC = CreateCompatibleDC(NULL);
primaryScreenSize.SetWidth(GetSystemMetrics(SM_CXSCREEN));
primaryScreenSize.SetHeight(GetSystemMetrics(SM_CYSCREEN));
screenRect.SetX(GetSystemMetrics(SM_XVIRTUALSCREEN));
screenRect.SetY(GetSystemMetrics(SM_YVIRTUALSCREEN));
screenRect.SetWidth(GetSystemMetrics(SM_CXVIRTUALSCREEN));
screenRect.SetHeight(GetSystemMetrics(SM_CYVIRTUALSCREEN));
if (screenRect.Width() == 0 || screenRect.Height() == 0)
screenRect = primaryScreenSize;
screenResImperial.SetWidth((PDIMENSION)GetDeviceCaps(hDC, LOGPIXELSX));
screenResImperial.SetHeight((PDIMENSION)GetDeviceCaps(hDC, LOGPIXELSY));
screenResMetric.SetWidth((PDIMENSION)(screenResImperial.Width()*394L/1000L));
screenResMetric.SetHeight((PDIMENSION)(screenResImperial.Height()*394L/1000L));
cursorSize.SetWidth((PDIMENSION)GetSystemMetrics(SM_CXCURSOR));
cursorSize.SetHeight((PDIMENSION)GetSystemMetrics(SM_CYCURSOR));
iconSize.SetWidth((PDIMENSION)GetSystemMetrics(SM_CXICON));
iconSize.SetHeight((PDIMENSION)GetSystemMetrics(SM_CYICON));
titledBorder.SetWidth((PDIMENSION)GetSystemMetrics(SM_CXFRAME));
titledBorder.SetHeight((PDIMENSION)GetSystemMetrics(SM_CYFRAME));
dlgBorder.SetWidth((PDIMENSION)GetSystemMetrics(SM_CXDLGFRAME));
dlgBorder.SetHeight((PDIMENSION)GetSystemMetrics(SM_CYDLGFRAME));
border.SetWidth((PDIMENSION)GetSystemMetrics(SM_CXBORDER));
border.SetHeight((PDIMENSION)GetSystemMetrics(SM_CYBORDER));
defMainWindow.SetWidth((PDIMENSION)CW_USEDEFAULT);
defMainWindow.SetHeight((PDIMENSION)CW_USEDEFAULT);
defTitledWindow.SetWidth((PDIMENSION)CW_USEDEFAULT);
defTitledWindow.SetHeight((PDIMENSION)CW_USEDEFAULT);
screenColours = GetDeviceCaps(hDC, NUMCOLORS);
screenDepth = (PDIMENSION)(GetDeviceCaps(hDC, BITSPIXEL)*GetDeviceCaps(hDC, PLANES));
heightTitle = (PDIMENSION)GetSystemMetrics(SM_CYCAPTION);
heightMenu = (PDIMENSION)GetSystemMetrics(SM_CYMENU);
heightHScroll = (PDIMENSION)GetSystemMetrics(SM_CYHSCROLL);
widthVScroll = (PDIMENSION)GetSystemMetrics(SM_CXVSCROLL);
dblClkRect.SetWidth((PDIMENSION)GetSystemMetrics(SM_CXDOUBLECLK));
dblClkRect.SetHeight((PDIMENSION)GetSystemMetrics(SM_CYDOUBLECLK));
dblClkRect.Offset(-GetSystemMetrics(SM_CXDOUBLECLK)/2,
-GetSystemMetrics(SM_CYDOUBLECLK)/2);
windowFg.FromSYSCOLOR(COLOR_WINDOWTEXT);
windowBk.FromSYSCOLOR(COLOR_WINDOW);
highlightFg.FromSYSCOLOR(COLOR_HIGHLIGHTTEXT);
highlightBk.FromSYSCOLOR(COLOR_HIGHLIGHT);
menuFg.FromSYSCOLOR(COLOR_MENUTEXT);
menuBk.FromSYSCOLOR(COLOR_MENU);
balloonFg = menuFg;
balloonBk = menuBk;
grayText.FromSYSCOLOR(COLOR_GRAYTEXT);
buttonFg.FromSYSCOLOR(COLOR_BTNTEXT);
buttonBk.FromSYSCOLOR(COLOR_BTNFACE);
buttonLighting.FromSYSCOLOR(COLOR_BTNHIGHLIGHT);
buttonShadow.FromSYSCOLOR(COLOR_BTNSHADOW);
scrollBar.FromSYSCOLOR(COLOR_SCROLLBAR);
activeTitleFg.FromSYSCOLOR(COLOR_CAPTIONTEXT);
activeTitleBk.FromSYSCOLOR(COLOR_ACTIVECAPTION);
inactiveTitleFg.FromSYSCOLOR(COLOR_INACTIVECAPTIONTEXT);
inactiveTitleBk.FromSYSCOLOR(COLOR_INACTIVECAPTION);
activeBorder.FromSYSCOLOR(COLOR_ACTIVEBORDER);
inactiveBorder.FromSYSCOLOR(COLOR_INACTIVEBORDER);
DeleteDC(hDC);
systemFont = PRealFont((HFONT)GetStockObject(DEFAULT_GUI_FONT));
createdWindows.DisallowDeleteObjects();
nonModalDialogs.DisallowDeleteObjects();
delayedCreateInteractors.DisallowDeleteObjects();
#ifndef P_PLATFORM_HAS_THREADS
timerWnd = CreateWindow("STATIC", "",
WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
SetWindowLong(PAssertNULL(timerWnd),
GWL_WNDPROC, (DWORD)wndProcPtr[WndProcType]);
lastSetTimerTick = 1; // Needs to be non-zero
#endif
Main();
return GetTerminationValue();
}
void PApplication::Main()
{
while (ProcessMessage()) {
windowsMutex.Wait();
if (!delayedCreateInteractors.IsEmpty()) {
for (PINDEX i = 0; i < delayedCreateInteractors.GetSize(); i++)
delayedCreateInteractors[i].CreateHWND();
delayedCreateInteractors.RemoveAll();
delayedCreateInteractorsDone.Signal();
}
windowsMutex.Signal();
delayedCloseInteractors.RemoveAll();
}
}
#ifndef P_PLATFORM_HAS_THREADS
void PApplication::OperatingSystemYield()
{
// Assure other MS-Windows tasks gets some time as well
MSG msg;
UINT id = 0x7fff;
while (PeekMessage(&msg, NULL, id, id, PM_NOREMOVE))
id--;
GetTimerList()->Process();
}
#endif
BOOL PApplication::ProcessMessage()
{
if (receivedQuitMessage)
return FALSE;
MSG msg;
receivedQuitMessage = GetMessage(&msg, NULL, 0, 0) == 0;
if (receivedQuitMessage)
return FALSE;
windowsMutex.Wait();
for (PINDEX i = 0; i < nonModalDialogs.GetSize(); i++) {
if (IsDialogMessage(nonModalDialogs[i].GetHWND(), &msg)) {
windowsMutex.Signal();
PassMainLoop();
return TRUE;
}
}
windowsMutex.Signal();
if (mdiClient != NULL && TranslateMDISysAccel(mdiClient, &msg)) {
PassMainLoop();
return TRUE;
}
if (hAccelerator != NULL && mainWindow != NULL &&
TranslateAccelerator(mainWindow->GetHWND(), hAccelerator, &msg)) {
PassMainLoop();
return TRUE;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
PassMainLoop();
return TRUE;
}
LRESULT PApplication::WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
LRESULT retval;
#ifndef P_PLATFORM_HAS_THREADS
if (hWnd == timerWnd)
retval = DefWindowProc(hWnd, msg, wParam, lParam);
else {
#endif
PInteractor * window = (PInteractor *)createdWindows.GetAt(HWNDKey(hWnd));
if (window == NULL)
retval = DefWindowProc(hWnd, msg, wParam, lParam);
else {
PInteractor::_WindowsMessage message;
message.event = msg;
message.wParam = wParam;
message.lParam = lParam;
message.lResult = 0;
message.processed = TRUE;
PInteractor::_WindowsMessage * oldMessage = window->_msg;
window->_msg = &message;
window->WndProc();
window->_msg = oldMessage;
retval = message.lResult;
}
#ifndef P_PLATFORM_HAS_THREADS
}
if (timerWnd != NULL &&
lastSetTimerTick != 0 && lastSetTimerTick != (UINT)GetTickCount()) {
lastSetTimerTick = 0; // Prevent recursive calls
Yield(); // Do the multithreading
long delay = GetTimerList()->Process().GetInterval();
if (!IsOnlyThread())
delay = PTimer::Resolution();
else if (delay > 60000)
delay = 60000;
KillTimer(timerWnd, 1);
PAssertOS(SetTimer(timerWnd, 1, (UINT)delay, NULL) != 0);
// Not too often or it gets really slow
lastSetTimerTick = (UINT)GetTickCount();
if (lastSetTimerTick == 0)
lastSetTimerTick++;
}
#endif
return retval;
}
void PApplication::AddDialog(PInteractorLayout * pWnd)
{
windowsMutex.Wait();
nonModalDialogs.Append(pWnd);
windowsMutex.Signal();
}
void PApplication::RemoveDialog(PInteractorLayout * pWnd)
{
windowsMutex.Wait();
if (nonModalDialogs.GetObjectsIndex(pWnd) != P_MAX_INDEX)
nonModalDialogs.Remove(pWnd);
windowsMutex.Signal();
}
static void DoHelp(PTopLevelWindow * wnd,
const PFilePath & helpFile,
UINT fuCmd, DWORD dwData)
{
PFilePath realHelpFile = helpFile;
if (realHelpFile.GetType().IsEmpty())
realHelpFile.SetType(".hlp");
WinHelp(wnd->GetHWND(), realHelpFile, fuCmd, dwData);
}
void PApplication::Terminate()
{
#ifndef P_PLATFORM_HAS_THREADS
KillTimer(timerWnd, 1);
lastSetTimerTick = 0; // Prevent WndProc from doing anything with timers
#endif
if (mainWindow != NULL) {
#ifdef P_PLATFORM_HAS_THREADS
if (PThread::Current() != &PProcess::Current()) {
::PostMessage(mainWindow->GetHWND(), WM_CLOSE, 0, 0);
return;
}
#endif
DoHelp(mainWindow, defaultHelpFile, HELP_QUIT, 0);
DelayedCloseInteractor(mainWindow);
mainWindow = NULL;
}
PostQuitMessage(0);
}
void PApplication::DoContextHelp(const PString & context, const PFilePath & file)
{
DoHelp(mainWindow, file, HELP_KEY, (DWORD)(const char *)context);
}
void PApplication::DoContextHelp(PINDEX context, const PFilePath & file)
{
switch ((unsigned)context) {
case PSTD_ID_HELP_CONTENTS :
DoHelp(mainWindow, file, HELP_CONTENTS, 0);
break;
case PSTD_ID_HELP_SEARCH :
DoHelp(mainWindow, file, HELP_PARTIALKEY, (DWORD)"");
break;
case PSTD_ID_HELP_ON_HELP :
DoHelp(mainWindow, file, HELP_HELPONHELP, 0);
break;
default :
DoHelp(mainWindow, file, HELP_KEY, context);
}
}
PString PMakeOEMText(const PString & txt)
{
PString s;
PINDEX lastPos = 0;
PINDEX searchPos = 0;
PINDEX pos;
while ((pos = txt.FindOneOf("\r\n", searchPos)) != P_MAX_INDEX) {
if (txt[pos] == '\r' && txt[pos+1] == '\n')
searchPos = pos + 2;
else {
if (pos > 0)
s += txt(lastPos, pos-1);
s += "\r\n";
lastPos = pos + 1;
searchPos = lastPos;
}
}
return s + txt(lastPos, pos);
}
// End Of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -