|
If you pass a pointer then changing the value locally will change it in the calling function as well. Wheren't you using a reference to a pointer ? Removing the & in that case will work fine.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I am trying to implement an AppBar that displays a set of
toolbars (CToolBar) in differing arrangement depending on
whether it is floating or docked to a dsktop edge. My
problem is that I cannot figure out how to get mouse hits
on the toolbar background to fall throught to CMainFrm
where I can easily translate them into movement of the
whole frame. Without this capability I cannot undock the
toolbar by draging on any of the "background" areas. I
have enabled docking for the toolbars and overridden
OnLButtonDown() to prevent the standard action which drags
the toolbar off of the main frame. I want this action to
pull the whole frame away from the desktop edge, not the
toolbar off of the application frame. I derived new
objects from CToolbar,CStatusBar etc. so that I can handle
OnNCHitTest and return HTTRANSPARENT when I wanted the
main frame to get the mouse action and treat it as a drag
operation. This works well when docking is not enable for
the toolbars. I chose to enable toolbar docking so that I
can take advantage of DockControlBar() to change toolbar
positions when switching from float to docked state for
the AppBar itself and for more contained maintenance of
tooltips and context menus. Can anyone tell me if I am
going down the wrong path, or what I might do to achieve
this when toolbar docking is enabled?
|
|
|
|
|
Take a look at MFCs dockbars. Once you start dragging, they actually create a temporary message look much like modal dialogs do. It really makes docking toolbars a lot easier.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Yes, the goal is to use dockbars, if I can get them to work. With toolbar docking enabled for the main frame, the CToolbar objects take on the dockbar behavior. The problem I am having is that I do not want the toolbar to drag away from the window. I want the drag action to pull the toolbar AND its parent application frame away from the edge of the desktop to which the application window is docked. (The application is a dockable AppBar) The support of the drag action by the dockbars is actually getting in the way. I need some clever way to translate a drag action initiated by a left mouse click on background of a toolbar (dockbar) and converting it to an action on the main window iteslf!
|
|
|
|
|
Hello
Does anyone have the code of ATSP32 compiled in Visual C++ 6 because the one that is on the SDK Help was made for Visual C++ 5
Thank you
|
|
|
|
|
If you load the project into VC6 it should convert it for you.
Load the makefile into VC6 using the Open Workspace menu option, it should then prompt asking if you want to convert it.
Michael
|
|
|
|
|
if i have a class of type Student
then which is the right way to write my constructor?
Student(char* Name, char* ID)
OR
Student(char*& Name, char*& ID)
thank you
|
|
|
|
|
I guess the first option is the right one in your particular example.
By passing a char * by reference, you're allowing the function called to modify not only the contents of the pointer, but the pointer itself. For instance:
void foo(char *& p)
{
p="Second";
}
...
char *p="First";
foo(p);
Compare this with
void foo(char *p)
{
p="Second";
}
...
char *p="First";
foo(p);
Hope I made myself clear enough.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks
it might sound stupid to you but like if i read the name and ID in that case i just talked about and let say that i have something like this:
main()
{
char name[32];
char ID[10];
cin>>name>>ID;
Student Bob = Student(name, ID);
}
DO you think that would work?
coz it's giving some sort of error!
C2665 'Student::Student'none of the 2 overloads can convert parameter 1from ype char[32]
|
|
|
|
|
I'm not sure what you are asking but I don't think you want to pass an array as a reference. The reason you are getting the error is the complier thinks try to pass the whole array char[32].
You should pass arrays by address. Otherwise they get copied to the stack when passed and that can eat up a lot of stack space. Also they have to be fixed size so the compiler can allocate space on the stack for them.
I think your real question it the best way to pass information to the Student class. Here are some examples...
class Student
{
public:
Student(char *name, char *ID)
{
strcpy(m_name, name);
strcpy(m_ID, ID);
}
private:
char m_name[32];
char m_ID[10];
}; This is very basic but also very dangerous! Nothing to keep use from writing passed the end of the arrays. This is a little better:
Student(char *name, char *ID)
{
strcnpy(m_name, name, 31);
m_name[31] = '\0';
strncpy(m_ID, ID, 9);
m_ID[9] = '\0';
} This is safe but no way to know if we truncated one of the strings passed in. This will solve that:
class Student
{
public:
Student(LPCTSTR szName, LPCTSTR szID)
{
strName = szName;
m_strID = szID;
}
private:
CString m_strName;
CString m_strID;
}; This is better but there is still a problem. A constructor can not return a value. So no way to pass back a error code if they say, pass in an invalid ID value. So this would be even better:
class Student
{
public:
Student()
{
strName = "";
m_strID = "";
}
BOOL SetInformation(LPCTSTR szName, LPCTSTR szID)
{
strName = szName;
m_strID = szID;
return TRUE;
}
private:
CString m_strName;
CString m_strID;
}; I think you can see that the important thing with arrays is making sure you don't write pass the end of them. Also remember you can't return anything from a constructor. So think twice about what you do with the constructor, like don't allocate memory in it! Note that the last code is not perfect either, if you do something like this:
Student A;
Student B:
.
.
.
B = A; You will have to overload the = operator if you use CString objects. So char arrays may be better but they require a little more care in coding.
Hope this helps.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Hello,
i got a question about the procedure that receives the messages of an application that is confusing me a lot.
Up to now, i have always seen that messages were received in an application via its window, and its windowproc(...). That window proc also receives the input messages... And that's one of the things i find strange, because an application could just use the mouse or the keboard, without having a window.
I admit that inputs have to be asociated with "something" to determine what application has the focus, but an application without window could (for exemple) be activated by a left mouse click on an icon in the tray, and unactivated by a right mouse click anywhere on the desktop...
Well, my question should be something like "can i explicity set a kind of mouseproc(...) ?"
Lets go, another one (; : is it possible to separate the mouse, keyboard and window procs into three separate callbacks, each one receiving the asociated messages ?
Thanks in advance,
Lion.
|
|
|
|
|
First question. Message procs are always associated with a window, so in general you must have a window to be able to process any message. The only exception (I know of) are messages intended to a thread: those are submitted by windows in the context of a thread (i.e. created within that thread) and consumed by the thread itself. These special messages are distinguised by having NULL as their associated HWND parameter. The most prominent example is WM_QUIT (see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/messques_0tgl.asp">PostQuitMessage</a> .)
Second question. You cannot separate events based on the classification you propose. For one, some messages can be triggered both by keyboard and mouse action, like the clicking on a button.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks Joaquín,
couldn't i achieve that using hooks ?
or hooks are made for other things ?
Cheers,
Lion.
|
|
|
|
|
Oh, didn't think about hooks... Well, maybe hooks can make the difference, you're right. I'm afraid I'm no expert on such things, maybe someone else here can answer you more authoritatively.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
...that VC7 doesn't support normal C++ programming. All I hear from people is that they don't want to do managed code or NET so they aren't going to get VC7.
Well, I have been using VC7 for a month now and haven't had to WRITE ONE LINE of managed code or NET code. If you don't want to program for NET, then don't. But that is no reason not get VC7.
There are a few good reasons not to upgrade, but not wanting to have NET forced on you is not one of them.
RANT RANT RANT RANT RANT
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
and better standards support, with more to come, is a good reason for C++ programmers to upgrade.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Luckily, I have been using STLPort, so the changes to better standard support didn't hurt me. I had my software built using VC7 in 2 hours.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I hear that the debugging support has been improved.
One nice feature is support to debug multiple applications in one instance of the IDE.
Also the way that MFC and ATL have been changed in order to make the CString a little more compatible between the two frameworks.
There are other features that I have heard of, but I have not yet had the chance to use it first hand.
|
|
|
|
|
I have a crap-load of memory leaks (embedding the Python interpreter is a blast...) and I need to set a breakpoint so the code breaks when data at a certain memory location has changed.
It looks like I can do this in the Edit/Breakpoints/Data tab, but it won't let me set this as a breakpoint:
(int) *((int *) 0x12345678)
Any idea why? Any idea how to do this?
J
|
|
|
|
|
Ok, I no longer want to do this. I found a better way.
J
|
|
|
|
|
Hi,
I have a 2 pane splitter wnd (bottom and top) in an SDI app. I wanna make the bottom pane of constant size (let's say: clientrect width x 100, and the top pane: clientrect width x (clientrect Height - 100).
I tried to handle WM_SIZE in bottomview and topview first calculating the required rects and then calling MoveWindow, without any success. (the panes were not repainted, so the underlying desktop was seen in them)
Could you give me please some pointer how to do it properly?
Thanks
R.
|
|
|
|
|
I am doing this in a current project... try this:
you need a member variable of your splitter window, for instance m_MySplitterWnd.
and in your main window add a WM_SIZE handler
void CYourMainWnd::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
if( nType != SIZE_MINIMIZED )
{
int iCyCur=0;
int iCyMin=0;
int iCyNew=0;
CRect ClientRect;
// get size of client window
GetClientRect(ClientRect);
// is the splitter valid?
HWND hWndMySplitter = m_MySplitterWnd.GetSafeHwnd();
if( hWndMySplitter == NULL || !::IsWindow( hWndMySplitter ) )
{
return;
}
// get and set row info for splitter
m_MySplitterWnd.GetRowInfo( 0, iCyCur, iCyMin );
iCyNew = max( iCyMin, (ClientRect.Height() - 100));
m_MySplitterWnd.SetRowInfo( 0, iCyNew, iCyMin );
// force the splitter to recalculate
m_MySplitterWnd.RecalcLayout();
}
}
Hope this works, it's working for me..
Sef Tarbell
"A mind all logic is like a knife all blade, it makes the hand bleed that wields it." --Rabindranath Tagore
|
|
|
|
|
Well I am almost ashamed of asking this...
After striving to understand ATL/WTL/and brand new COM interface from Redmond...
#include <cstdio>
#ifndef __cplusplus
#error Ok, now you are sure that its cpp.... Disable Language extensions ... no
#endif
int f()
{
return 10;
}
int main()
{
int n = f();
char s[n];
}
My Documents\Visual Studio Projects\test\main.cpp(15) : error C2057: expected constant expression
Am I missing something??? Did I not understand a word of the C++ standard? Did I forget to turn on a obscure switch buried somewhere? I know that it is not valid C, but I thought it *was* :? valid C++...
The code below compiles fine on gcc 2.95.3, but I am aware that the GCC compiler has some extensions to everything...
Please clarify,
Regards,
R.
|
|
|
|
|
You're not missing anything. The offending line is simply illegal: in C++ (and in C) arrays must be declared as having constant (i.e. knowable at compile-time) size, except if you allocate them dynamically
char *s=new char[n]; which might not be what you want --it incurs the extra burden of managing dynamic memory. A good combination of these two extremes (contanst-size stack allocation vs. dynamic allocation) is STL's vector , which allows for non constant-size allocation and keeps you away from the error-prone memory management issues.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
PS: The code presumably compiles in gcc as this compiler is supersmart and can deduce that f(n) is a constant value, namely 10. It is a striking fact that it's allowing this, however (and I think it's not standard anyway).
|
|
|
|
|