/*类mNewButton的构造函数*/
static void mNewButton_construct(mNewButton *self, DWORD param)
{
Class(mWidget).construct((mWidget*)self, param);
}
/*类mNewButton的onLButtonDow和onLButtonUp函数,其作用是接收鼠标事件,并通知父窗口。*/
static int mNewButton_onLButtonDown (mNewButton* self, int x, int y, DWORD keyFlags)
{
SetCapture (self->hwnd);
self->status = BTN_PUSHED;
InvalidateRect(self->hwnd, NULL, TRUE);
return 0;
}
static int mNewButton_onLButtonUp (mNewButton* self, int x, int y, DWORD keyFlags)
{
if (GetCapture() == self->hwnd){
self->status = BTN_NORMAL;
InvalidateRect(self->hwnd, NULL, TRUE);
ReleaseCapture ();
ncsNotifyParent((mWidget*)self, NCSN_NEWBTN_PUSHED);
}
}
/*类mNewButton onPaint的处理函数,其作用是根据button的不同状态,显示不同的图片*/
static void mNewButton_onPaint (mNewButton *self, HDC hdc, const PCLIPRGN pinv_clip)
{
RECT rect;
GetWindowRect (self->hwnd, &rect);
switch (self->status){
case BTN_NORMAL:
FillBoxWithBitmap (hdc, 0, 0, RECTW(rect),
RECTH(rect), self->bmp_nor);
break;
case BTN_PUSHED:
FillBoxWithBitmap (hdc, 0, 0, RECTW(rect),
RECTH(rect), self->bmp_up);
break;
}
}
/*类mNewButton setProperty的处理函数,其作用是加载图片,并将其显示出来。*/
static BOOL mNewButton_setProperty (mNewButton *self, int id, DWORD value)
{
char *str;
if (id > NCSP_NEWBTN_MAX){
return FALSE;
}
str = (char*)value;
switch (id){
case NCSP_NEWBTN_IMAGE_NORMAL:
self->bmp_nor = LoadBitmapFromRes (HDC_SCREEN, str);
if (self->bmp_nor == NULL){
printf ("Cant load %s\n ", str);
return 1;
}
break;
case NCSP_NEWBTN_IMAGE_DOWN:
self->bmp_up = LoadBitmapFromRes (HDC_SCREEN, str);
if (self->bmp_up == NULL){
printf ("Cant load %s\n ", str);
return 1;
}
break;
}
InvalidateRect(self->hwnd, NULL, TRUE);
return Class(mWidget).setProperty((mWidget*)self, id, value);
}
/*类mNewButton 在销毁的时候使用的destroy函数,其作用是释放使用的图片资源*/
static void mNewButton_destroy(mNewButton *self)
{
ReleaseRes (Str2Key (self->bmp_nor));
ReleaseRes (Str2Key (self->bmp_up));
}
/*类mNewButton onCreate的处理函数,其作用是将button的status置为BTN_NORMAL*/
static BOOL mNewButton_onCreate (mNewButton *self, LPARAM lParam)
{
self->status = BTN_NORMAL;
}