|
Your while loop initializes the array roll with values between 1 and 10 . Note that there is no guarantee every value between 1 and 10 will actually be stored in roll somewhere; for all you know it might be an array full of 1s or full of 10 s!
In your first for loop you increment loop num times, then access roll[loop+1] ; on the last loop you will read past the end of the array, invalidating the comparison, so if the biggest value in your array happens to be stored in the last element, it may or may not be stored in temp . In Debug this probably won't cause a problem, as likely roll[100] would just access fin[0] instead, and that would be initialized to 0. In Release mode however there is no guarantee that the array fin will be initialized to 0 - in my experience it most likely will not.
The intention of the first for loop appears to be to find the largest value in roll and store it in temp . Note that this value may be anything between 1 and 10 !
The error you noticed, however, is due to what the others already pointed out above: you shouldn't increment cyc in the outer loop! What happens is this: the inner loop finds all items in roll that correspond to the temp value, store it in fin , and increment (correctly) the index cyc . Once you're at the end of the loop, temp gets decremented, then cyc gets incremented again, causing the gap you noticed, then you go on searching for occurences of your now decreased value of temp .
The reason for this confusion is that the outer loop is really all about temp, not cyc! The clearest way to write your last loop would be like this:
cyc = 0;
for (int compare = temp; compare > 0; compare--) {
for (loop = 0; loop < LIMIT; loop++) {
if (roll[loop] == compare) {
fin[cyc] = compare;
cyc++;
}
}
}
Note that I replaced num with LIMIT. This doesn't change anything in your code, but it is easier to read, as a reader unfamiliar with your code doesn't have to interpret all of it just to find out what value num would hold. Also it's less likely to accidentally mess up if you later change your code and possibly change the value of num.
Now, while the above is clearer, it is also potentially less efficient; you used the condition cyc < num , which would lead the outer loop to terminate, even if temp is still > 0 , e.g. when there are no 1 s in the array roll . So you could replace compare > 0 in the above loop with cyc < num , or, preferably, cyc < LIMIT .
You could of course also avoid the introduction of yet another variable (compare ) and just write the outer for loop like this, trading clarity for shorter, and potentially more efficient, code:
for (cyc = 0; cyc < LIMIT; temp--) {
}
|
|
|
|
|
Hi,In my MDI application,i want to close each child window with confirm message.
For this in each view,OnClose() fucntion i coded like
void CAlarmView::OnClose()
{
if(AfxMessageBox("Do you want to close the Alarm?",MB_YESNO|MB_DEFBUTTON2,NULL) == IDNO)
return;
CView::OnClose();
} But when i close the child window it does not go this OnClose() function itself.
So i gave this OnDestroy() fucntion.
void CAlarmView::OnDestroy()
{
if(AfxMessageBox("Do you want to close the Alarm?",MB_YESNO|MB_DEFBUTTON2,NULL) == IDNO)
return;
CView::OnDestroy();
}
When the application shows this confirm message,when i press NO , the child window is getting closed.Actually if i press YES then the child window should close,if i press NO it doesnot get close.
Pls help me in this concern
Anu
modified on Wednesday, February 16, 2011 2:02 AM
|
|
|
|
|
hi,
actually, your condition is wrong. change like this.
if(AfxMessageBox("Do you want to close the Alarm?",MB_YESNO|MB_DEFBUTTON2,NULL) == IDNO)
return;
else
CView::OnDestroy();
or
if(AfxMessageBox("Do you want to close the Alarm?",MB_YESNO|MB_DEFBUTTON2,NULL) == IDYES)
CView::OnDestroy();
Hope this will work..
Regards.
A. Gopinath.
|
|
|
|
|
OnDestroy[^] is called by the framework. Can you debug to check the issue with OnClose?
I am a HUMAN. I have that keyword in my name........
_AnsHUMAN_
|
|
|
|
|
I changed the code to childframe OnClose(),there im checking each window and gave this AfxMessageBox and it works fine.Thank for ur support.
void CChildFrame::OnClose()
{
if(iWindowNumber == 1)
{
if(AfxMessageBox("Do you want to close the Alarm?",MB_YESNO|MB_DEFBUTTON2,NULL) == IDNO)
return;
}
CMDIChildWnd::OnClose();
}
Anu
|
|
|
|
|
Hello , I'm programing in VC++ 6, and the entire project runs in a computer without keyboard but with touch screen.
The thing is that a have two app runnig at the same time, and I want the user to be able to switch between these apps by touching in a third app (called "Switcher",wich is always on top), this third app is a dialog based app, dialog's size is small and it has only two buttons, one for bring the first app to front and the other button to bring to the second app.
The project has to run over win 98 an over win XP.
How can i do to get wich app is The "Switcher" and bring the other to front but under the "switcher"?
|
|
|
|
|
Have you considered SetWindowPos() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
You can use SetWindowPos to move, resize and change the z-index of a window, SetWindowPos[^]
So you could use this:
SetWindowPos(targetWindow, switcherHandle, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
To bring the window to the front, by passing the handle to your switcher window as the second parameter the target application should appear just behind it. Rather than at the front of all windows.
|
|
|
|
|
Thanks, So I have to use this instruccion SetWindowPos(targetWindow, switcherHandle, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); on my "Switcher" dialog, ok, my last doubt is how can I get the handler to the target window from the "Switcher" dialog?
|
|
|
|
|
If you know the title of the window, or its class name then you can use FindWindow[^].
If you don't have the name of the window, but do have a HINSTANCE then you can search through all of the windows until you find the one you need:
HWND tmpWnd;
bool foundWindow = false;
tepWnd = FindWindow(NULL, NULL)
while(tmpWnd != NULL)
{
HINSTANCE hInstance = ProcIDFromWnd(tmpWnd);
if(hInstance == windowInst)
{
foundWindow = true;
break;
}
else
{
tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT);
}
}
Without either a HINSTANCE the class name, or the window name then I don't think there's much you could do.
|
|
|
|
|
Ok, it's working for the app1 that I know his title, let say from the "Switcher" app it's possible bring the other app1(the one i know his title) behind the Switcher, but with the other app2 , (wich is no-modal dialog) it doesn't work , i do not know the name of his class and the dialog it has not title, so i went whith the code that you wrote, but compiler complains with ProcIDFromWnd, it says that is undeclared identifier, it seems that is not a valid intruction for VC++ 6 , ??
Anyway , since in the final projet will be runnig only these three apps, i thoth that the Switcher can bring the app 1(the one working) behind it and send it to bottom when the user wants to see the app2, mfc library says that it's possible to use the parameter HWND_BOTTOM instead hWndSwitcher in SetWindowPos(hWndTarget, hWndSwitcher, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); to do that, but it's doesn't work neither. What do you think?
|
|
|
|
|
I'm not sure why SetWindowPos wouldn't work, unless you have the wrong hWnd, but as for finding a window by its HINSTANCE this code should actually work. The sample I originally found was in VB so I guess that ProcIDFromWnd is specific to that, GetWindowThreadProcessId seems to be what we really need.
HWND tmpWnd;
bool foundWindow = false;
tepWnd = FindWindow(NULL, NULL)
DWORD procID = GetProcessId(hInstace);
while(tmpWnd != NULL)
{
DWORD id = 0;
GetWindowThreadProcessId(tmpWnd, &id);
if(id == procID)
{
foundWindow = true;
break;
}
else
{
tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT);
}
}
Bear in mind that this code would find all windows that a process owns, so if it has more than one then you'll have to try and figure out which one you really need.
|
|
|
|
|
Now i get these error messages from compiler:
error C2065: 'GetProcessID' : undeclared identifier
error C2065: 'hInstace' : undeclared identifier
I can't find a the equivalent instruction in VC++6 for GetProcessID
|
|
|
|
|
Well, the function does exist MSDN[^]
hInstace is just the handle for the process that started the window that you want to move, if you don't have that and want to find and move a window that has no title that you don't have a class name for, then your last option would be to look through all of the running processes and find the one you need, only then would you be able to look through all of the windows in search of the one the process opened.
|
|
|
|
|
Three parts:
-----------------
| | |
| | |
|---------------|
| |
-----------------
I only can split one frame to two parts, the top and the bottom. But when drag this form, the form is ghost image.
Is there example to split frame?
modified 2-Apr-12 13:12pm.
|
|
|
|
|
Lots of articles here on CodeProject showing how to use splitter windows. Try the Article Search in the menu above.
I must get a clever new signature for 2011.
|
|
|
|
|
Does anyone use CListCtrl's with multiple selection (i.e., without LVS_SINGLESEL)? If yes, could you post here or send me an email about why you do this, instead of (for example) using checkboxes to mark multiple items?
Thanks!
|
|
|
|
|
It is much easier to click CTRL+A or hold down the SHIFT key while using the arrow keys, than having to move up and down press the "space"-key to flip each item checkbox.
Many times one would combine selection together with checkboxes, where one can flip the checkboxes of all the selected items.
|
|
|
|
|
yeap many times, please pm me your email id, i would send it to you!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
There's an email link in my post.
|
|
|
|
|
Hi All,
I want to Use the SQLFetchScroll to Move the Record to First Position.
There is no Article which gives clear clarity of this Usage.
Pls help me out.
Thanks & Regards,
Uday
|
|
|
|
|
There is a good description on MSDN[^]. I haven't tried, but I would guess you use FetchOrientation = SQL_FETCH_FIRST, and FetchOffset = 0 to get the first record.
|
|
|
|
|
Hi,
Im having MDI application.In that for only one view, iam adding menu.
So i reffered one article form MSDN and i create the menu for that particular view.
http://support.microsoft.com/kb/118435[^]
By using this document i coded and i got my menu also.
But what i need is?
Actually for that particular child window im setting size of the window as 0,0,1500,700.
When i set this,the child window menu is attached with mainframe,only the window is getting this postion.
How can i change this.
I want to move this menu from mainframe to the childwindow(below the caption bar).
Pls help.
Anu
|
|
|
|
|
In google chrome they have checksum value for bookmark file.if i add any bookmark manually i need to change checksum value otherwise browser don't display bookmarks...
|
|
|
|
|
Well, Chrome is open source. Presumably the algorithm is in the code somewhere.
Check out http://dev.chromium.org/developers/how-tos/get-the-code[^].
There is a link to search the code on that page, but I couldn't find it, but is is there somewhere. Also Chrome calls bookmarks favourites.
|
|
|
|
|