📄 new.cpp
字号:
// new.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "new.h"
#include <msxml2.h>
#include <objsafe.h>
#include <objbase.h>
#include <atlbase.h>
#define MAX_LOADSTRING 100
const int size = 100;
// 全局变量:
HINSTANCE g_hInst; // 当前实例
HWND g_hWndMenuBar; // 菜单栏句柄
HWND g_hDlgMenuBar; // 对话框菜单栏句柄
HWND hwndCB;
LPCTSTR g_szTitle;
char total[100]; // use to store the text value and send to server
int p = 0; // use to join parts information to whole
int count = 0; // Check out whether loadxml is successful
long num = 0; // Use to store the xml child number
//XML变量
CComPtr<IXMLDOMDocument> m_iXMLDoc = NULL;
// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//初始化会话框
BOOL InitDialog (HWND hDlg);
//Message Handler for Dialog Box
BOOL CALLBACK DialogProc(HWND hDlg, UINT uiMessage,
WPARAM wParam, LPARAM lParam);
//Menu 控制函数
BOOL OnMenuPopup(const HWND hWnd, const WPARAM wParam);
//--------------------------------------------------------
//XML函数
BOOL InitXML(); //初始化XML处理器
BOOL LoadXML(LPCSTR fileName); //载入XML文件到m_iXMLDoc
BOOL SaveXML(LPCSTR fileName); //将m_iXMLDoc保存的磁盘
BOOL ShowXML(HWND hWnd); //显示XML文件内容,以MessageBox形式显示
void DisplayChildren( IXMLDOMElement* pParent, HWND hWnd, int n ); //显示子目录下的内容
void DisplayChild( IXMLDOMElement* pChild, HWND hWnd, int n ); //显示单个结点的内容
//--------------------------------------------------------
//发送消息函数
void SendMessageToServer( HWND hWnd, const char *mes, const int size );
//--------------------------------------------------------
//--------------------------------------------------------
//IP address
in_addr g_in_addr = { (unsigned char)192,
(unsigned char)168,
(unsigned char)1,
(unsigned char)102 };
//--------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// load in program name
g_szTitle = (LPCTSTR)LoadString(hInstance, IDS_DIALOG_TITLE, NULL, 0);
if (!g_szTitle)
return 0;
// 执行应用程序初始化:
if (!InitInstance(hInstance, nCmdShow))
{
return false;
}
// XML处理器的初始化
if(!InitXML())
{
return false;
}
// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// 函数: MyRegisterClass()
//
// 目的: 注册窗口类。
//
// 注释:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NEW));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// 函数: InitInstance(HINSTANCE, int)
//
// 目的: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名
g_hInst = hInstance; // 将实例句柄存储在全局变量中
// 在应用程序初始化期间,应调用一次 SHInitExtraControls 以初始化
// 所有设备特定控件,例如,CAPEDIT 和 SIPPREF。
SHInitExtraControls();
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_NEW, szWindowClass, MAX_LOADSTRING);
//如果它已经在运行,则将焦点置于窗口上,然后退出
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// 将焦点置于最前面的子窗口
// “| 0x00000001”用于将所有附属窗口置于前台并
// 激活这些窗口。
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
if (!MyRegisterClass(hInstance, szWindowClass))
{
return false;
}
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return false;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return true;
}
//
// 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 目的: 处理主窗口的消息。
//
// WM_COMMAND - 处理应用程序菜单
// WM_PAINT - 绘制主窗口
// WM_DESTROY - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
LPCTSTR lpMBoxTitle;
LPCTSTR lpMBoxText2;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case ID_OK:
DialogBox (g_hInst, MAKEINTRESOURCE(IDD_SMARTPHONE_PORTRAIT), hWnd, DLGPROC(DialogProc));
break;
case ID_CANCEL:
lpMBoxText2 = (LPCTSTR)LoadString(g_hInst, IDS_MESSAGEBOX_CANCEL, NULL, 0);
lpMBoxTitle = (LPCTSTR)LoadString(g_hInst, IDS_MESSAGEBOX_TITLE, NULL, 0);
MessageBox(hWnd, lpMBoxText2, lpMBoxTitle, MB_OK);
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
break;
case WM_CREATE:
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.dwFlags = SHCMBF_HMENU;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
CommandBar_Destroy(g_hWndMenuBar);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
BOOL InitDialog(HWND hDlg)
{
// Specify that the dialog box should stretch full screen
SHINITDLGINFO shidi;
//ZeroMemory(&shidi, sizeof(shidi));
memset(&shidi, 0, sizeof(SHINITDLGINFO));
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
// Set up the menu bar
SHMENUBARINFO shmbi;
memset(&shmbi, 0, sizeof(SHMENUBARINFO));
shmbi.cbSize = sizeof(shmbi);
shmbi.hwndParent = hDlg;
shmbi.dwFlags = SHCMBF_HMENU;
shmbi.nToolBarId = IDR_MENU1;
shmbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&shmbi))
{
return false;
g_hDlgMenuBar = NULL;
}
else
{
g_hDlgMenuBar = shmbi.hwndMB;
}
// If we could not initialize the dialog box, return an error
if ( !SHInitDialog(&shidi) )
{
return false;
}
// set the title bar
SetWindowText( hDlg, g_szTitle );
// Overriding Back button functionality
(void)SendMessage(shmbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
return true;
}
// ***************************************************************************
// Function Name: DialogProc
//
// Purpose: Message Handler for Base level modeless Dialog Box
//
// Arguments: Standard Dialog Procedure Arguments
//
// Return Values:
// Only returns to exit the dialog
//
// Description:
// This is the base state dialog window. Using the populate option will bring up
// several child windows.
BOOL CALLBACK DialogProc(HWND hDlg, UINT uiMessage,
WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
BOOL bProcessedMsg = true;
static SHACTIVATEINFO sai;
switch(uiMessage)
{
case WM_INITDIALOG:
InitDialog (hDlg);
break;
case WM_INITMENUPOPUP:
OnMenuPopup(hDlg, wParam);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case ID_LOAD:
count = 0;
if(LoadXML("http://192.168.1.102:8080/smartPhone/login.xml") == FALSE)
{
MessageBox(hDlg, L"Failed", L"Title", MB_OK);
}
else if(ShowXML(hDlg) == FALSE)
{
MessageBox(hDlg, L"Empty document!", L"Error Loading XML", MB_OK);
}
break;
case ID_NEXT:
if(ShowXML(hDlg) == FALSE)
{
MessageBox(hDlg, L"Empty document!", L"Error Loading XML", MB_OK);
}
if(SaveXML("\\save.xml") == FALSE)
{
MessageBox(hDlg, L"Failed", L"Title", MB_OK);
}
break;
case ID_MES:
TCHAR id[10],idvalue[10],name[10],namevalue[10],add[10],addvalue[10];
GetDlgItemText(hDlg, IDC_EDIT11, (LPWSTR)id, 10);
GetDlgItemText(hDlg, IDC_EDIT12, (LPWSTR)idvalue, 10);
GetDlgItemText(hDlg, IDC_EDIT21, (LPWSTR)name, 10);
GetDlgItemText(hDlg, IDC_EDIT22, (LPWSTR)namevalue, 10);
GetDlgItemText(hDlg, IDC_EDIT31, (LPWSTR)add, 10);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -