主题:Panel.cpp:文件
Panel.cpp:
#include "Panel.h"
//#include <commctrl.h>
#define DEBUG 0
void error(void)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox( NULL, (char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
}
Panel::Panel(HWND tmpParent)
:WndParent(tmpParent)
{
WinClassName = "Panel";
}
void Panel::CreateHandle(void)
{
// InitCommonControls();
RECT tmpRect;
GetWindowRect(WndParent, &tmpRect);
X = tmpRect.left;
Y = tmpRect.top;
Width = static_cast<int>((tmpRect.right - tmpRect.left) * 0.3);
Height = tmpRect.bottom - tmpRect.top;
/* if (GetClassInfoEx(hInstance, WinClassName, &wincl))
{
error();
}
else
{
error();
}
*/
wincl.hInstance = hInstance;
wincl.lpszClassName = WinClassName;
wincl.lpfnWndProc = WndProce;
wincl.style = 0,//CS_VREDRAW + CS_HREDRAW + CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (hInstance, IDI_APPLICATION);
wincl.hCursor = LoadCursor (hInstance, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_ACTIVEBORDER;
Style = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP | WS_BORDER ;
ExStyle = WS_EX_CONTROLPARENT | WS_EX_CLIENTEDGE;
RegisterClassEx (&wincl);
#ifdef DEBUG
error();
#endif
Fhadle = CreateWindowEx (
ExStyle, /* Extended possibilites for variation */
WinClassName, /* Classname */
"Windows", /* Title Text */
Style, /* default window */
X, /* Windows decides the position */
Y, /* where the window ends up on the screen */
Width, /* The programs width */
Height, /* and height in pixels */
Fhadle, /* The window is a child-window to desktop */
NULL, /* No menu */
hInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
#ifdef DEBUG
error();
#endif
ShowWindow (Fhadle, SW_SHOW);
}
void Panel::SetColor(COLORREF tmpColor)
{
Color = tmpColor;
}
void Panel::SetXY(int tmpX, int tmpY)
{
X = tmpX;
Y = tmpY;
}
void Panel::SetWidth(int tmpW, int tmpH)
{
Width = tmpW;
Height = tmpH;
}
void Panel::SetWndP(WinPro tmp)
{
WndProce = tmp;
}
Panel::~Panel()
{
}
结果会说系统找不到指定的文件和无效句柄,但是在 Winmain函数中就能注册成功,那位高人解释一下怎么回事?
#include "Panel.h"
//#include <commctrl.h>
#define DEBUG 0
void error(void)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox( NULL, (char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
}
Panel::Panel(HWND tmpParent)
:WndParent(tmpParent)
{
WinClassName = "Panel";
}
void Panel::CreateHandle(void)
{
// InitCommonControls();
RECT tmpRect;
GetWindowRect(WndParent, &tmpRect);
X = tmpRect.left;
Y = tmpRect.top;
Width = static_cast<int>((tmpRect.right - tmpRect.left) * 0.3);
Height = tmpRect.bottom - tmpRect.top;
/* if (GetClassInfoEx(hInstance, WinClassName, &wincl))
{
error();
}
else
{
error();
}
*/
wincl.hInstance = hInstance;
wincl.lpszClassName = WinClassName;
wincl.lpfnWndProc = WndProce;
wincl.style = 0,//CS_VREDRAW + CS_HREDRAW + CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (hInstance, IDI_APPLICATION);
wincl.hCursor = LoadCursor (hInstance, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_ACTIVEBORDER;
Style = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP | WS_BORDER ;
ExStyle = WS_EX_CONTROLPARENT | WS_EX_CLIENTEDGE;
RegisterClassEx (&wincl);
#ifdef DEBUG
error();
#endif
Fhadle = CreateWindowEx (
ExStyle, /* Extended possibilites for variation */
WinClassName, /* Classname */
"Windows", /* Title Text */
Style, /* default window */
X, /* Windows decides the position */
Y, /* where the window ends up on the screen */
Width, /* The programs width */
Height, /* and height in pixels */
Fhadle, /* The window is a child-window to desktop */
NULL, /* No menu */
hInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
#ifdef DEBUG
error();
#endif
ShowWindow (Fhadle, SW_SHOW);
}
void Panel::SetColor(COLORREF tmpColor)
{
Color = tmpColor;
}
void Panel::SetXY(int tmpX, int tmpY)
{
X = tmpX;
Y = tmpY;
}
void Panel::SetWidth(int tmpW, int tmpH)
{
Width = tmpW;
Height = tmpH;
}
void Panel::SetWndP(WinPro tmp)
{
WndProce = tmp;
}
Panel::~Panel()
{
}
结果会说系统找不到指定的文件和无效句柄,但是在 Winmain函数中就能注册成功,那位高人解释一下怎么回事?