View Full Version : updown control problem
gizmo27
9th November 2009, 11:17
hi
I'm actually working on a soft with c++ and API WINDOWS
I have created an updown control following this (http://msdn.microsoft.com/en-us/library/bb759951%28VS.85%29.aspx)
so I've created the updown control into the WM_CREATE : hupdown=CreateWindowEx(
0,
UPDOWN_CLASS,
NULL,
WS_CHILD|WS_VISIBLE,
10+290,
10+163,
40,
40,
fenetrePrincipale,
(HMENU)ID_UPDOWN,
instance,
NULL);
after I use it into the WM_COMMAND like this :
UINT iId=LOWORD(wParam);
switch(iId)
{
(...)
case ID_UPDOWN:
{ MessageBox(fenetrePrincipale,lpMessage,"",MB_OK);
}
And when I click on the updown button nothing happens
It doesn't come from the params cause there's no warning for that.
I want to make an editbox buddy with my updown control : purpose : when I click up or down : increase or decrease a value into the editbox.
Have you got any idea about that ?
Thanks in advance.
mpucoder
9th November 2009, 16:48
To associate an updown with its buddy it is easier to use CreateUpDownControl
HWND CreateUpDownControl( DWORD dwStyle,
int x,
int y,
int cx,
int cy,
HWND hParent,
int nID,
HINSTANCE hInst
HWND hBuddy,
int nUpper,
int nLower,
int nPos
);
Also, when the control is pressed it creates a scroll event, either WM_VSCROLL or WM_HSCROLL (not a WM_COMMAND) which also reports the position as HIWORD(wParam).
The position of the control can also be read with the UDM_GETPOS message (position = SendMessage (hCntl, UDM_GETPOS, 0, 0);
gizmo27
9th November 2009, 23:02
I've already tested but this function doesn't work with OS 32-bits
only with 16 bits
those I find bizarre it's that when I write "CASE" : my updown control contains 2 buttons : up and down
how to make the difference if it's ID_UPDOWN : which one ? up or down ? that's the question
neuron2
9th November 2009, 23:16
how to make the difference if it's ID_UPDOWN : which one ? up or down ? that's the question As mpucoder says, the control returns the position. Store the current position and when you get a notification, if the new position is greater than the old one then it is up; if it is less then it is down. After deciding, save the new position for use in the next notification.
Often you can code things to just use the position and not really care whether it was up or down.
You can look at the source code for DGIndex, specifically for the Luminance dialog.
gizmo27
10th November 2009, 07:42
I got the DGIndex source but where is located the code that you talk about ?
dancho
10th November 2009, 09:37
@gizmo27
This is a small snipet just to show you basic updown control,
project is build with Pelle C (http://smorgasbordet.com/pellesc/) so its not C++ but I think you will not have any trouble understand it...
gizmo27
10th November 2009, 11:52
I don't want to compile
There's so much cpp file in the DGIndex source : just to know which file and which code if possible ?
Thanks in advance.
neuron2
10th November 2009, 14:39
It's the function Luminance() in the file gui.cpp. Here it is:
LRESULT CALLBACK Luminance(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
SendDlgItemMessage(hDialog, IDC_GAMMA_SPIN, UDM_SETRANGE, 0, MAKELPARAM(511, 1));
SendDlgItemMessage(hDialog, IDC_GAMMA_SPIN, UDM_SETPOS, 1, LumGamma + 256);
sprintf(szTemp, "%d", LumGamma);
SetDlgItemText(hDialog, IDC_GAMMA_BOX, szTemp);
SendDlgItemMessage(hDialog, IDC_OFFSET_SPIN, UDM_SETRANGE, 0, MAKELPARAM(511, 1));
SendDlgItemMessage(hDialog, IDC_OFFSET_SPIN, UDM_SETPOS, 1, LumOffset + 256);
sprintf(szTemp, "%d", LumOffset);
SetDlgItemText(hDialog, IDC_OFFSET_BOX, szTemp);
ShowWindow(hDialog, SW_SHOW);
if (Luminance_Flag)
SendDlgItemMessage(hDialog, IDC_LUM_CHECK, BM_SETCHECK, BST_CHECKED, 0);
return true;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_LUM_CHECK:
if (SendDlgItemMessage(hDialog, IDC_LUM_CHECK, BM_GETCHECK, 1, 0)==BST_CHECKED)
{
CheckMenuItem(hMenu, IDM_LUMINANCE, MF_CHECKED);
Luminance_Flag = true;
}
else
{
CheckMenuItem(hMenu, IDM_LUMINANCE, MF_UNCHECKED);
Luminance_Flag = false;
}
RefreshWindow(true);
break;
case IDCANCEL:
EndDialog(hDialog, 0);
return true;
}
break;
case WM_VSCROLL:
switch (GetWindowLong((HWND)lParam, GWL_ID))
{
case IDC_GAMMA_SPIN:
LumGamma = LOWORD(SendDlgItemMessage(hDialog, IDC_GAMMA_SPIN, UDM_GETPOS, 0,0)) - 256;
sprintf(szTemp, "%d", LumGamma);
SetDlgItemText(hDialog, IDC_GAMMA_BOX, szTemp);
break;
case IDC_OFFSET_SPIN:
LumOffset = LOWORD(SendDlgItemMessage(hDialog, IDC_OFFSET_SPIN, UDM_GETPOS, 0,0)) - 256;
sprintf(szTemp, "%d", LumOffset);
SetDlgItemText(hDialog, IDC_OFFSET_BOX, szTemp);
break;
}
RefreshWindow(true);
break;
}
return false;
}
gizmo27
10th November 2009, 23:08
ok thanks a lot : I'll take a look as soon as possible
Regards,
Gizmo.
mpucoder
16th November 2009, 17:35
I've already tested but this function doesn't work with OS 32-bits
That had me wondering for awhile, as I use CreateUpDownControl in 32-bit aps - then I found these lines in my project:
//to use controls like CreateUpDownControl
#pragma comment(lib, "comctl32.lib")
gizmo27
19th November 2009, 13:35
hi
about the updown control : is it possible and easy to realize a code which makes the updown act on 2 editbox in the same time ?
@neuron2 : you've said that to make the difference (for the program) between 'up' and 'down' when clicking : a way is to get the cursor position
what's the function a how to use it ? the (X,Y) position is always the same (same numbers) for all pc screens ?
gizmo27
19th November 2009, 14:49
on the msdn site I've see that the difference can be made with UDN_DELATAPOS
but how does it works ?
I've tried with 2 editbox but the updown control works only with 1 editbox : not 2 at the same time
neuron2
19th November 2009, 15:09
about the updown control : is it possible and easy to realize a code which makes the updown act on 2 editbox in the same time ? Yes. The spin button is not associated with any edit box. That's why you have to write the values yourself. So to affect two edit boxes just write to both of them and manage variables as required.
you've said that to make the difference (for the program) between 'up' and 'down' when clicking : a way is to get the cursor position
what's the function a how to use it ? the (X,Y) position is always the same (same numbers) for all pc screens ? Not the cursor position! When you instantiate the spin button, you define its range of possible values. When you get the position you get the current value in that range. It is not different for different PCs.
gizmo27
22nd November 2009, 14:50
hi
I made my code based on updown control
I create my updown in the WM_CREATE like that :
hupdown=CreateWindowEx(
0,
UPDOWN_CLASS,
NULL,
WS_CHILD|WS_VISIBLE|UDS_SETBUDDYINT,
10+290,
10+163,
40,
40,
fenetrePrincipale,
(HMENU)ID_UPDOWN,
instance,
NULL);
SendDlgItemMessage(
fenetrePrincipale,
ID_UPDOWN,
UDM_SETBUDDY,
(WPARAM)GetDlgItem(fenetrePrincipale, ID_EDITBOX_3),
0);
SendDlgItemMessage(
fenetrePrincipale,
ID_UPDOWN,
UDM_SETBUDDY,
(WPARAM)GetDlgItem(fenetrePrincipale, ID_EDITBOX_4),
0);
after in the WM_COMMAND I wrote the code :UINT iId=LOWORD(wParam);
switch(iId)
{
(...)
case ID_UPDOWN:
lpnmud = (LPNMUPDOWN) lParam; // I use UDN_DELTAPOS notification
if (lpnmud>0)
{
width = width + 16;
height = height + 16
}
else if (lpnmud<0)
{
width = width - 16;
height = height - 16
}
break;
and it doesn't work
dancho
22nd November 2009, 17:34
@gizmo27
not tested in live app,but it is something like this...
/* btw The UDN_DELTAPOS message is sent in the form of a WM_NOTIFY message */
case WM_NOTIFY:
{
NMHDR *pnmhdr=(LPNMHDR)lParam;
if( (pnmhdr->hwndFrom)==hupdown )
{
if( pnmhdr->code==UDN_DELTAPOS )
{
NM_UPDOWN *pnmupdown=(LPNMUPDOWN)lParam;
if( pnmupdown->iPos>0 )
{
}
else if( pnmupdown->iPos<0 )
{
}
}
}
break;
}
gizmo27
22nd November 2009, 19:05
ok thanks a lot
I'll try that and tell you
gizmo27
22nd November 2009, 21:39
in the code :
if( (pnmhdr->hwndFrom)==hupdown
what '->' means ?
neuron2
22nd November 2009, 22:13
pnmhdr is a pointer to an NMHDR structure so -> allows you to access one of the pointed-to structure's members. pnmhdr->hwndFrom gives you the hwndFrom member of the structure.
You use . when you have a structure instantiation and -> when you have a pointer to one.
In general, -> is a pointer dereference operation.
gizmo27
23rd November 2009, 10:09
hi all
I've put the action updown in the WM_NOTIFY
so I did in the WM_CREATE:hupdown=CreateWindowEx(
0,
UPDOWN_CLASS,
NULL,
WS_CHILD|WS_VISIBLE|UDS_SETBUDDYINT,
10+290,
10+163,
40,
40,
fenetrePrincipale,
(HMENU)ID_UPDOWN,
instance,
NULL);
SendDlgItemMessage(
fenetrePrincipale,
ID_UPDOWN,
UDM_SETBUDDY,
(WPARAM)GetDlgItem(fenetrePrincipale, ID_EDITBOX_3),
0);
SendDlgItemMessage(
fenetrePrincipale,
ID_UPDOWN,
UDM_SETBUDDY,
(WPARAM)GetDlgItem(fenetrePrincipale, ID_EDITBOX_4),
0);
after in the WM_NOTIFY I did :if (iId == ID_UPDOWN)
{
lpnmud = (LPNMUPDOWN) lParam;
if (lpnmud>0)
{
<instructions>
}
else if (lpnmud<0)
{
<instructions>
}
but it only acts into the EDITBOX_4 and not into the EDITBOX_3, more it doesn't react as myincrementations/decrementations
neuron2
23rd November 2009, 14:50
lpnmud is a pointer so you have to dereference it.
if (lpnmud->iDelta > 0)
For the buddy issue check the error from the call to get the edit box handle.
dancho
23rd November 2009, 15:14
@gizmo27
ok,this is basic updown control with custom (int&float) inc/dec values...
gizmo27
24th November 2009, 01:13
yes it works : thanks Dancho
you don't need UDM_SETBUDDYINT
it works without
so I've addedsprintf(bufw, "%d", width); SendDlgItemMessage(fenetrePrincipale,ID_EDITBOX_3,WM_SETTEXT,0,(LPARAM)bufw);
sprintf(bufh, "%d", height); SendDlgItemMessage(fenetrePrincipale,ID_EDITBOX_4,WM_SETTEXT,0,(LPARAM)bufh);
and it works now
Thanks a lot all for your help.
Regards,
Gizmo.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.