I know this isn't exactly a game, but I don't know any win32 specific forums, so here goes:
I'm trying to make a music/movie player. I need to have some sort of slider to display where you are in the movie or music, so i'm making one, only i'm have a problem with WM_LBUTTONDOWN.
My control doesn't detect it. But it does detect WM_NCLBUTTONDOWN (this is supposed to be sent when you aren't clicking on the client area of the control, right?), but only when you click on the control not in the window area. I don't know how to fix it...
heres my control code:
class SLIDER {
public:
//functions to initialize slider
SLIDER(bool i);
//functions for callback func
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT paint(WPARAM wParam, LPARAM lParam);
private:
//variables to control control
HWND hwnd; //you never know when you might need it
COLORREF bg; //the background
COLORREF Scol; //color of the slider
float pos; //position (percentage) of the slider
RECT rect;
}; //classes need semi colons at the end =)
SLIDER::SLIDER(bool i) {
if (i != false) {
WNDCLASSEX wc;
//fill it in
wc.cbSize = sizeof(wc);
wc.lpszClassName = "slider";
wc.hInstance = GetModuleHandle(0);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = 0;
wc.lpszMenuName = 0;
wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(SLIDER);
wc.hIconSm = 0;
//now register
RegisterClassEx(&wc);
}
}
LRESULT SLIDER::paint(WPARAM wParam, LPARAM lParam) {
HDC dc;
PAINTSTRUCT ps;
int x;
dc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
//drawing here
x = rect.left + ((rect.right - rect.left) * (pos / 100));
Rectangle(dc, x - 10, rect.top, x + 10, rect.bottom);
EndPaint(hwnd, &ps);
return 0;
}
/*-----------------------------Window Procedure------------------------------------*/
LRESULT CALLBACK SLIDER::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
//memory variable
SLIDER* memory = (SLIDER *)GetWindowLong(hwnd, 0);
switch (message) {
case WM_NCCREATE:
memory = new SLIDER(false);
SetWindowLong(hwnd, 0, (LONG)memory);
//fill in default vars
memory->hwnd = hwnd;
memory->bg = RGB(10, 20, 30);
memory->Scol = (COLORREF)20;
memory->pos = 50;
return (memory != NULL);
case WM_PAINT:
return memory->paint(wParam, lParam);
case WM_LBUTTONUP:
memory->pos += 1;
InvalidateRect(hwnd, &memory->rect, false);
UpdateWindow(hwnd);
return 0;
case WM_ERASEBKGND:
//prevent flicker
return 1;
default:
DefWindowProc(hwnd, message, wParam, lParam);
}
}
/*---------------------------------End----------------------------------------------*/
SLIDER slide(true);
heres the bit where i use it:
#include "resource.h"
#include <windows.h>
#include <stdio.h>
#include "controls.h"
#include "wrapper.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
static HWND slider;
switch(message) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case menu_exit:
exit(0);
}
case WM_CREATE:
slider = CreateWindowEx(
WS_EX_CLIENTEDGE,
"slider",
"slider",
WS_VISIBLE | WS_CHILD,
0, 0,
100, 100,
hwnd, NULL, GetModuleHandle(0), NULL);
if (slider == NULL) {
MessageBox(NULL, "hello", "bs", MB_OK);
}
break;
case WM_SIZE:
SetWindowPos(slider, NULL, 0, HIWORD(lParam) - 20, LOWORD(lParam), 20, NULL);
break;
case WM_CLOSE:
exit(0);
default:
DefWindowProc(hwnd, message, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmd, int show) {
if (!win.MakeWindow("MPLAY", hInstance, 200, 200)) {
return 0;
}
win.ShowWin(show);
while(GetMessage(&win.message, NULL, 0, 0) > 0) {
TranslateMessage(&win.message);
DispatchMessage(&win.message);
}
}
any help would be much appreciated.
Edit: please use source tags for large portions of code - .ED
[Edited by - Emmanuel Deloget on March 2, 2007 4:01:57 AM]