一共有三个代码:
打包下载:
http://files.cppblog.com/Aiscanf/wince1.rar
#include <windows.h>
#include <CommCtrl.h>
#define dim(x) (sizeof(x)/sizeof(x[0]))
typedef struct
{
UINT uCode;
LRESULT(*functionName)(HWND,UINT,WPARAM,LPARAM);
}MessageProc;
//菜单或者控件id命令的处理
typedef struct
{
UINT uCode;
LRESULT(*funcionName)(HWND,HWND,WORD,WORD);
}CommandProc;
#define IDC_CMDBAR 1
int RegisterWnd(HINSTANCE);
int ShowMainWnd(HINSTANCE,LPWSTR,int);
int QuitMainWnd(HINSTANCE,int);
LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT GoCreateMain(HWND,UINT,WPARAM,LPARAM);
LRESULT GoPaintMain(HWND,UINT,WPARAM,LPARAM);
LRESULT GoDestoryMain(HWND,UINT,WPARAM,LPARAM);
LRESULT GoCloseMain(HWND,UINT,WPARAM,LPARAM);
#include <tchar.h>
#include "hello.h"
const TCHAR szAppName[] = TEXT ("HelloCE");
HINSTANCE hInst;
const MessageProc MainMessages[] =
{
WM_CREATE, GoCreateMain,
WM_PAINT, GoPaintMain,
WM_DESTROY, GoDestoryMain,
WM_CLOSE,GoCloseMain
};
int RegisterWnd(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL,
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
if (RegisterClass (&wc) == 0)
return 0;
return 1;
}
int ShowMainWnd (HINSTANCE hInstance, LPWSTR lpCmdLine,int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow (szAppName,
TEXT("WindowsForm"),
WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL, //菜单,必须为NULL,WINCE窗口不支持菜单。
hInstance,
NULL);
if (!IsWindow (hWnd))
return 0;
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return 1;
}
int QuitMainWnd(HINSTANCE,int nExitCode)
{
return nExitCode;
}
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
INT i;
for (i = 0; i < dim(MainMessages); i++)
{
if (wMsg == MainMessages[i].uCode)
return (*MainMessages[i].functionName)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
LRESULT GoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
HWND hwndCB;
hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
CommandBar_AddAdornments (hwndCB, 0, 0);
return 0;
}
LRESULT GoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
GetClientRect (hWnd, &rect);
rect.top += CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR));
hdc = BeginPaint (hWnd, &ps);
DrawText (hdc, TEXT ("hello wince"), -1, &rect, //被改成了中文
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint (hWnd, &ps);
return 0;
}
//----------------------------------------------------------------------
// DoHibernateMain – 处理窗口挂起消息(WM_HIBERNATE)的函数,这是WINCE独有的消息,目的//是将内存的使用量将到最小.
//
// LRESULT DoHibernateMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
// {
// // 如果窗口不是活动的,则取消命令条,释放内存
// if (GetActiveWindow () != hWnd)
// CommandBar_Destroy (GetDlgItem (hWnd, IDC_CMDBAR));
// return 0;
// }
//----------------------------------------------------------------------
// DoActivateMain – 处理窗口激活(WM_ACTIVATE)消息的函数
//
// LRESULT DoActivateMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
// {
// HWND hwndCB;
// // 如果窗口正处在活动状态而没有命令条则建立它
// if ((LOWORD (wParam) != WA_INACTIVE) &&
// (GetDlgItem (hWnd, IDC_CMDBAR) == 0))
// {
// // 建立命令条
// hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
// // 添加退出按钮到命令条
// CommandBar_AddAdornments (hwndCB, 0, 0);
// }
// return 0;
// }
LRESULT GoDestoryMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage (0);
return 0;
}
LRESULT GoCloseMain(HWND hWnd,UINT msgCode,WPARAM wParam,LPARAM lParam)
{
INT idCode;
idCode = MessageBox(hWnd,TEXT("退出软件么?"),TEXT("退出"),
MB_YESNO|MB_ICONQUESTION);
if (idCode==IDNO)
return 0;
PostQuitMessage(1);
return 0;
}
#include <iostream>
#include "hello.h"
using namespace std;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd )
{
MSG msg;
if (!RegisterWnd(hInstance))
return 1;
if (!ShowMainWnd(hInstance,lpCmdLine,nShowCmd))
return 2;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
// Sleep(10000);
return QuitMainWnd (hInstance, msg.wParam);
}
posted on 2009-06-01 21:11
Aiscanf 阅读(692)
评论(0) 编辑 收藏 引用 所属分类:
Wince