新手求帮助,一段简单代码一运行就退出
本人刚学WINCE应用,看了一下视频,照着写了一段代码,但是一运行(不管在模拟机还是实际连接开发板都同样问题)就显示:
加载模块: TestControl.exe
加载模块: coredll.dll
程序“[40e003e] TestControl.exe”已退出,返回值为 0 (0x0)。
程序根本没跑起来,什么原因呀?代码如下:
头文件TestControl.h
#define dim(x) (sizeof(x)/sizeof(x[0]))
struct myMessageAry{
UINT message;
LONG (*fun)(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
};
LONG OnInit(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnCommand(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnEditChange(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
***********************************************
源文件TestControl.cpp:
#include <windows.h>
#include <WindowsX.h>
#include <Commctrl.h.>
#include <stdio.h>
#include "resource.h"
#include "TestControl.h"
struct myMessageAry myDlgMessageAry[]={
WM_INITDIALOG,OnInit,
WM_COMMAND,OnCommand,
};
struct myMessageAry myDlgCommandAry[]={
IDE_RED,OnEditChange,
IDE_GREEN,OnEditChange,
IDE_BLUE,OnEditChange,
};
BOOL CALLBACK About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
//入口主函数
int WINAPI WinMain(HINSTANCE hHinstance,HINSTANCE preHinstance,LPTSTR lpCmdLind,int nShowCmd){
try{
DialogBox(hHinstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,About);
}catch(...){
MessageBox(NULL,TEXT("catch error"),TEXT("my exception"),MB_OK);
}
return 0;
}
//对话框消息处理
BOOL CALLBACK About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam){
for (int i=0;i<dim(myDlgMessageAry);i++){
if (myDlgMessageAry[i].message==message)
{
(*myDlgMessageAry[i].fun)(hDlg,message,wParam,lParam);
}
}
return FALSE;
}
//初始化
LONG OnInit(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam){
Edit_SetText(GetDlgItem(hDlg,IDE_RED),TEXT("127"));
Edit_SetText(GetDlgItem(hDlg,IDE_GREEN),TEXT("127"));
Edit_SetText(GetDlgItem(hDlg,IDE_BLUE),TEXT("127"));
SendDlgItemMessage(hDlg,IDE_RED,UDM_SETBUDDY,(WPARAM)GetDlgItem(hDlg,IDC_RED),0);
SendDlgItemMessage(hDlg,IDE_RED,UDM_SETRANGE,0,MAKELONG(255,0));
SendDlgItemMessage(hDlg,IDE_RED,UDM_SETPOS,0,MAKELONG(123,0));
return 1;
}
//窗体中的控件事件响应
LONG OnCommand(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam){
for (int i=0;i<dim(myDlgCommandAry);i++)
{
if (myDlgCommandAry[i].message=LOWORD(wParam))
{
(*myDlgCommandAry[i].fun)(hDlg,message,wParam,lParam);
}
}
return 1;
}
LONG OnEditChange(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam){
HDC hdc;
HWND hStatic;
TCHAR buff[32]=TEXT("");
RECT rect;
GetClientRect(hDlg,&rect);
if(HIWORD(wParam)==EN_UPDATE){
hStatic = GetDlgItem(hDlg,IDC_STATIC1);
hdc = GetDC(hStatic);
Edit_GetText(GetDlgItem(hDlg,IDE_RED),buff,32);
int red = _wtoi(buff);
Edit_GetText(GetDlgItem(hDlg,IDE_GREEN),buff,32);
int green = _wtoi(buff);
Edit_GetText(GetDlgItem(hDlg,IDE_BLUE),buff,32);
int blue = _wtoi(buff);
FillRect(hdc,&rect,CreateSolidBrush(RGB(red,green,blue)));
ReleaseDC(hStatic,hdc);
}
return 1;
}
********************************
[解决办法]