CreateWindow 失败 为什么啊?

skyspark 2006-04-14 12:24:36
源代码如下: 用EVC4.0做的 是Programming microsoft window CE 第二版得
头文件:
// Header file//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling//
//================================================================
// Returns number of elements
#define dim(x) (sizeof(x) / sizeof(x[0]))
//----------------------------------------------------------
// Generic defines and data types
//
struct decodeUINT { // Structure associates
UINT Code; // messages
// with a function.
LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
};
struct decodeCMD { // Structure associates
UINT Code; // menu IDs with a
LRESULT (*Fxn)(HWND, WORD, HWND, WORD); // function.
};
//----------------------------------------------------------------------
// Generic defines used by application
#define IDC_CMDBAR 1 // Command bar ID
//----------------------------------------------------------------------
// Function prototypes
//
//int InitApp (HINSTANCE);
HWND InitInstance (HINSTANCE, LPWSTR, int);
int TermInstance (HINSTANCE, int);
// Window procedures
LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

// Message handlers
LRESULT DoCreateMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoPaintMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoHibernateMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoActivateMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDestroyMain (HWND, UINT, WPARAM, LPARAM);



...全文
486 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyspark 2006-04-14
  • 打赏
  • 举报
回复
谢谢大家得支持
skyspark 2006-04-14
  • 打赏
  • 举报
回复
CPP:
#include<windows.h>
#include<commctrl.h>
#include"helloworld.h"

const TCHAR szAppName[] = TEXT("HelloCE");
HINSTANCE hInst;

const struct decodeUINT MainMessages[] ={
{WM_CREATE, DoCreateMain},
{WM_PAINT, DoPaintMain},
{WM_HIBERNATE, DoHibernateMain},
{WM_ACTIVATE, DoActivateMain},
{WM_DESTROY, DoDestroyMain}
};
//int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nCmdShow)
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
int rc =0;
HWND hwndMain;

hwndMain=InitInstance(hInstance,(LPWSTR) lpCmdLine,nCmdShow);

if(0==hwndMain)
return 0x10;

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return TermInstance (hInstance,msg.wParam);
}
//---------------------------------------------------------------
// InitApp - Application initialization
//


int InitApp (HINSTANCE hInstance)
{
WNDCLASS wc;
#if defined(WIN32_PLATFORM_PSPC)
// If Pocket PC, allow only one instance of the application.
HWND hWnd = FindWindow (szAppName, NULL);
if (hWnd)
{
SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01)); //????????/
return 1;
}
#endif

// Register application main window class.
wc.style = 0;
// Window style
wc.lpfnWndProc = MainWndProc;
// Callback function
wc.cbClsExtra = 0;
// Extra class data
wc.cbWndExtra = 0;
// Extra window data
wc.hInstance = hInstance;
// Owner handle
wc.hIcon = NULL;
// Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
// Menu name
wc.lpszClassName = szAppName;
// Window class name
if (RegisterClass (&wc) == 0) return 1;
return 0;
}
//------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow)
{ HWND hWnd;
// Save program instance handle in global variable.
hInst = hInstance;
// Create main window.
hWnd = CreateWindow (szAppName, // Window class
TEXT("Hello"), // Window title
WS_VISIBLE, // Style flags
CW_USEDEFAULT, // x position
CW_USEDEFAULT, // y position
CW_USEDEFAULT, // Initial width
CW_USEDEFAULT, // Initial height
NULL, // Parent
NULL, // Menu, must be null
hInstance, // Application instance
NULL); // Pointer to create
// parameters

if (!IsWindow (hWnd)) {

MessageBox(hWnd,TEXT("ss"),NULL,0);
/*DEBUGMSG(ZONE_VERBOSE | ZONE_ERROR,
(TEXT ("Could not create main window.")));*/

}
//return 0;
// Fail if not created.
// Standard show and update calls

ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return hWnd;
}

//----------------------------------------------------------------------
// TermInstance - Program cleanup
//
int TermInstance (HINSTANCE hInstance, int nDefRC)
{
return nDefRC;
}
//======================================================================
// Message handling procedures for main window
//
//----------------------------------------------------------------------
// MainWndProc - Callback function for application window
//
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = 0; i < dim(MainMessages); i++)
{
if (wMsg == MainMessages[i].Code)
return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}

//----------------------------------------------------------------------
// DoCreateMain - Process WM_CREATE message for window.
//
LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
HWND hwndCB;
// Create a command bar.
hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
// Add exit button to command bar.
CommandBar_AddAdornments (hwndCB, 0, 0);
return 0;
}

//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
// Adjust the size of the client rectangle to take into account
// the command bar height.
GetClientRect (hWnd, &rect);
rect.top += CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR));
hdc = BeginPaint (hWnd, &ps);
DrawText (hdc, TEXT ("Hello Windows CE!"), -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint (hWnd, &ps);
return 0;
}

//----------------------------------------------------------------------
// DoHibernateMain - Process WM_HIBERNATE message for window.
//
LRESULT DoHibernateMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
// If not the active window, nuke the command bar to save memory.
if (GetActiveWindow() != hWnd)
CommandBar_Destroy (GetDlgItem (hWnd, IDC_CMDBAR));
return 0;
}

//----------------------------------------------------------------------
// DoActivateMain - Process WM_ACTIVATE message for window.
//
LRESULT DoActivateMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
HWND hwndCB;
// If activating and no command bar, create it.
if ((LOWORD (wParam) != WA_INACTIVE) && (GetDlgItem (hWnd, IDC_CMDBAR) == 0))
{
// Create a command bar.
hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
// Add exit button to command bar.
CommandBar_AddAdornments (hwndCB, 0, 0);
}
return 0;
}

//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
PostQuitMessage (0);
return 0;
}


skyspark 2006-04-14
  • 打赏
  • 举报
回复
忘了怎么结帖了 呵呵
skyspark 2006-04-14
  • 打赏
  • 举报
回复
C
skyspark 2006-04-14
  • 打赏
  • 举报
回复
呵呵 搞定了 谢谢yzx0023(无聊客) 谢谢你的提示

窗口未注册
无聊客 2006-04-14
  • 打赏
  • 举报
回复
按照你的写法,你没有在窗口创建之前调用InitApp,所以你的窗口类没有注册
社会栋梁 2006-04-14
  • 打赏
  • 举报
回复
1407 :找不到窗口类别。
skyspark 2006-04-14
  • 打赏
  • 举报
回复
GetLastError 返回为1407
无聊客 2006-04-14
  • 打赏
  • 举报
回复
GetLastError,先看看错误返回是什么再做判断

19,502

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧