跪求解答。。。孙鑫书上的例子(窗口,窗口类和窗口类对象之间的关系)
#include <windows.h>
#include <stdio.h>
/*
LRESULT CALLBACK WinLiuProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
*/
class CWnd
{
public:
BOOL CreateEx(DWORD dwExStyle,LPCTSTR lpClassName,LPCTSTR lpWindowName,DWORD dwStyle,int x, int y,
int nWidth,int nHeight,HWND hWndParent,HMENU nMenu,HINSTANCE hInstance,
LPVOID lpParam);
public :
BOOL ShowWindow(int nCmdShow);
BOOL UpdateWindow();
HWND m_hwnd;
};
BOOL CWnd::CreateEx(DWORD dwExStyle,LPCTSTR lpClassName,LPCTSTR lpWindowName,DWORD dwStyle,int x, int y,
int nWidth,int nHeight,HWND hWndParent,HMENU nMenu,HINSTANCE hInstance,
LPVOID lpParam)
{
m_hwnd=::CreateWindowEx(dwExStyle, lpClassName,lpWindowName,dwStyle,x,y,nWidth,
nHeight,hWndParent,nMenu,hInstance,lpParam );
if(m_hwnd!=NULL)
return TRUE;
else
return FALSE;
}
BOOL CWnd::ShowWindow(int nCmdShow)
{
return ::ShowWindow (m_hwnd,nCmdShow);
}
BOOL CWnd::UpdateWindow()
{
return ::UpdateWindow(m_hwnd);
}
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor =LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
wndclass.hCursor=LoadCursor((HINSTANCE) NULL, IDC_ARROW);
wndclass.hInstance=hInstance;
// wndclass.lpfnWndProc =WinLiuProc;
wndclass.lpszClassName = "GT.TOM ";
wndclass.lpszMenuName= "NULL ";
wndclass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndclass);
//////////////////////////////////////////////////////////////////////////
CWnd wnd;
wnd.CreateEx(WS_EX_CLIENTEDGE, "GT.TOM ", "liugt ",WS_BORDER,50, 50,
600,400,NULL ,NULL ,hInstance,NULL);
wnd.ShowWindow(SW_SHOWNORMAL);
wnd.UpdateWindow();
//////////////////////////////////////////////////////////////////////////
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
/*HWND hwnd;
hwnd=CreateWindowEx();
::ShowWindow(hwnd,SW_SHOWNORMAL);
::UpdateWindow(hwnd);
*/
}
任务栏管理器中WinMain.exe有运行,但为什么窗口不显示呢?跪求解答。。。
[解决办法]
你明显是象写一个api的程序 那为什么又要加上 CWND 的东西在里面呢。。
就简单使用createWindow()就可以了 为什么使用这段代码:CWnd wnd;
wnd.CreateEx(WS_EX_CLIENTEDGE, "GT.TOM ", "liugt ",WS_BORDER,50, 50,
600,400,NULL ,NULL ,hInstance,NULL);
wnd.ShowWindow(SW_SHOWNORMAL);
wnd.UpdateWindow();
把这段代码换成正常API的,加入你上面注册的窗口类的数据填写的参数,肯定就可以了。
[解决办法]
或者你打开VC 新键项目时选择 window32 application ,然后选择一个简单的hello world程序。
然后查看里面的创建窗口的代码,你就知道怎么写了。
窗口是显示在显示器上的(对应于内存的数据)的一个框框; 窗口类是在系统中注册的一个窗口类别,用这个系统注册用的窗口类别去创建一个窗口。 窗口类对象。。。这个词好别扭;
注意API里是没有类的。窗口类 指的不是c++的class 而是在系统里注册了的一个东西而已。相当于数据类型吧(晕,真蹩脚),就象struct一样。。
郁闷 不说了。哪来这么多概念,编程序 道理懂了就行, 没概念之说。
想到那些面向对象的书一上来花一两章吹面向对象的好处就烦。咕隆玄虚。