June 20th, 2012, 05:09 AM
#1
MOVEMOUSE event!
Env: Win32 (Visual C++)
I'm using WM_MOUSEMOVE to change a button (using STATIC with SS_BITMAP) so that when the mouse is hovering at the button it change from Default.bmp to Hover.bmp. I manage to compile and the program is running, but the button doesn't change sometime.
Any solution and hel, will be great. Thanks.
P.S Sorry for my bad english
Code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
flashMWindow.cbSize = sizeof(flashMWindow);
flashMWindow.dwFlags = FLASHW_ALL;
flashMWindow.dwTimeout = 250;
flashMWindow.hwnd = hWnd;
flashMWindow.uCount = 4;
static BOOL Click, BtnConnectClick, BtnConnectHover, BtnConnectChange;
switch (message)
{
case WM_CREATE:
FlashWindowEx(&flashMWindow);
ConnectionButton = CreateWindowEx (NULL, _T("STATIC"), TEXT (""),
WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_BITMAP,
10, 400, 140, 40,
hWnd, (HMENU) IDC_CONNECTION, GetModuleHandle(NULL), NULL) ;
LoadImage();
InvalidateRect(hWnd,NULL,true);
break;
/*
case WM_LBUTTONDOWN :
if ((LOWORD(lParam)>=10)&&(LOWORD(lParam)<=150)&&(HIWORD(lParam)>=400)&&(HIWORD(lParam)<=440))
{
BtnConnectClick = TRUE;
}
else
{
BtnConnectClick = FALSE;
}
Click = TRUE ;
InvalidateRect(hWnd,NULL,false);
break;
*/
case WM_MOUSEMOVE:
if ((LOWORD(lParam)>=10)&&(LOWORD(lParam)<=150)&&(HIWORD(lParam)>=400)&&(HIWORD(lParam)<=440))
{
BtnConnectHover = TRUE;
}
else
{
BtnConnectHover = FALSE;
}
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hWnd;
TrackMouseEvent(&tme);
InvalidateRect(hWnd,NULL,false);
return 0;
/*
case WM_LBUTTONUP :
if (Click)
{
if ((LOWORD(lParam)>=10)&&(LOWORD(lParam)<=150)&&(HIWORD(lParam)>=400)&&(HIWORD(lParam)<=440))
{
if (BtnConnectClick)
{
BtnConnectChange = 1;
if (Connection == Disconnect)
{
Connection = Connect;
}
else
{
Connection = Disconnect;
}
}
}
}
Click = FALSE;
InvalidateRect (hWnd, NULL, TRUE);
break;
*/
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CONNECTION:
if (Connection == Disconnect)
{
Connection = Connect;
}
else
{
Connection = Disconnect;
}
break;
}
InvalidateRect(hWnd,NULL,false);
break;
case WM_KEYDOWN:
{
if (wParam == VK_ESCAPE)
{
int ret = MessageBox(NULL, TEXT("Are you sure to quit?"), TEXT("Message"), MB_OKCANCEL);
if ( ret == IDOK)
{
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
}
break;
}
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
MemDC = CreateCompatibleDC(hDC);
SelectObject(MemDC,bmp[0]);
BitBlt(hDC,0,0,800,450,MemDC,0,0,SRCCOPY);
DeleteDC(MemDC);
EndPaint(hWnd, &ps);
//Paint Connection Button
if(BtnConnectHover == FALSE)
{
if (Connection == 0)
{
cn = 1;
}
else
{
cn = 3;
}
}
if(BtnConnectHover == TRUE)
{
if (Connection == 0)
{
cn = 2;
}
if (Connection == 1)
{
cn = 4;
}
}
hDC = BeginPaint(ConnectionButton, &ps);
MemDC = CreateCompatibleDC(hDC);
SelectObject(MemDC,bmp[cn]);
BitBlt(hDC,0,0,140,40,MemDC,0,0,SRCCOPY);
DeleteDC(MemDC);
EndPaint(ConnectionButton, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
void LoadImage()
{
bmp[0]=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BG));
bmp[1]=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_DefaultConnect));
bmp[2]=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_HoverConnect));
bmp[3]=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_DefaultDisconnect));
bmp[4]=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_HoverDisconnect));
}
June 21st, 2012, 08:58 PM
#2
Re: MOVEMOUSE event!
You are painting on the child window (i.e., the static window) from the WM_PAINT of the parent. That's usually poor practice; the child window should do all of its own painting, in response to WM_PAINT messages sent to the child.
In addition, you are calling BeginPaint and EndPaint twice. They should be called only once in any one WM_PAINT procedure.
Mike
June 24th, 2012, 08:03 PM
#3
Re: MOVEMOUSE event!
Thx Mike, it's all done now.
Julius
June 25th, 2012, 01:10 PM
#4
Re: MOVEMOUSE event!
Originally Posted by
Cung2_91
Env: Win32 (Visual C++)
I'm using WM_MOUSEMOVE to change a button (using STATIC with SS_BITMAP )
STM_SETIMAGE message
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks