|
There are some tips discussed in Herb Sutter exceptional and more exceptional C++. Guidelines that may reduce the include hell are:
* use forward delarations. The author stresses the use of #include < iosfwd >
* Avoid unnecesary inheritace. "is implemented in terms of". By encapsulating data members (pointers wrapped in a convenient smart pointer like std::auto_ptr or boost::shared_ptr ).
* The pimpl idiom.
For further details go to www.gotw.ca (lots of C++ good material there) and even better, support the author by buying his book (I'm in no way related to the author, but I do enjoy reading his columns...)
Regards,
R.
|
|
|
|
|
Ramon Casellas wrote:
For further details go to www.gotw.ca (lots of C++ good material there) and even better, support the author by buying his book (I'm in no way related to the author, but I do enjoy reading his columns...)
Very True , a indispensable portal of knowledge to any serious c++ developer .
I've Exceptional C++, but I didn't bought yet The More Exceptional C++
Joao Vaz
|
|
|
|
|
One thing I always do, and I picked this up from reading windoze SDK headers, is I put this little block at the front of all my headers :
#ifdef _HEADER_H
#error repeated include of this file
#else
#define _HEADER_H
#endif
Then substitute the name of your header file in place of HEADER.
Any time I want to include the file I use this :
#ifndef _HEADER_H
#include "Header.h"
#endif
This forces one and only inclusion of a given header file without having to parse each one a whole bunch of times. This really adds up in large projects.
One key to making this work is to have a consistent define pattern for the header files. I always use the one shown. I dislike the GUID method but that's just me.
This is also portable unlike MFC's pragma once method in case that matters.
Another frequent header file headache is the issue of global variables and the use of extern. Here is what I do.
In one central macro definition header define this :
#ifdef _DEFINE_GLOBALS
#define Global
#else
#define Global extern
#endif
Then you can declare global variables like this :
Global int GlobalInteger_1;
Global int GlobalInteger_2;
If you want them initialized then do this :
#ifdef _DEFINE_GLOBALS
int GlobalInteger_1 = 42;
#else // _DEFINE_GLOBALS
Global int GlobalInteger_1;
#endif // _DEFINE_GLOBALS
Prior to include the header with the global declarations, do this :
#define _DEFINE_GLOBALS
#include "Globals.h"
NOTE: the _DEFINE_GLOBALS may only be defined one and only one time. I usually do it in my application class module.
The advantages of this scheme are that you only have to maitain one file of declarations and the extern issue is taken care of.
|
|
|
|
|
Hi
First of all a short description of what I want to do:
I want to start a program (using ShellExecute), then find the only ListBox within the new launched app. I use FindWindow and then EnumChildWindows.
Until now everything works fine, I can get a HWND handle to the ListBox of the other app.
Now I want to select the 2nd item of the single-selection ListBox.
I use
SendMessage(hwnd,LB_SETCURSEL,1,0);
The ListBox definately has at least 2 items and the hwnd handle is correct as well. However, no item is selected, although it should work this way (MFC does it the same way).
If I try
int count = SendMessage(hwnd,LB_GETCOUNT,0,0);
this works, i.e. I can get the numer of items of this ListBox.
Can you explain, why I can't change the selected item?
thanks in advance
Gregor
modified 12-Sep-18 21:01pm.
|
|
|
|
|
LB_SETCURSEL only works for single selection list boxes. If the list box supports multiple selection, use LB_SETSEL instead.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
As I said in my first post this is a single selection listbox
Help Me!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Ooops sorry, didn't see that!
What's the return value of SendMessage() ? Does it return LB_ERR ?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
It returns "1".
Dunno what that means but shout mean that item 1 has been selected, right?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hmmm, looks like it's doing the right thing.
Have you tried selecting (i.e. setting focus to) the window containing the list box after you do the SendMessage() ? Does it show the highlighted item when you do that?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
It automatically gets focus after it has been launched through ShellExecute
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I just found a very strange behavior:
If I start my app for the first time, the item does not get selected in the listbox of the app.
But if I start my app for a second time (and therefore my program starts the other program again so that two instances are running), then suddenly the item gets selected, but only in the first (!) instance of the other app.
What's going on?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Can you use Spy++ to check if your listbox actually receives LB_SETCURSEL?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I never used Spy++ before, could you shortly explain where I can check for incoming messages in other applications?
thanks
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Ctrl+F, then drag 'target' icon on the listbox window. You'll be able to choose between examining properties of the window and hooking into its messages.
BTW: you're calling ShellExecute, then immediately follow with SendMessage? Or there's some other event, like button press which is used to invoked SendMessage with LB_SETCURSEL?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
SendMessage is called within the EnumChildWindows-Callback,which is directly called after ShellExecute. But there's no problem with e.g. LB_GETCOUNT, this works quite well
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Well, while it's not guaranteed to solve your problems, you may try to add WaitForInputIdle call between ShellExecute and EnumChildWindows to avoid dependencies in startup time of second application.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
How do I get a HANDLE of the other app?
Is WaitForInputIdle((HANDLE)wnd,INFINTE) legal?
This did not solve my problems, but you might take a look at my comment "Just found strange behavior" I hope you understand it, my English is not very good
thanks
modified 12-Sep-18 21:01pm.
|
|
|
|
|
No, you can't just use HWND as a process handle. For that you'll need to use ShellExecuteEx or get the handle with a call to GetWindowThreadProcessId/OpenProcess.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
|
Gregor S. wrote:
You are my hero of the month
Stop brown-nosing
BTW: you'll have to change FindWindow to EnumWindows. That's because your app may be started twice, and it may launch two (or more?) apps with ShellExecute. FindWindow will find first HWND with given class/caption - this criteria is too weak if you can have more than one app launched with ShellExecute.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Gregor S. wrote:
you might take a look at my comment "Just found strange behavior"
It looks like synchronization problem. Your 2nd FindWindow call finds the main window launched by 1st ShellExecute call, then sends the message. Message is processed OK and item is selected.
It seems that launched app needs some time before it can accept messages - WaitInputIdle ensures that. Use ShellExecuteEx to avoid problems with mutliple target windows - you'll get the process handle. You'll also have to abandon FindWindow - if two apps were launched, the find criteria are too weak. EnumWindows and GetWindowThreadProcessId are the way to go.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I need to handle a 2D Array whose first subscript is known to me only at runtime.The Array is an array of strings.The second subscript is the max size of a string.But I want to use only character arrays but not CString to represent a string.
Hence,if I declare an array,like
#define MAX_STRING_SZ 10
char MyArray[][MAX_STRING_SZ+1];
...
and I want to use the above array in a function F1.
F1 will return such arrays , n numbers,to function F2,where The arrays's members are shown in a list view.
But,the array declaration is not allowed in Microsoft Visual C++ to have empty braces[] as well as with any variable,whose value I would supply as and when I get.
I am in urgent need of this.
Thanking you ,The Experts,in advance!!!
Best Regards,
GVBhaskar
srigvb@yahoo.com
srigvb@rediffmail.com
gvbhaskar@hotmail.com
G.V.Bhaskar
|
|
|
|
|
Can't you use CStringArray, CStringList or std::vector<std::string> ?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
First of all, I'd recommend forgetting about 2D arrays and going to something more high-level like, for instance, a std::vector of std::string s. Anyway, if you can't afford it, the syntax you must follow is like this:
void F2(char array[][MAX_STRING_SZ+1],int len); Here len is needed to inform about the first dimension of the 2D array. To define a variable capable of holding 2D arrays of unspecified (i.e. determined at run-time) first dimension, the syntax is:
char (* MyArray)[MAX_STRING_SZ+1]; which is also the return type of your F1 function. Remember, the first dimension must be passed along somehow. And please allow me to recommend you again that you use STL containers to make your life easier.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Why RichEdit20A scroll the contents of the CRichEditCtrl in view ?
For example, I wrote handler for ON_WM_VSCROLL():
[ccode]
void CRichSyntaxView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CRichEditView::OnVScroll(nSBCode, nPos, pScrollBar); //call std handler
CRichEditCtrl& r = GetRichEditCtrl();
CHARFORMAT2A cf;
CHARRANGE ccr;
memset(&cf,0,sizeof(cf)); // clear
r.SetRedraw(false); // don'n redraw
r.HideSelection(true, true); //don't show the selection
r.GetSel(ccr); //save old selection
r.SetSel(iMin, iMax); //set new selection
...
r.SetSel(ccr); //restore selection
r.HideSelection(false, true); //show the selection
r.SetRedraw(true); //redraw=on
Invalidate(false); // refresh view
}
[/ccode]
In Richedit 1.0 all ok. Why?
=== MSDN98 ===:
SetSel(..)
The caret is placed at the end of the selection indicated by the greater
of the start (cpMin or nStartChar) and end (cpMax or nEndChar) indices.
This function does not scroll the contents of the CRichEditCtrl
so that the caret is visible.
RichEdit20A - glucked..
Please help me!
thank you..
|
|
|
|