对话框全屏代码 -----在OnInitDialog函数中加入以下代码
m_bFullScreen = FALSE;
// Call SHInitDialog with flags for full screen.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_FULLSCREENNOMENUBAR;
shidi.hDlg = m_hWnd;
SHInitDialog(&shidi);
// SHFullScreen fails if dialog box is not foreground.
SetForegroundWindow();
SHFullScreen(m_hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON|SHFS_HIDESTARTICON);
// Resize the window over the taskbar area.
nX = GetSystemMetrics(SM_CXSCREEN);
nY = GetSystemMetrics(SM_CYSCREEN);
MoveWindow(0,0,nX,nY, TRUE);
调用输入法面板:SHSipPreference(AfxGetMainWnd()->m_hWnd, SIP_UP); //SipShowIM(SIPF_ON);
隐藏输入法面板:SHSipPreference(AfxGetMainWnd()->m_hWnd, SIP_DOWN); //SipShowIM(SIPF_OFF);
/隐藏窗口右上角的OK按钮和X按钮
ModifyStyleEx(WS_EX_CAPTIONOKBTN,WS_EX_TOPMOST,SWP_NOMOVE);//窗口右上角的OK按钮改为X按钮
ModifyStyle(0, WS_NONAVDONEBUTTON, SWP_NOSIZE); //将X按钮隐藏
使用unload.exe卸载程序
PROCESS_INFORMATION stProgressInfo;
CreateProcess(_T("\\Windows\\unload.exe"), szUninstallBuf, NULL, NULL, NULL, 0, NULL, NULL, NULL, &stProgressInfo) ;
szUninstallBuf这个参数必须和注册表 HLM\SOFTWARE\APPS\下的对应应用的名称一致。
有个前提,使用这个必须是在cab中没有指定 nouninstall这个参数
/*
#define EWX_LOGOFF 0
#define EWX_SHUTDOWN 1
#define EWX_REBOOT 2 重启
#define EWX_FORCE 4
#define EWX_POWEROFF 8 关机
*/
extern "C" BOOL ExitWindowsEx(UINT uFlags, DWORD dwReason);
ExitWindowsEx(EWX_REBOOT, 0); //重启(软重启)
ExitWindowsEx(EWX_POWEROFF, 0); //关机
显示或者隐藏等待图标
// Set the cursor as the wait cursor.
SetCursor (LoadCursor (NULL, IDC_WAIT));
// Hide the cursor.
SetCursor (0);
//获取当前剩余物理内存:
#include <windows.h>
MEMORYSTATUS Status;
Status.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&Status);
//return Status.dwAvailPhys;
获取电池电量剩余百分比:
SYSTEM_POWER_STATUS_EX stat;
GetSystemPowerStatusEx(&stat, TRUE);
if (stat.BatteryLifePercent > 100)
return -1;
else
return stat.BatteryLifePercent;
获取磁盘剩余空间:
GetDiskFreeSpaceEx(NULL,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
通过GPRS连接WAP的代码:
HANDLE m_hConnection;
// 得到正确的连接信息
CONNMGR_DESTINATION_INFO networkDestInfo = {0};
// 得到网络列表
DWORD dwEnumIndex=0;
for (; ; dwEnumIndex++ )
{
memset ( &networkDestInfo, 0, sizeof(CONNMGR_DESTINATION_INFO) );
if ( ConnMgrEnumDestinations ( dwEnumIndex, &networkDestInfo ) == E_FAIL )
break;
if(!_tcscmp(networkDestInfo.szDescription, _T("WAP")))
break;
}
CONNMGR_DESTINATION_INFO DestInfo = {0};
HRESULT hResult = ConnMgrEnumDestinations(dwEnumIndex, &DestInfo);
BOOL bRet = FALSE;
if(SUCCEEDED(hResult))
{
// 初始化连接结构
CONNMGR_CONNECTIONINFO ConnInfo;
ZeroMemory(&ConnInfo, sizeof(ConnInfo));
ConnInfo.cbSize = sizeof(ConnInfo);
ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ConnInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_WAP | CONNMGR_FLAG_PROXY_SOCKS4 | CONNMGR_FLAG_PROXY_SOCKS5;
ConnInfo.dwPriority = CONNMGR_PRIORITY_HIPRIBKGND;//CONNMGR_PRIORITY_USERINTERACTIVE;
ConnInfo.guidDestNet = /*IID_DestNetInternet*/DestInfo.guid;
ConnInfo.bExclusive = FALSE;
ConnInfo.bDisabled = FALSE;
DWORD dwStatus = 0;
hResult = ConnMgrEstablishConnectionSync(&ConnInfo, &m_hConnection, 100*1000, &dwStatus );
DWORD err = GetLastError();
if (SUCCEEDED(hResult))
{
//MessageBox(NULL,L"网络连接成功",L"信息",MB_OK);
return TRUE;
}
else
{
//MessageBox(NULL,L"网络连接失败!!请检查网络状况。",L"错误",MB_OK);
return FALSE;
}
}
下面是封装的一个socket类,可用在wince和wm上
1 // TCPClient_CE.h: interface for the CTCPClient_CE class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #if !defined(AFX_TCPCLIENT_CE_H__B7856B99_69E7_4868_9BA3_96152245C65E__INCLUDED_)
6 #define AFX_TCPCLIENT_CE_H__B7856B99_69E7_4868_9BA3_96152245C65E__INCLUDED_
7
8 #if _MSC_VER > 1000
9 #pragma once
10 #endif // _MSC_VER > 1000
11
12 #include <winsock2.h>
13 #include "yourProject.h"
14
15
16 //定义连接断开事件
17 typedef void (CALLBACK* ONDISCONNECT)(CWnd*);
18 //定义当有数据接收事件
19 typedef void (CALLBACK* ONREAD)(CWnd*,const char * buf,int len );
20 //定义Socket错误事件
21 typedef void (CALLBACK* ONERROR)(CWnd*,int nErrorCode);
22
23 class CTCPClient_CE
24 {
25 public:
26 CTCPClient_CE();
27 virtual ~CTCPClient_CE();
28 public:
29 friend class YourApp;
30 //打开客户端socket
31 bool Open(CWnd * pWnd);
32 //关闭客户端socket
33 bool Close();
34 //与服务器端建立连接
35 bool Connect();
36 //向服务器端发送数据
37 bool SendDate(const char * buf , int len);
38 bool SendData(const char * buf , int len);
39 public:
40 //远程主机IP地址
41 CString m_remoteHost;
42 //远程主机端口
43 int m_port;
44
45 /*--以下客户端通讯事件--*/
46 //连接断开事件,回调函数
47 ONDISCONNECT OnDisConnect;
48 //接收数据事件,回调函数
49 ONREAD OnRead;
50 //发生错误事件,回调函数
51 ONERROR OnError;
52 HANDLE m_hSynMutex; //同步互斥句柄
53 private:
54 //通讯Socket句柄
55 SOCKET m_socket;
56 //通讯线程退出事件句柄
57 HANDLE m_exitThreadEvent;
58 //通讯线程句柄
59 HANDLE m_tcpThreadHandle;
60 //父窗口句柄
61 CWnd * m_pOwnerWnd;
62 private:
63 //通讯线程函数
64 static DWORD SocketThreadFunc(LPVOID lparam);
65 };
66
67 #endif // !defined(AFX_TCPCLIENT_CE_H__B7856B99_69E7_4868_9BA3_96152245C65E__INCLUDED_)
68
// TCPClient_CE.cpp: implementation of the CTCPClient_CE class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "yourProject.h"
#include "TCPClient_CE.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//构造函数
CTCPClient_CE::CTCPClient_CE()
{
INT iRet = 0;
//初始化socket环境
WSADATA wsd;
iRet = WSAStartup(MAKEWORD(2,2),&wsd);
int nNetTimeout=1000;//1秒
//创建互斥对象,默认状态为“未被线程拥有”
m_hSynMutex = CreateMutex(NULL,FALSE,NULL);
//创建线程退出事件句柄
m_exitThreadEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
}
//析构函数
CTCPClient_CE::~CTCPClient_CE()
{
//释放socket资源
WSACleanup();
//关闭线程退出事件句柄
CloseHandle(m_exitThreadEvent);
//关闭互斥对象
CloseHandle(m_hSynMutex);
}
/*--------------------------------------------------------------------
【函数介绍】: 此线程用于监听TCP客户端通讯的事件,例如当接收到数据、
连接断开和通讯过程发生错误等事件
【入口参数】: lparam:无类型指针,可以通过此参数,向线程中传入需要用到的资源。
在这里我们将CTCPClient_CE类实例指针传进来
【出口参数】: (无)
【返回 值】: 返回值没有特别的意义,在此我们将返回值设为0。
---------------------------------------------------------------------*/
DWORD CTCPClient_CE::SocketThreadFunc(LPVOID lparam)
{
CTCPClient_CE *pSocket;
//得到CTCPClient_CE实例指针
pSocket = (CTCPClient_CE*)lparam;
//定义读事件集合
fd_set fdRead;
int ret;
//定义事件等待时间
TIMEVAL aTime;
aTime.tv_sec = 1;
aTime.tv_usec = 0;
while (TRUE)
{
//收到退出事件,结束线程
if (WaitForSingleObject(pSocket->m_exitThreadEvent,0) == WAIT_OBJECT_0)
{
break;
}
//置空fdRead事件为空
FD_ZERO(&fdRead);
//给客户端socket设置读事件
FD_SET(pSocket->m_socket,&fdRead);
//调用select函数,判断是否有读事件发生
ret = select(0,&fdRead,NULL,NULL,&aTime);
if (ret == SOCKET_ERROR)
{
//触发错误事件
pSocket->OnError(pSocket->m_pOwnerWnd,1);
//触发连接断开事件
pSocket->OnDisConnect(pSocket->m_pOwnerWnd);
//关闭客户端socket
closesocket(pSocket->m_socket);
break;
}
if (ret > 0)
{
if (FD_ISSET(pSocket->m_socket,&fdRead))
{
//发生读事件
char recvBuf[1024];
int recvLen;
ZeroMemory(recvBuf,1024);
//接收数据
recvLen = recv(pSocket->m_socket,recvBuf, 1024,0);
if (recvLen == SOCKET_ERROR)
{
int iError = WSAGetLastError();
//触发socket错误事件
pSocket->OnError(pSocket->m_pOwnerWnd,iError);
//触发与服务器断开事件
pSocket->OnDisConnect(pSocket->m_pOwnerWnd);
//关闭客户端socket
closesocket(pSocket->m_socket);
break;
}
else if (recvLen == 0)
{
//触发与服务器端断开事件
pSocket->OnDisConnect(pSocket->m_pOwnerWnd);
//关闭客户端socket
closesocket(pSocket->m_socket);
break;
}
else
{
//触发数据接收事件
pSocket->OnRead(pSocket->m_pOwnerWnd,recvBuf,recvLen);
}
}
}
}
return 0;
}
/*--------------------------------------------------------------------
【函数介绍】: 用于打开客户端socket
【入口参数】: pWnd用于指定父窗口句柄
【出口参数】: (无)
【返回 值】: TRUE:打开成功;FALSE:打开失败
---------------------------------------------------------------------*/
bool CTCPClient_CE::Open(CWnd * pWnd)
{
//复位线程退出事件
ResetEvent(m_exitThreadEvent);
//存储父窗口句柄
m_pOwnerWnd = pWnd;
//创建TCP套接字
m_socket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (m_socket == SOCKET_ERROR)
{
return FALSE;
}
//创建通讯线程
m_tcpThreadHandle = CreateThread(NULL,0,SocketThreadFunc,this,0,NULL);
if (m_tcpThreadHandle == NULL)
{
closesocket(m_socket);
return FALSE;
}
return TRUE;
}
/*--------------------------------------------------------------------
【函数介绍】: 用于关闭客户端socket
【入口参数】: (无)
【出口参数】: (无)
【返回 值】: TRUE:关闭成功;FALSE:关闭失败
---------------------------------------------------------------------*/
bool CTCPClient_CE::Close()
{
//发送通讯线程结束事件
SetEvent(m_exitThreadEvent);
Sleep(1000);
//关闭Socket,释放资源
int err = closesocket(m_socket);
if (err == SOCKET_ERROR)
{
return FALSE;
}
return TRUE;
}
/*--------------------------------------------------------------------
【函数介绍】: 用于建立与TCP服务器连接
【入口参数】: (无)
【出口参数】: (无)
【返回 值】: TRUE:建立连接成功;FALSE:建立连接失败
---------------------------------------------------------------------*/
bool CTCPClient_CE::Connect()
{
struct sockaddr_in addr;
int err;
addr.sin_family = AF_INET;
addr.sin_port = htons(m_port);
//此处要将双字节转换成单字节
char ansiRemoteHost[255];
ZeroMemory(ansiRemoteHost,255);
WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,m_remoteHost,wcslen(m_remoteHost)
,ansiRemoteHost,wcslen(m_remoteHost),NULL,NULL);
addr.sin_addr.s_addr=inet_addr(ansiRemoteHost);
//此时采用同步连接方式,connect直接返回成功或是失败
err = connect(m_socket,(struct sockaddr *)&addr,sizeof(addr));
if (err == SOCKET_ERROR)
{
return FALSE;
}
DWORD Result = GetLastError();
//select 模型,即设置超时
/* struct timeval timeout;
fd_set r;
FD_ZERO(&r);
FD_SET(m_socket, &r);
timeout.tv_sec = 15; //连接超时15秒
timeout.tv_usec = 0;
int ret = select(0, 0, &r, 0, &timeout);
if(ret <= 0)
{
::closesocket(m_socket);
return FALSE;
} */
//设置通讯模式为异步模式(阻塞模式)
DWORD ul= 1;
ioctlsocket(m_socket,FIONBIO,&ul);
return TRUE;
}
/*--------------------------------------------------------------------
【函数介绍】: 向服务器端发送数据
【入口参数】: buf:待发送的数据
len:待发送的数据长度
【出口参数】: (无)
【返回 值】: TRUE:发送数据成功;FALSE:发送数据失败
---------------------------------------------------------------------*/
bool CTCPClient_CE::SendDate(const char * buf , int len)
{
int nBytes = 0;
int nSendBytes=0;
static int Count = 0;
Count += 1;
while (nSendBytes < len)
{
nBytes = send(m_socket,buf+nSendBytes,len-nSendBytes,0);
if (nBytes==SOCKET_ERROR )
{
DWORD Err = GetLastError();
int iErrorCode = WSAGetLastError();
// CString cs;
// cs.Format(L"%ld",Err);
// CString cs1;
// cs1.Format(L"%d",Count);
// MessageBox(NULL,cs,cs1,MB_OK);
//触发socket的Error事件
OnError(m_pOwnerWnd,iErrorCode);
//触发与服务器端断开连接事件
OnDisConnect(m_pOwnerWnd);
//关闭socket
Close();
return FALSE;
}
nSendBytes = nSendBytes + nBytes;
if (nSendBytes < len)
{
Sleep(2000);
}
}
return TRUE;
}
bool CTCPClient_CE::SendData(const char * buf , int len)
{
//请求互斥对象
if (WaitForSingleObject(m_hSynMutex,INFINITE) == WAIT_OBJECT_0)
{
SendDate(buf,len);
}
//释放对互斥对象的拥有权
ReleaseMutex(m_hSynMutex);
return TRUE;
}
上面就是封装的socket类,类中的友元类是应用程序类,我们在app中引入这个类,并在app类中实现它的void CALLBACK OnDisConnect(CWnd* pWnd); //连接断开事件处理函数;void CALLBACK OnError(CWnd* pWnd,int nErrorCode); //Socket错误事件处理函数;void CALLBACK OnRead(CWnd* pWnd,const char * buf,int len); //数据接收事件;上面三个方法最好都做成static方法,方便在程序中任意地方引用它。
在Windows Mobile中最小化,显示图标在任务栏上
BOOL SampleDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
UINT nID = LOWORD( wParam );
switch(nID)
{
case 20:
{
this->ShowWindow(SW_SHOW);
return true;
}
break;
}
return CWnd::OnCommand(wParam,lParam);
}
当然如果是再Windows程序中也可以用如下的方式写:
在WinMain函数中设置回调函数。
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
g_hInst = hInstance;
SHInitExtraControls();
// just call a dialog box, system will handle messaging, painting, etc...
DialogBox(hInstance,(LPCTSTR)IDD_NOTIFYMAIN, NULL,(DLGPROC)NotifyMain );
return 0;
}
在回调函数中处理:
LRESULT CALLBACK NotifyMain(
HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
switch(message)
{
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case 10:
{Your operation}
Break;
}
}
}
}
不断更新中..........................