|
FlyWithYou wrote: RegisterWindowMessage?
You have no other option or send the message to each task individually
"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
|
|
|
|
|
Yes, that will do the job. Just use the same registration string in each process and they will get the same message ID.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
When using MFC, you might get away with using the OnUpdate /UpdateAllViews mechanism and a separate (numeric) hint for every message you want to transport.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
OK, I didn't get much of a response in a previous post about program design, and I can see why - I didn't really break the problem down into small enough chunks.
So I am following up with some of the same problem expressed in a (hopefully) more concise way.
All I really want to do is get suggestions on Class design. Now, I have a feeling that some people will wade in with suggestions to use STL templates, which I don't have a problem with, but, because of the fairly simple nature of the program, and the lack of programming skills of people who may have to make small changes to the code, I think it might be OK to just use a simple "normal" array for example, rather than set up a whole vector implementation (not that I'm au fait even with that, having been away from programming for a good few years, I find I've forgotten everything!)
So, here is what my program does (and is linked to an MFC dialog, though that's not relevant probably)
User loads a set of text files
A listbox is populated
A file is selected and a process button clicked
Processed data is displayed in simple static controls on the dialog
The processing part involves
open the text file (in theory should be the same format each time)*
read in a few lines of header info, incl array size
load in some lines of data, making up a 2D array
do stuff with the 2D array data, fairly simple stuff, max size 27*27
because of my time away from programming and because I only ever learned "on the job" with tools code and updates, I never really got comfortable with setting up classes and programs from the ground up. And that's where I would like some help
i.e.
should I be making a "2DArray" type class that can hold the header info and data and be able to do arbitrary processing on 1D and 2D subsets of the array, or should the class be the "2DArrayfile" object, and then have a separate array class that I can call methods on?
It's also important that I do some error checking at each stage, because its being used to check data which impacts clinical treatments - though in fact, the most important thing is correct calculation of the results, so if it fails to load a file properly because somethings out of whack, thats less serious than if it output the wrong value in a calculation!
The things I need to do with this 2D Array:
Find the centre point, which is the "100%" mark
Calculate the size of the array bounded by the 50% values (interpolating between array indexes, each index refers to 1cm of physical distance)
Reduce the physical dimensions of the array to 80% of its value calculated above
This then defines which elements of the array are included in the next step
calculate the max/min in that region
calculate the highest ratio of equally spaced points about the central point along the central axes (or any axis)
So, let's say I have a 2DArray class, and I've read in the text file details, read in the array and it's stored - presumably as a 1D array of doubles, can I overload the [] operators [][]? so that I can access it like a 2D array, or do I need functions to do it, like GetCell(int a, int b), and GetSubArray(int a, int b, int, c, int d)
and then the processing tasks outlined above could just be generalised functions that you can perform on any array data set, and the implementation could check for errors/array bounds, and return the right thing
|
|
|
|
|
You ask a difficult question here. In general a good class design is never easy to make. But try to think in a object-oriented way. First you should define what problem you want to solve. As i can suggest from your post, you made that already. Then try to define the classes. Start with the core of the problem. I try to explain what i do if i invent a new class design from scratch and hope that leads you in the right direction.
1. First i write the problem i like to solve on a piece of paper. I try to put the words in one simple sentence. That helps me to get a crip on the problem.
2. Then i start with the core class. In your case this would be something like C2DArray. I try to keep it as simple as possible first. What do i need the class to do:
- read in a text file
- store the data kept in the text file
- store some header information
- do some simple calculations
These points already define me some member functions:
- C2DArray(const char* filename)
- readFile()
- calculateSomething()
- ...
3. After i got the first simple class i try it out with a simple application. In most cases this is a console application with a lot of printf's.
4. I put more functionality into the class. While i do this, i keep the following in mind:
- If a member function gets too big and i don't understand what's going on anymore i split it
in several subfunctions
- If a class gets too big and i don't understand what's going on anymore i try to generalize
parts of the class into a superclass
In that way you will become more classes and functions on need and you don't get overwhelmed by a mass of classes from the start.
About generalisation, operator overloading etc. Do this only if it is worth the effort and you need it for your application. There are so many class designs where people did operator overloading only cause it looked nice.
I am not sure if this is what you needed. Hope it helps you out a bit. And i am sorry if my English isn't that good. It is not my native language.
Walter
|
|
|
|
|
Thanks for your help and suggestions.
I'm not totally sure if a better idea might be to have an array class itself and then an arrayfile class. That way i could make a generic array class that allows me to get the required functionality but in lots of arbitrary and generalised ways, and I can just have that as a data member of the arrayfile class.
|
|
|
|
|
Hehehe! It is working as intended. You are thinking in-depth about your problem domain and the design. The way you mentioned in your last post sounds good to me. Make 2 classes one for the array and another for the file reading and parsing stuff. Do a composition of both, i. e. make the array class a member of the file reading class.
Keep in mind to always start simple and extend your design as needed.
Walter
|
|
|
|
|
I written win app to launch console app write data to it and read results from it thru pipes.
My Console app on launch from command line:
type numbers:
//I'm then typing floating point numbers
1.1\n
2.2\n
3.3\n
\032\n <------ ctrl-z and new line forcing console to stop reading
//produce some output
My win app:
creates pipes;
create process; //console app
write to stdinWPipe; //console read it from its end of pipe stdinRPipe
fprintf(stdinWPipe,"%f\n",numb[i]);
frpintf(stdinWPipe,"\032\n"); //write ctrl-z symbol
closehandle(stdinWPipe); //close write end of stdin pipe
closehandle(stdoutWPipe); //close write end of stdout pipe before read
ReadFile(stdoutRPipe, ...); //read from read end of stdout pipe
This all works fine with my test console app and my win app to launch it, write data to its stdin and read data from its stdout throu pipes.
But there is just executable console which I need to lunch the same mode.
After it is ran from just command prompt it behaves exactly the same as my test console app:
type numbers: //writing prompt for typing in
1.1\n //and all the same typing numbers
2.2\n
3.3\n
\032\n //ctrl+z + \n
//and then it outputs results
But when I run this unknown console app from my win app function ReadFile(stdoutRPipe,... ) hangs itself never returning?? That is no data written to stdoutWPipe from console app. Whats the hell??
9ine
|
|
|
|
|
I did the same thing with a program I wrote in the past.. On Read I loop the read until no more data is available... Not sure how you are doing your ReadFile but this may help.
for ( ;; )
{
if(!ReadFile(hChildStdoutRdDup, chOutputBuf, sizeof(chOutputBuf), &dwRead, NULL) || dwRead == 0)
break;
chOutputBuf[dwRead] = 0;
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I've figured out the reason.
This executable first writes to stderr so it was useless to read from stdout untill this program accepted data in stdin. So this is why readfile suspends itself if trying to read from stdin.
9ine
|
|
|
|
|
Hi,
how can i get a handle to my current window class?, i mean from within the class, if its possible at all.
and is there any way to convert between both HWnd and CWnd , f.e a function that takes a handle and returns a pointer ?
thanks
|
|
|
|
|
CWnd::FromHandle() [^]
Vini
|
|
|
|
|
saadani wrote: is there any way to convert between both HWnd and CWnd , f.e a function that takes a handle and returns a pointer ?
HWND to CWnd *
CWnd *pWnd = CWnd::FromHandle(aHwnd);
CWnd to HWND
HWND aHwnd = pWnd->GetSafeHwnd();
saadani wrote: how can i get a handle to my current window class?, i mean from within the class
HWND hWnd = this->GetSafeHwnd();
Nibu thomas
Software Developer
|
|
|
|
|
From the Documentation of the CWnd-Class:
CWnd::m_hWnd
Remarks
The handle of the Windows window attached to this CWnd. The m_hWnd data member is a public variable of type HWND.
CWnd::GetSafeHwnd
HWND GetSafeHwnd( ) const;
Return Value
Returns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer.
Hope this helps you out.
Walter
|
|
|
|
|
|
Hi Guys,
I have a list control containing 3 columns, When i click on any item in the list box it again pops up a combo box. But problem is that when i am tring to increase the height of the combo box it's not increasing and reamain same always. I am giving you the whole code. please tell me how to fix this problem. I am trying to increase the rect.bottom but its not increasing.
void CListAgr::OnListLButton(WPARAM wParam, LPARAM lParam)
{
UINT nFlags = lParam;
int iItem = wParam;
int iItem = m_list_Agr.GetNextItem(-1, LVNI_SELECTED);
if (iItem >= 0)
{
CRect rect;
int offset = 0;
// Make sure that the item is visible
m_list_Agr.GetSubItemRect(iItem, 1, LVIR_BOUNDS, rect);
// Now scroll if we need to expose the column
CRect rcClient;
m_list_leaseabs.GetClientRect(rcClient);
if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
{
CSize size;
size.cx = rect.left;
size.cy = 0;
m_list_leaseabs.Scroll(size);
rect.left -= size.cx;
}
rect.left += offset;
rect.right = rect.left + m_list_Agr.GetColumnWidth(1);
if(rect.right > rcClient.right)
rect.right = rcClient.right;
//basic code end
rect.NormalizeRect();
rect.bottom += 10 * rect.Height();//dropdown area "PLEASE SEE THIS"
rect.left += 10;
rect.right += 10;
rect.top += 30;
CStringList lstItems;
lstItems.AddTail("X");
lstItems.AddTail("Y");
lstItems.AddTail("Z");
CComboBox *pADFList = new CComboInListView(iItem, 1, &lstItems);
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL |
WS_HSCROLL|CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL;
pADFList->Create(dwStyle, rect, this, IDC_COMBOBOXINLISTVIEW);
pADFList->ModifyStyleEx(0,WS_EX_CLIENTEDGE);//can we tell at all
pADFList->SetHorizontalExtent(m_list_Agr.GetColumnWidth(1));
pADFList->ShowDropDown();
pADFList->SelectString(-1, m_list_Agr.GetItemText(iItem, 1));
}
}
|
|
|
|
|
I could not check all of your code, but you can try this:
Remove the CBS_DISABLENOSCROLL style from the Combobox.
See if that helps.
this is this.
|
|
|
|
|
No it's not working. As per MSDN
CBS_DISABLENOSCROLL: The list box shows a disabled vertical scroll bar when the list box does not contain enough items to scroll. Without this style, the scroll bar is hidden when the list box does not contain enough items.
If possible then check the code we are missing fundamental concept like it's mapping mode or something.
|
|
|
|
|
|
Hi,
I'm running into some issues with my custom created class..
A simplified version:
ref class cCollection<br />
{<br />
public:<br />
int id;<br />
array< Point >^ points;<br />
char* name;<br />
};
Declared an array for it with:
<br />
array< cCollection^ >^ aCollection;<br />
<br />
array< cCollection^ >^ aCollection = gcnew array< cCollection^ >(99);
The application compiles, builds, and runs, but when i try to add an element in my btnAdd_Click event with:
<br />
iCount++;<br />
<br />
cCollection^ tempCollection = gcnew cCollection;<br />
<br />
aCollection[iCount] = tempCollection;
...the application crashes with "aCollection contains < undefined value > "
I hope you see my target; I have a class cCollection and i'd like to put them in an array.. I lost track with the fact that my array contains managed elements (points).
Could someone please help me out? thanks in advance,
joost
-- modified at 7:51 Wednesday 1st March, 2006
|
|
|
|
|
This looks like managed C++. Yes?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Indeed.. The use of Points requires the use of it. At least, that's what i can make up out of the errors i receive during the development of this small application.
Thanks for your reply,
joost
-- modified at 9:38 Wednesday 1st March, 2006
|
|
|
|
|
The problem is solved with:
array< cCollection^ >^ aCollection; <br />
<br />
aCollection = gcnew array< cCollection^ >(99);
|
|
|
|
|
Hi ,
As i know the data read and write from a hard disk in a file is bit a slow process,
So i want read a data from file and load it into a memory to do some operations on data and then i want to write that all data inot a file , so read and write will b only for once.
actualy i dont want the continoius read and write to a hard disk,
so how can i load the all file contents in a memry and read them from memoery , and how can i write a that memory data into a file
Thanks
Regards.
|
|
|
|
|
Create a file.
pass that handle as first parameter in the function CreateFileMapping()
now pass the hanle return from the function CreateFileMapping to the function
MapViewOfFile().
The function MapViewOfFile() returns a pointer to the buffer. u can do read and write to thst buffer. Finally u have to call UnMappviewoffile() when u exit.
nave
|
|
|
|
|