|
I'm getting a bad value when doing a drag-right-click ( doing a selection with the right mouse button) in a CTreeCtrl.
This is the callback for the NM_RCLICK notification.
void CAboutDlg::OnTreeRclick( NMHDR* pNMHDR, LRESULT* pResult )
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
HTREEITEM hSelItem = pNMTreeView->itemNew.hItem;
if ( hSelItem == NULL )
{
return;
}
}
Sometimes, the hSelItem tree item is not a valid item ( for example : 0x0000008d ) which is not valid.
I alse tried this where ptDrag is supposed to be the "structure that contains the client coordinates of the mouse at the time the event occurred that caused the notification message to be sent. (from MSDN) "
CPoint point( pNMTreeView->ptDrag );
UINT uHF;
HTREEITEM hItem;
hItem = m_Tree.HitTest( point, &uHF );
But the point is mostly invalid.
I also use which works, but seems not to be the right way to do it.
UINT uHF;
HTREEITEM hItem;
CPoint point;
GetCursorPos( &point );
m_Tree.ScreenToClient( &point );
hItem = m_Tree.HitTest( point, &uHF );
Thanks for you help and/or suggestions.
Max.
|
|
|
|
|
Some of the tree notifications don't set the itemNew element in the NM_TREEVIEW structure. As a result, it can be filled with random garbage.
Another thing to remember is that the right click notification happens whenever you right click on the tree control. If you're doing that over an area that doesn't include an item, you'll need to detect that.
IIRC, the last time I did this kind of stuff with a tree control, I ended up with a similar approach.
Sorry I'm not giving you more definite answers here. I'm working from memory, and don't have access to the code where I was dealing with this stuff.
Software Zen: delete this;
|
|
|
|
|
I tried to export a static member in one of my classes.
All other methods and operators of the same class can be successfully exported and then linked by another program excepte all static data member(declared as public static const in .hpp and implemented in .cpp, according to msdn guild on the dllexport part, it should work). I wonder why?
I am not the 1st one who's suffering from this, I did a simple research with google, some other guys also had this kind of problem and posted it on the web but never got a response.
Hopefully some one here could help me out, thanks.
|
|
|
|
|
Btw, by "unable to export" I mean the program can be compiled but get a link error generated.
|
|
|
|
|
Hello,
For a CDBVariant MFC class, how do I assign value to an object of type CDBVariant?
If
CDBVariant V;
V.m_dwtype = DBVT_SHORT;
V.m_iVal = 5;
Is this the right way to do ?
Priya
|
|
|
|
|
Does anyone know what happens when you have a socket bound to INADDR_ANY and then have a second socket (both TCP or both UDP sockets) bound to a specific address?
I am trying to add something to an existing program that has a TCP socket bound to INADDR_ANY. I need to add a TCP socket that listens to 127.5.0.1 (within the same executable). Will messages sent to 127.5.0.1 be handled by my new socket or will everything go through the existing socket bound to INADDR_ANY?
I guess I can check the address on the existing socket and handle the messages based on that but I'd still like to understand how this works.
Thanks,
Dave
|
|
|
|
|
INADDR_ANY indicates that the caller to bind() doesn't care what address the socket is bound
to. Typically this is used on client ends of TCP connections to let the system select an
unused port.
If you want to listen on a specific address/port then you have to bind to that specific
address.
Dave_ wrote: I need to add a TCP socket that listens to
What do you mean by "listens to"? This is very different on TCP and UDP.
|
|
|
|
|
When I use the listen() call, which socket (or will it be both?) will get the attempt to connect from the client? If I try to recv(), will the socket that is bound to the specific address get the data or will there be a race condition (first socket to read gets the data)?
|
|
|
|
|
A socket address consists of an address and a port.
listen() would be used on a connection-oriented protocol (like TCP) socket. You need to
create a socket to listen on and bind it to a specific address to listen on. Once a socket is
placed in the listen state you don't recv data on it. You receive connection attempts on it.
Accepting a connection creates a new, connected socket which will be used for send/recv of
data.
For UDP, which is connectionless, you'd create a socket and bind it to an address. Then you
can either use connect to set a default destination address on it and/or use sendto/recvfrom to
send and receive datagrams to/from multiple destination addresses.
Only one socket per protocol can be bound to a specific address so there's never a race
condition.
|
|
|
|
|
Not sure what your trying to do.
Normally you use INADDR_ANY to bind the socket to the IP address of your PC, which normally only has one IP address.
If you want multiple server sockets, you normally use INADDR_ANY for the IP and a different address for the port of each server. For example
Server 1
ServerAddress.sin_family = AF_INET;
ServerAddress.sin_addr.s_addr = INADDR_ANY;
ServerAddress.sin_port = htons((u_short)27015);
if(bind(ServerSocket, (struct sockaddr*)&ServerAddress, sizeof(ServerAddress)) != 0)
.........
Server 2
ServerAddress.sin_family = AF_INET;
ServerAddress.sin_addr.s_addr = INADDR_ANY;
ServerAddress.sin_port = htons((u_short)27016);
if(bind(ServerSocket, (struct sockaddr*)&ServerAddress, sizeof(ServerAddress)) != 0)
..........
Then the clients will send to port 27015 for server 1 and port 27016 for server 2. You
can definitely substitute
service.sin_addr.s_addr = inet_addr("127.5.0.1");
if you want to specify and exact IP address
|
|
|
|
|
I have compiled VC project which was created using VC compiler of version older than 6.0. There are some C files which if I change extension to .cpp many errors are happening. So I would like to keep those files .c and I want to read numbers from .CSV file and store in array.
Is it possible to read CSV file from .C file?
Any ideas would be greatly appreciated.
Thanks & Regards,
Suman
|
|
|
|
|
rp_suman wrote: Is it possible to read CSV file from .C file?
Certainly.
Which part are you having trouble with?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I want to read the numbers in csv file, cell by cell and assign it to the int array variable. The number count is not fixed. Which function is good for doing this.
Thanks & Regards,
Suman
|
|
|
|
|
rp_suman wrote: ...the numbers in csv file, cell by cell...
Files don't have cells.
There are several ways to do this, some better than others. One such way, although not very bullet-proof, is:
int num[25][3];
int x = 0;
FILE *pFile = fopen();
while (! feof(pFile))
{
fscanf(pFile, "%d,%d,%d\n", &num[x][0], &num[x][1], &num[x][2]);
x++;
} You can quickly see how this would not work too well if the file size changed. There are other solutions to address this, however.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks a lot for your help!!
I had confidence when I saw your first reply "Certainly.." and did before your code help.
But thanks again for your help!!
Best Regards,
Suman
|
|
|
|
|
rp_suman wrote: s it possible to read CSV file from .C file?
Any ideas would be greatly appreciated.
csv is nothing .. it is comma separated file .. you just have to implement logic to extract data from comma separated file
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Hello everybody,
In the OnSize-Function, i retrieve the changed Width-Value and changed Height-Value.
then i perform this :
//new position for the Bar
Bar.GetWindowRect(WSize);
ScreenToClient(WSize);
Bar.SetWindowPos(NULL,0,0,(WSize.right - WSize.left),(WSize.bottom - WSize.top)+ChangeY,SWP_NOZORDER | SWP_NOACTIVATE);
//new position for the Tab
Tab->GetWindowRect(WSize);
ScreenToClient(WSize);
Tab->SetWindowPos(NULL,182,3,(WSize.right - WSize.left)+ChangeX,(WSize.bottom - WSize.top)+ChangeY,SWP_NOZORDER | SWP_NOACTIVATE);
if i perform the first SetWindowPos, a new Event is launched directly which provokes some
problems
How can i change the position of these 2 controls and not re-enter in the OnSize?
Thanks
|
|
|
|
|
|
Thanks for your help
The help says me, thats exact what i'm looking for.
But it doesn't work :S
Bar.SetWindowPos(NULL,0,0,(WSize.right - WSize.left),(WSize.bottom - WSize.top)+ChangeY,SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
it steps into it, than before the rest of the OnSize-Code is be executed, he steps at new to this line.
After it, he steps 2 times to the rest of the code.
|
|
|
|
|
baerten wrote: it steps into it, than before the rest of the OnSize-Code is be executed, he steps at new to this line.
After it, he steps 2 times to the rest of the code.
I'm sorry, but I really can't understand your meaning.
You are positioning the windows from your OnSize handler. Here's how it works internally.
When the main window moves or changes a WM_WINDOWPOSCHANGING message is sent, after this a WM_WINDOWPOSCHANGED is sent. During the message, DefWindowProc() detects if the size or position has changed then sends WM_SIZE and/or WM_MOVE .
If you want to move child windows around, it would be better for you to overide OnWindowPosChanging Calculate your new size and position then call SetWindowPos() with the SWP_NOSENDCHANGING flag. This way your controls will be moved/positioned before the main window.
|
|
|
|
|
I have a MDI Child.
In the View i have this "OnSize"-Handler
I always want to resize 2 controls on the view. If the View is getting greater, the controls increase also.
UniView::OnSize(nType, cx, cy);
CRect WSize;
this->GetWindowRect(WSize);
ScreenToClient(WSize);
if(OldSize.top != -9999 && canSize) {
// Calculates the changings
int ChangeX = (WSize.right - WSize.left) - (OldSize.right - OldSize.left);
int ChangeY = (WSize.bottom - WSize.top) - (OldSize.bottom - OldSize.top);
//BAR
Bar.GetWindowRect(WSize);
ScreenToClient(WSize);
// Adds the Difference to the Height -> The bar changes only in height
Bar.SetWindowPos(NULL,0,0,(WSize.right - WSize.left),(WSize.bottom -
WSize.top)+ChangeY,SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING); ( A )
//TAB
//Tab->GetWindowRect(WSize);
//ScreenToClient(WSize);
//Tab->SetWindowPos(NULL,182,3,(WSize.right - WSize.left)+ChangeX,(WSize.bottom -
WSize.top)+ChangeY,SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
}
this->GetWindowRect(WSize); ( B )
ScreenToClient(WSize);
OldSize= WSize;
// Saves the current Size of the View, ( used to compare with the new size next time )
if i place a breakpoint to A and B it stops as follows
A,A,B,B ... if the line (A) is executed, it steps at new on (A), before it reaches (B)
Or does it exist a easier way to fit the controls ?
Thanks
|
|
|
|
|
Hi
I have some (probably) basic questions about CToolbar class, just point me somewhere (article, code or just general idea)
How to change button's position? - I would like to move them closer, without a single pixel of free space between. (or just 2 pixels right and bottom for 'press' effect)
How to disable this square box around button's bitmap when I hover/press the button?
And finally what message/base class member function should I override to make my bitmaps transparent? I have already handled WM_ERASEBKGND message but now my buttons have plain background instead of a bitmap. I've seen some articles about it but the solutions are not so simple (many lines of code, message handlers ect.) Is there a simple way how to draw CBitmap 24bit bitmap on a CToolBar control? Assuming some transparency RGB value in my input bitmap?? (Let's assume Windows 2000+ environment)
Thanks in advance!
|
|
|
|
|
First - Toolbar Controls Overview[^]
PatrykDabrowski wrote: How to change button's position? - I would like to move them closer, without a single pixel of free space between. (or just 2 pixels right and bottom for 'press' effect)
A combination of TB_SETMETRICS message to set button spacing and using separators between
buttons will help for custiomizing spacing.
PatrykDabrowski wrote: How to disable this square box around button's bitmap when I hover/press the button?
Use image lists to have control over button images.
PatrykDabrowski wrote: And finally what message/base class member function should I override to make my bitmaps transparent?
This has nothing to do with WM_ERASEBKGND (actually toolbars have the TBSTYLE_TRANSPARENT style
so you don't have to do that). For the button images you need to use a masked image list with
the mask created using a certain color in the bitmap that represents transparent.
For example, this code takes a 24bit source bitmap resource and creates a masked image list
from it, using bright green as the transparent color...
CBitmap bitmap;
bitmap.LoadBitmap(IDB_TOOLBARBITMAP);
m_ToolBarImageList.Create(32, 32, ILC_COLOR24|ILC_MASK, 2, 1);
m_ToolBarImageList.Add(&bitmap, RGB(0x00,0xFF,0x00));
When the toolbar is created set its image list to the image list created above:
static TBBUTTON ToolBarButtonDescs[] =
{
{0, ID_BUTTON1, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0},
{1, ID_BUTTON2, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0}
};
m_ToolBar.CreateEx(this, TBSTYLE_FLAT);
m_ToolBar.SetSizes(CSize(39,38), CSize(32,32));
m_ToolBar.GetToolBarCtrl().SetImageList(&m_ToolBarImageList);
m_ToolBar.GetToolBarCtrl().AddButtons(2, ToolBarButtonDescs);
|
|
|
|
|
Thanks for help but it seems not working for me... But first, my second question. I was asking how to disable this square "3d-like" frame around my buttons. Image lists do not solve this problem because they are 32x32 pixel and this box is bigger, about 38x38 pixels.
I have partialy solved this problem by this code:
void CToolBarEx::OnTbnHotItemChange(NMHDR *pNMHDR, LRESULT *pResult)
{
*pResult = (1-m_bHoverMouse); //0=no change;1=no box around buttons
}
and now, when I move the mouse over buttons, this box is not drawn but when I press the button it is still there...How to disable it completly??
To my last question, I have almost copy-pasted Your code to my app but the buttons are still opaque. I have a transparent color RGB(255,0,255) in my bitmap containing 6 buttons (192x32 24bit bitmap). Now the transparent color is not directly drawn but replaced by the plain gray (background) color. That would be fine, but I have a background bitmap?!?
Maybe the way I'm drawing my background bitmap is wrong??? The drawing code is:
BOOL CToolBarEx::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect); //toolbar rect
CBrush *m_brOld = NULL; //Old brush
m_brOld = pDC->SelectObject(&m_bgBrush); //load my background brush
pDC->FillRect(&rect,&m_bgBrush); //fill the whole toolbar
pDC->SelectObject(m_brOld); //restore original brush
return TRUE;
}
Maybe I should save somehow this brush into the toolbar's DC for proper background drawing when the control draw its buttons?? How to "tell" the control to use bitmap/brush to draw its background??
Thanks again I'm waiting for Your response...
|
|
|
|
|
PatrykDabrowski wrote: I was asking how to disable this square "3d-like" frame around my buttons. Image lists do not solve this problem
because they are 32x32 pixel and this box is bigger, about 38x38 pixels.
The closest I think you'll get is using the TBSTYLE_FLAT style. But you'll still see the hot-
track, 3d button outline indication.
The buttons are 7 pixels wider and 6 pixels higher than the bitmaps. I tested to see if this
could be changed but the system defaulted them.
OnEraseBkgnd is fine but the buttons are not drawn transparently. The images on the buttons are.
This is the behavior of the toolbar control. The 3d box around buttons indicates to the user
that it's a button.
You could use the TBSTYLE_CUSTOMERASE style and respond to NM_CUSTOMDRAW messages. In the passed
NMTBCUSTOMDRAW struct there's a NMCUSTOMDRAW struct member that you can look at to see if a button
is about to be drawn hot and if so, change the state to normal so it gets drawn normally.
You could also draw the buttons yourself.
It sounds like you may just need to transparently draw images on a background and respond to
clicks within the images. Maybe that's a viable alternative route as well(?)
Mark
|
|
|
|
|