📄 mailman.cpp
字号:
// MailMan.cpp : Defines the entry point for the application.
//
#include <windows.h>
#include <windowsx.h>
#include <aygshell.h>
#include "resource.h"
#include "CMainListView.h"
#include "ContactsManager.h"
#include "CSignInDlg.h"
#include "CSendMailDB.h"
#include "userData.h"
#include "MailDate.h"
#include "CRecieveMailDlg.h"
#include "CeUidlDB.h"
CMainListView mainview;
HINSTANCE g_hInst = NULL; // Local copy of hInstance
userDataDB* g_puserDataDB = NULL;
CeMailDate g_maildate;
CeMailDate g_mailtrash;
CeUidlDB g_uiddb;
int g_messageid;
BOOL timestart = FALSE;;
const TCHAR* g_szAppWndClass = TEXT("HelloApp");
HBITMAP g_readedmailmap;
HBITMAP g_newmailmap;
HBITMAP g_mailsendmap;
HBITMAP g_mailnotsendmap;
HBITMAP g_mainmenumap[6];
//global strings
TCHAR g_MainList[6][30];
HWND g_winmain;
//global functions
BOOL LoadGlobleString();
BOOL LoadGlobleBitMap();
BOOL InitialDB();
BOOL RemoveDB();
BOOL DrawMainItem(HWND hwnd, LPARAM lParam);
BOOL ReleaseResource();
//global declaration
extern CContactsManager g_contactmanager;
extern TCHAR g_group[GROUP_NUMBER][16];
extern CSignInDlg g_signindlg;
extern CSendMailDB g_sendmaildb;
extern CRecieveMailDlg g_rmaildlg;
extern TCHAR g_username[ADDRESS_LENTH];
extern AutoRecieve(HWND);
int const REVIEMAIL_TIMER_ID = 5000;
int const TIME = 60*1000*30;
/**************************************************************************************
OnCreate
**************************************************************************************/
LRESULT OnCreate(
HWND hwnd,
CREATESTRUCT* lParam
)
{
// create the menu bar
TCHAR apppath[60];
SHMENUBARINFO mbi;
ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDR_MENUBAR_MAINMENU;
mbi.hInstRes = g_hInst;
if(!SHCreateMenuBar(&mbi))
{
// Couldn't create the menu bar. Fail creation of the window.
return(-1);
}
if(LoadGlobleString() == FALSE)
return (-1);
if(LoadGlobleBitMap() == FALSE)
return (-1);
// Do other window creation related things here.
//创建mainview
mainview.m_hmenu = (HMENU)IDC_MAIN_VIEW;
if(mainview.Create(hwnd,g_hInst) == -1)
return (-1);
LoadString(g_hInst,IDS_STRING_APPDATAPATH,apppath,60);
CreateDirectory(apppath,NULL);
g_puserDataDB = new userDataDB(g_hInst);
if(g_puserDataDB == NULL)
return (-1);
g_puserDataDB->OpenOrCreateDB();
InitialDB();
memset(g_username,0,sizeof(g_username));
return(0); // continue creation of the window
}
/**************************************************************************************
WndProc
**************************************************************************************/
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wp,
LPARAM lp
)
{
LRESULT lResult = TRUE;
switch(msg)
{
case WM_CREATE:
{
TCHAR path[50];
lResult = OnCreate(hwnd, (CREATESTRUCT*)lp);
LoadString(g_hInst,IDS_STRING_CONTACTPATH,path,50);
g_contactmanager.MountVolumeAndCreate(path);
break;
}
case WM_COMMAND:
switch (wp)
{
case ID_MENUITEM_QUIT:
DestroyWindow(hwnd);
break;
case ID_MENUITEM_RECEIVEMAIL:
{
g_rmaildlg.m_curusername = (LPWSTR)g_username;
CRecieveMailDlg::DlgBox(g_rmaildlg,g_hInst,hwnd);
break;
}
case ID_MENUITEM_MIN:
{
ShowWindow(hwnd,SW_HIDE);
SendMessage(hwnd,WM_KILLFOCUS,NULL,0);
break;
}
default:
goto DoDefault;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
KillTimer(hwnd,REVIEMAIL_TIMER_ID);
g_contactmanager.UnmountVolume();
RemoveDB();
ReleaseResource();
if(g_puserDataDB != NULL)
delete g_puserDataDB;
PostQuitMessage(0);
break;
case WM_NOTIFY:
if(IDC_MAIN_VIEW == wp)
{
lResult = mainview.OnNotify(lp);
}
break;
case WM_MEASUREITEM: //
{
LPMEASUREITEMSTRUCT lpmi;
lpmi = (LPMEASUREITEMSTRUCT)lp;
if(lpmi->CtlType == ODT_LISTVIEW)
{
lpmi->itemHeight = 30;
}
break;
}
case WM_DRAWITEM:
DrawMainItem(hwnd, lp);
break;
case WM_ACTIVATE:
{
DWORD dwFlags = LOWORD(wp);
if(dwFlags != WA_INACTIVE)
{
HWND m = SetFocus(mainview.m_hwnd);
}
}
break;
case WM_TIMER:
{
if(timestart)
break;
timestart = TRUE;
UINT wTimerID = wp;
if(wp != REVIEMAIL_TIMER_ID)
break;
if(g_puserDataDB== NULL)
break;
userData user;
if((!g_puserDataDB->GetUserInfo(g_username,user)) || user.rece_manu)
break;
AutoRecieve(hwnd);
timestart = FALSE;
break;
}
DoDefault:
default:
lResult = DefWindowProc(hwnd, msg, wp, lp);
break;
}
return(lResult);
}
/****************************************************************************
ActivatePreviousInstance
****************************************************************************/
HRESULT ActivatePreviousInstance(
const TCHAR* pszClass,
const TCHAR* pszTitle,
BOOL* pfActivated
)
{
HRESULT hr = S_OK;
int cTries;
HANDLE hMutex = NULL;
*pfActivated = FALSE;
cTries = 5;
while(cTries > 0)
{
hMutex = CreateMutex(NULL, FALSE, pszClass); // NOTE: We don't want to own the object.
if(NULL == hMutex)
{
// Something bad happened, fail.
hr = E_FAIL;
goto Exit;
}
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
HWND hwnd;
CloseHandle(hMutex);
hMutex = NULL;
// There is already an instance of this app
// running. Try to bring it to the foreground.
hwnd = FindWindow(pszClass, pszTitle);
if(NULL == hwnd)
{
// It's possible that the other window is in the process of being created...
Sleep(500);
hwnd = FindWindow(pszClass, pszTitle);
}
if(NULL != hwnd)
{
// Set the previous instance as the foreground window
// The "| 0x01" in the code below activates
// the correct owned window of the
// previous instance's main window.
ShowWindow(hwnd,SW_SHOW);
SetForegroundWindow((HWND) (((ULONG) hwnd) | 0x01));
// We are done.
*pfActivated = TRUE;
break;
}
// It's possible that the instance we found isn't coming up,
// but rather is going down. Try again.
cTries--;
}
else
{
// We were the first one to create the mutex
// so that makes us the main instance. 'leak'
// the mutex in this function so it gets cleaned
// up by the OS when this instance exits.
break;
}
}
if(cTries <= 0)
{
// Someone else owns the mutex but we cannot find
// their main window to activate.
hr = E_FAIL;
goto Exit;
}
Exit:
return(hr);
}
BOOL InitialDB()
{
TCHAR full[100];
TCHAR name[30];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -