📄 mywincepro.cpp
字号:
// MyWinCEPro.cpp : Defines the entry point for the application.
//
#include <windows.h>
#include <windowsx.h>
#include <aygshell.h>
#include <assert.h>
#include <TCHAR.H>
#include "resource.h"
#include "ErrorReporting.h"
#include "File.h"
#include "SearchEngine.h"
#include "DBRecord.h"
#include "Infrared.h"
#pragma warning(disable: 4800)
HINSTANCE g_hInst = NULL; // Local copy of hInstance
#define ARRAYSIZE(a) (sizeof(a)/sizeof(*a))
const TCHAR* g_szAppWndClass = TEXT("HelloApp");
TCHAR g_szMessage[30];
/*************************************************************************************/
HINSTANCE hInst = NULL;
HWND MyhWnd;
//HWND MyhWnd2;
LPTSTR FileContent = new TCHAR[1024];
LPTSTR FileName = new TCHAR[50];
LPTSTR SearchYear = new TCHAR[20];
LPTSTR SearchMonth = new TCHAR[20];
LPTSTR SearchDay = new TCHAR[20];
LPTSTR SearchHour = new TCHAR[20];
LPTSTR SearchMinute = new TCHAR[20];
LPTSTR SearchName = new TCHAR[50];
LPTSTR SendName = new TCHAR[50];
LPTSTR FileNameAfterSearch = new TCHAR[50];
LPTSTR pword=new TCHAR[100];
ErrorReport erFile;
int openflagsearch=0; //time数据库没有被打开 ,显示0
int updateflagsinceopen=0; //表示自从打开过以后并没有改变,显示0
db dbname,dbft,dbpw;
/*************************************************************************************/
LRESULT CALLBACK EditFile(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK SearchFile(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK SendFile(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK SendFile2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK Password(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK PasswordCheck(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
/**************************************************************************************
OnCreate
**************************************************************************************/
LRESULT OnCreate(
HWND hwnd,
CREATESTRUCT* lParam
)
{
// create the menu bar
SHMENUBARINFO mbi;
ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDR_HELLO_MENUBAR;
mbi.hInstRes = g_hInst;
if(!SHCreateMenuBar(&mbi))
{
// Couldn't create the menu bar. Fail creation of the window.
return(-1);
}
// Get our message text.
if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage, ARRAYSIZE(g_szMessage)))
{
// Couldn't load the string. Fail creation of the window.
return(-1);
}
// Do other window creation related things here.
return(0); // continue creation of the window
}
/**************************************************************************************
WndProc
**************************************************************************************/
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wp,
LPARAM lp
)
{
MyhWnd=hwnd;
// MyhWnd2=hwnd;
LRESULT lResult = TRUE;
switch(msg)
{
case WM_CREATE:
lResult = OnCreate(hwnd, (CREATESTRUCT*)lp);
break;
case WM_COMMAND:
switch (wp)
{
case ID_MENUcreate:
dbname.createDB(TEXT("\\Name.cdb"),TEXT("Name"));
dbft.createDB(TEXT("\\Time.cdb"),TEXT("Time"));
dbpw.createDB(TEXT("\\PW.cdb"),TEXT("PW"));
openflagsearch=1; //time数据库已经被打开
break;
case ID_MENUeditFile:
DialogBox(hInst, (LPCTSTR)IDD_EditFile, hwnd, (DLGPROC)EditFile);
break;
case ID_MENUITEMsearch:
DialogBox(hInst, (LPCTSTR)IDD_SearchFile, hwnd, (DLGPROC)SearchFile);
break;
case ID_MENUinfraredSend:
DialogBox(hInst, (LPCTSTR)IDD_sendFile, hwnd, (DLGPROC)SendFile);
break;
case ID_MENUlistFile:
{
LPTSTR FileNameMessage=new TCHAR[1024];
int listallRowNo;
wcscpy(FileNameMessage,L"Files are:\n");
listallRowNo=dbname.prgPropVal[0].val.iVal;
int i=0;
for(i=1;i<=listallRowNo;i++){
TCHAR numberi[20];
_itot(i,numberi,10);
wcscat(FileNameMessage,numberi);
wcscat(FileNameMessage,TEXT(":"));
wcscat(FileNameMessage,dbname.prgPropVal[i].val.lpwstr);
wcscat(FileNameMessage,TEXT("\n"));
}
MessageBox(NULL,FileNameMessage, L"Total:",MB_OK);
delete FileNameMessage;
}
break;
default:
goto DoDefault;
}
break;
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hdc, g_szMessage, -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hwnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
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.
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);
}
/*****************************************************************************
WinMain
***************************************************************************/
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow
)
{
MSG msg;
HWND hwnd = NULL;
BOOL fActivated;
WNDCLASS wc;
HWND hwndMain;
TCHAR szAppTitle[20];
g_hInst = hInstance;
hInst = hInstance;
if(0 == LoadString(g_hInst, IDS_HELLO_TITLE, szAppTitle, ARRAYSIZE(szAppTitle)))
{
return(0);
}
if(FAILED(ActivatePreviousInstance(g_szAppWndClass, szAppTitle, &fActivated)) ||
fActivated)
{
return(0);
}
// Register our main window's class.
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = NULL;
wc.hInstance = g_hInst;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szAppWndClass;
if(!RegisterClass(&wc))
{
return(0);
}
// Create the main window.
hwndMain = CreateWindow(g_szAppWndClass, szAppTitle,
WS_CLIPCHILDREN, // Setting this to 0 gives a default style we don't want. Use a benign style bit instead.
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, g_hInst, NULL );
if(!hwndMain)
{
return(0);
}
ShowWindow(hwndMain, nCmdShow);
UpdateWindow(hwndMain);
// Pump messages until a PostQuitMessage.
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
// end MyWinCEPro.cpp
LRESULT CALLBACK EditFile(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;
switch (message)
{
case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;
// if the About box is larger than the physical screen
if (NewPosX < 0) NewPosX = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -