?? mainwin.cpp
字號:
static char *mainwin_id =
"@(#)Copyright (C) H.Shirouzu 1996-2004 mainwin.cpp Ver2.06";
/* ========================================================================
Project Name : IP Messenger for Win32
Module Name : Main Window
Create : 1996-06-01(Sat)
Update : 2004-09-08(Wed)
Copyright : H.Shirouzu
Reference :
======================================================================== */
#include "tlib.h"
#include "resource.h"
#include "ipmsg.h"
#include "msgstr.h"
#include "blowfish.h"
HICON TMainWin::hMainIcon = NULL;
HICON TMainWin::hRevIcon = NULL;
TMainWin *TMainWin::mainWin = NULL;
static HWND hMainWnd = NULL;
/*
MainWindow 偺弶婜壔
*/
TMainWin::TMainWin(ULONG nicAddr, int _portNo, TWin *_parent) : TWin(_parent)
{
hosts.Enable(THosts::NAME, TRUE);
hosts.Enable(THosts::ADDR, TRUE);
cfg = new Cfg(nicAddr, portNo = _portNo);
if ((msgMng = new MsgMng(nicAddr, portNo, cfg))->GetStatus() == FALSE)
{
::ExitProcess(0xffffffff);
return;
}
cfg->ReadRegistry();
setupDlg = new TSetupDlg(cfg, &hosts);
aboutDlg = new TAboutDlg();
absenceDlg = new TAbsenceDlg(cfg, this);
logmng = new LogMng(cfg);
ansList = new TRecycleList(MAX_ANSLIST, sizeof(AddrObj));
shareMng = new ShareMng(cfg);
shareStatDlg = new TShareStatDlg(shareMng, cfg);
refreshStartTime = 0;
entryStartTime = IPMSG_GETLIST_FINISH;
memset(packetLog, 0, sizeof(packetLog));
packetLogCnt = 0;
entryTimerStatus = 0;
reverseTimerStatus = 0;
ansTimerID = 0;
terminateFlg = FALSE;
activeToggle = TRUE;
InitIcon();
hAccel = ::LoadAccelerators(TApp::hI, (LPCSTR)IPMSG_ACCEL);
}
/*
MainWindow 廔椆
*/
TMainWin::~TMainWin()
{
#if 0 // 柍懯
delete msgMng;
delete cfg;
delete ansList;
#endif
}
/*
巕Window 偍傛傃 socket偺廔椆偲強桳Memory偺奐曻
*/
void TMainWin::Terminate(void)
{
if (terminateFlg)
return;
terminateFlg = TRUE;
if (msgMng->GetStatus() != TRUE)
return;
ExitHost();
DeleteListDlg(&sendList);
DeleteListDlg(&recvList);
DeleteListDlg(&msgList);
delete aboutDlg;
delete shareStatDlg;
delete absenceDlg;
delete setupDlg;
if (IsNewShell())
TaskBar(NIM_DELETE);
time_t now_time = Time();
for (int cnt=0; cnt < hosts.HostCnt(); cnt++)
hosts.GetHost(cnt)->updateTime = now_time;
cfg->WriteRegistry(CFG_HOSTINFO|CFG_DELCHLDHOST);
msgMng->CloseSocket();
if (cfg->hPrivKey)
pCryptDestroyKey(cfg->hPrivKey);
if (cfg->hSmallPrivKey)
pCryptDestroyKey(cfg->hSmallPrivKey);
#if 0 // 柍懯
delete logmng;
Host *host;
while (hosts.HostCnt() > 0)
{
hosts.DelHost(host = hosts.GetHost(0));
// delete host;
}
AddrObj *brObj;
while ((brObj = (AddrObj *)cfg->DialUpList.TopObj()) != NULL)
{
cfg->DialUpList.DelObj(brObj);
delete brObj;
}
#endif
}
/*
MainWindow 惗惉帪偺 CallBack
New Shell 側傜丄TaskTray 偵 icon搊榐丄偦偆偱側偄側傜 icon壔
Packet 庴怣奐巒丄Entry Packet偺憲弌
*/
BOOL TMainWin::EvCreate(LPARAM lParam)
{
hMainWnd = hWnd;
mainWin = this;
if (msgMng->GetStatus() != TRUE)
return TRUE;
if (IsNewShell())
{
Show(SW_HIDE);
while (TaskBar(NIM_ADD, hMainIcon, IPMSG_MSGSTR) != TRUE)
Sleep(1000); // for logon script
}
else
Show(SW_MINIMIZE);
TaskBarCreateMsg= ::RegisterWindowMessage("TaskbarCreated");
SetIcon(cfg->AbsenceCheck == FALSE ? hMainIcon : hRevIcon);
SetCaption();
if (SetupCryptAPI() == FALSE)
MessageBox("CryptoAPI can't be used. Setup New version IE");
msgMng->AsyncSelectRegist(hWnd);
SetHotKey(cfg);
if (msgMng->GetStatus())
EntryHost();
return TRUE;
}
/*
Task Manager側偳偐傜偺廔椆梫媮
*/
BOOL TMainWin::EvClose(void)
{
Terminate();
::PostQuitMessage(0);
return TRUE;
}
/*
Timer Callback
NonPopup庴怣帪偺 icon斀揮
ListGet Mode偵偍偗傞丄HostList梫媮/庴怣張棟
*/
BOOL TMainWin::EvTimer(WPARAM timerID, TIMERPROC proc)
{
if (terminateFlg)
{
::KillTimer(hWnd, timerID);
return TRUE;
}
switch (timerID)
{
case IPMSG_REVERSEICON:
ReverseIcon(FALSE);
return TRUE;
case IPMSG_LISTGET_TIMER:
::KillTimer(hWnd, IPMSG_LISTGET_TIMER);
entryTimerStatus = 0;
if (entryStartTime != IPMSG_GETLIST_FINISH)
{
entryStartTime = Time();
if (::SetTimer(hWnd, IPMSG_LISTGETRETRY_TIMER, cfg->ListGetMSec, NULL))
entryTimerStatus = IPMSG_LISTGETRETRY_TIMER;
BroadcastEntry(IPMSG_BR_ISGETLIST2 | IPMSG_RETRYOPT);
}
return TRUE;
case IPMSG_LISTGETRETRY_TIMER:
::KillTimer(hWnd, IPMSG_LISTGETRETRY_TIMER);
entryTimerStatus = 0;
if (entryStartTime != IPMSG_GETLIST_FINISH)
{
entryStartTime = IPMSG_GETLIST_FINISH;
if (cfg->ListGet)
BroadcastEntry(IPMSG_BR_ENTRY);
}
return TRUE;
case IPMSG_ANS_TIMER:
::KillTimer(hWnd, IPMSG_ANS_TIMER);
ansTimerID = 0;
ExecuteAnsQueue();
return TRUE;
case IPMSG_ENTRY_TIMER:
::KillTimer(hWnd, IPMSG_ENTRY_TIMER);
for (TBroadcastObj *brobj=cfg->broadcastList.Top(); brobj; brobj=cfg->broadcastList.Next(brobj))
BroadcastEntrySub(brobj->Addr(), htons(portNo), IPMSG_BR_ENTRY);
for (AddrObj *obj = (AddrObj *)cfg->DialUpList.TopObj(); obj != NULL; obj = (AddrObj *)cfg->DialUpList.NextObj(obj))
BroadcastEntrySub(obj->addr, obj->portNo, IPMSG_BR_ENTRY);
return TRUE;
}
return FALSE;
}
/*
WM_COMMAND CallBack
*/
BOOL TMainWin::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl)
{
switch (wID)
{
case MENU_SETUP:
MiscDlgOpen(setupDlg);
return TRUE;
case MENU_LOGOPEN:
LogOpen();
return TRUE;
case MENU_ABOUT:
MiscDlgOpen(aboutDlg);
return TRUE;
case MENU_SHARE:
MiscDlgOpen(shareStatDlg);
return TRUE;
case MENU_ACTIVEWIN:
ActiveChildWindow(activeToggle = TRUE);
return TRUE;
case MENU_ABSENCE:
cfg->AbsenceCheck = !cfg->AbsenceCheck;
BroadcastEntry(IPMSG_BR_ABSENCE);
SetIcon(cfg->AbsenceCheck == FALSE ? hMainIcon : hRevIcon);
return TRUE;
case MENU_ABSENCEEX:
MiscDlgOpen(absenceDlg);
return TRUE;
case HIDE_ACCEL:
PostMessage(WM_HIDE_CHILDWIN, 0, 0);
return TRUE;
case MISC_ACCEL:
case MENU_DELMISCDLG:
DeleteListDlg(&msgList);
return TRUE;
case MENU_EXIT:
case IDCANCEL:
Terminate();
::PostQuitMessage(0);
return TRUE;
default:
if (wID >= (UINT)MENU_ABSENCE_START && wID < (UINT)MENU_ABSENCE_START + cfg->AbsenceMax)
{
cfg->AbsenceChoice = wID - MENU_ABSENCE_START;
cfg->AbsenceCheck = FALSE;
EvCommand(0, MENU_ABSENCE, 0);
return TRUE;
}
}
return FALSE;
}
/*
System Menu Callback
*/
BOOL TMainWin::EvSysCommand(WPARAM uCmdType, POINTS pos)
{
switch (uCmdType)
{
case SC_RESTORE: case SC_MAXIMIZE:
if (!IsNewShell())
SendDlgOpen();
return TRUE;
case MENU_SETUP:
case MENU_LOGOPEN:
case MENU_ABOUT:
case MENU_SHARE:
case MENU_ACTIVEWIN:
case MENU_DELMISCDLG:
case MENU_ABSENCE:
case MENU_ABSENCEEX:
case MENU_EXIT:
return EvCommand(0, uCmdType, 0);
default:
if (uCmdType >= MENU_ABSENCE_START && (int)uCmdType < MENU_ABSENCE_START + cfg->AbsenceMax)
return EvCommand(0, uCmdType, 0);
break;
}
return FALSE;
}
/*
Logout帪側偳偺廔椆捠抦 CallBack
*/
BOOL TMainWin::EvEndSession(BOOL nSession, BOOL nLogOut)
{
if (nSession)
Terminate();
return TRUE;
}
/*
icon傪捠忢Window偵栠偟偰傛偄偐偳偆偐偺栤偄崌傢偣 CallBack
*/
BOOL TMainWin::EvQueryOpen(void)
{
if (!IsNewShell())
SendDlgOpen();
return TRUE;
}
BOOL TMainWin::EvHotKey(int hotKey)
{
switch (hotKey)
{
case WM_SENDDLG_OPEN:
case WM_DELMISCDLG:
case WM_RECVDLG_OPEN:
return PostMessage(hotKey, 0, 0), TRUE;
}
return FALSE;
}
/*
MouseButton Event CallBack
*/
BOOL TMainWin::EventButton(UINT uMsg, int nHitTest, POINTS pos)
{
switch (uMsg)
{
// case WM_RBUTTONDOWN:
// case WM_NCRBUTTONDOWN:
case WM_RBUTTONUP:
case WM_NCRBUTTONUP:
Popup(MAIN_MENU);
return TRUE;
case WM_LBUTTONDBLCLK:
case WM_NCLBUTTONDBLCLK:
if (cfg->OneClickPopup == FALSE)
SendDlgOpen();
return TRUE;
case WM_LBUTTONDOWN:
case WM_NCLBUTTONDOWN:
SetForegroundWindow();
BOOL ctl_on = (GetAsyncKeyState(VK_CONTROL) & 0x8000) ? TRUE : FALSE;
BOOL shift_on = (GetAsyncKeyState(VK_SHIFT) & 0x8000) ? TRUE : FALSE;
BOOL menu_on = (GetAsyncKeyState(VK_MENU) & 0x8000) ? TRUE : FALSE;
// if (ctl_on && !menu_on)
// return PostMessage(WM_COMMAND, MENU_ABSENCE, 0), TRUE;
if (shift_on && !menu_on)
return PostMessage(WM_COMMAND, MENU_ACTIVEWIN, 0), TRUE;
if (!IsNewShell() && cfg->MsgMinimize == FALSE)
ActiveListDlg(&msgList);
for (TSendDlg *dlg = (TSendDlg *)sendList.TopObj(); dlg != NULL; dlg = (TSendDlg *)sendList.NextObj(dlg))
if (dlg->IsSending())
dlg->SetForegroundWindow(); // 嵞憲怣妋擣僟僀傾儘僌傪慜偵
if (PopupCheck())
return TRUE;
if (cfg->OneClickPopup)
PostMessage(WM_SENDDLG_OPEN, 0, 0);
return FALSE;
}
return FALSE;
}
/*
Menu Event CallBack
*/
BOOL TMainWin::EventInitMenu(UINT uMsg, HMENU hMenu, UINT uPos, BOOL fSystemMenu)
{
switch (uMsg)
{
case WM_INITMENU:
if (IsNewShell() != TRUE && GetMenuItemID(hMenu, 0) != MENU_DELMISCDLG)
{
HMENU hTargetMenu;
char buf[MAX_LISTBUF];
GetSystemMenu(hWnd, TRUE); // 弶婜壔
hTargetMenu = GetSystemMenu(hWnd, FALSE);
DeleteMenu(hTargetMenu, SC_MAXIMIZE, MF_BYCOMMAND);
DeleteMenu(hTargetMenu, SC_MINIMIZE, MF_BYCOMMAND);
DeleteMenu(hTargetMenu, SC_SIZE, MF_BYCOMMAND);
DeleteMenu(hTargetMenu, SC_TASKLIST, MF_BYCOMMAND);
HMENU hMainMenu = LoadMenu(TApp::hI, (LPCSTR)MAIN_MENU);
HMENU hSubMenu = GetSubMenu(hMainMenu, 0);
int maxItem = GetMenuItemCount(hSubMenu);
for (int cnt=0; cnt < maxItem -2; cnt++)
{
if (GetMenuString(hSubMenu, cnt, buf, sizeof(buf), MF_BYPOSITION) > 0)
::AppendMenu(hTargetMenu, MF_STRING, GetMenuItemID(hSubMenu, cnt), buf);
else
::AppendMenu(hTargetMenu, MF_SEPARATOR, NULL, NULL);
}
AddAbsenceMenu(hTargetMenu, 0);
DestroyMenu(hMainMenu);
}
return TRUE;
}
return FALSE;
}
BOOL TMainWin::AddAbsenceMenu(HMENU hTargetMenu, int insertOffset)
{
char buf[MAX_LISTBUF];
HMENU hSubMenu = ::CreateMenu();
UINT index = ::GetMenuItemCount(hTargetMenu) - insertOffset;
if (hSubMenu == NULL)
return FALSE;
for (int cnt=cfg->AbsenceMax -1; cnt >= 0; cnt--)
::AppendMenu(hSubMenu, MF_STRING, MENU_ABSENCE_START + cnt, cfg->AbsenceHead[cnt]);
::AppendMenu(hSubMenu, MF_SEPARATOR, 0, 0);
::AppendMenu(hSubMenu, MF_STRING, MENU_ABSENCEEX, ABSENCESET_MSGSTR);
::InsertMenu(hTargetMenu, index++, MF_BYPOSITION|MF_POPUP, (UINT)hSubMenu, ABSENCEMENU_MSGSTR);
if (cfg->AbsenceCheck)
{
wsprintf(buf, "%s(%s)", ABSENCELIFT_MSGSTR, cfg->AbsenceHead[cfg->AbsenceChoice]);
::InsertMenu(hTargetMenu, index, MF_BYPOSITION|MF_STRING, MENU_ABSENCE, buf);
}
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -