|
Can any one share the idea, what actualy going inside main() funcation.
|
|
|
|
|
Hi,
1)What is the difference between a list and array?
2)Which one to use and when?
3)Which one is the best one to use (array or list), when we have a 100 data elements of int type?
Thanks
Maha
|
|
|
|
|
The best one does not depend on the type of elements you are holding, it depends
on the kind of operations you want to perform most often:
- they are equally good at enumerating or traversing the collection
- arrays are better at referencing by index (do not need finding sequentially)
- lists are better at inserting, removing (do not need copying)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
i succeeded in making tray icon..bur how to minimize it to tray only when i click on minimize button.also after filling all three field which are asked and then when i press ok i want the dialog window to minimize to taskbar icon..please help me...my code is as follows:
#include <windows.h>
#include "resource.h"
#include <cstdlib>
#include<atlstr.h>
#include <fstream>
#include<iostream>
#include<string.h>
#include "FileOperation.h"
#include<stdio.h>
#define WM_ICON_NOTIFY WM_USER+1
//---------------------------------------------------------------------------
LPSTR lpString;
HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST),hWnd, reinterpret_cast<dlgproc>(DlgProc));
return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
char cPath[20];
char cUserName[20];
char cPassword[20];
switch(Msg)
{
case WM_INITDIALOG:
{
}
case WM_ICON_NOTIFY:
{
}
case WM_LBUTTONDBLCLK:
{
ShowWindow(hWndDlg, IDD_DLGFIRST);
break;
}
break;
case WM_COMMAND:
{
switch(wParam)
{
case IDOK:
{
size_t nLen;
GetDlgItemText(hWndDlg, IDC_EDIT1, cPath, 20);
nLen = strlen(cPath);
if (nLen == 0)
{
MessageBox(hWndDlg,"Please Enter SVN Path","Error",MB_ICONERROR);
break;
}
GetDlgItemText(hWndDlg, IDC_EDIT2, cUserName, 20);
nLen = strlen(cUserName);
if (nLen == 0)
{
MessageBox(hWndDlg,"Please Enter your user name","Error",MB_ICONERROR);
break;
}
GetDlgItemText(hWndDlg, IDC_EDIT3, cPassword, 20);
nLen = strlen(cPassword);
if (nLen == 0)
{
MessageBox(hWndDlg,"Please Enter your Password ","Error",MB_ICONERROR);
break;
}
/*EndDialog(hWndDlg, 0);*/
/*std::ofstream file ("config.txt");
file << " SVN Path entered by user is -> "<<cpath <<="" std::endl;
file="" "="" svn="" user="" name="" entered="" by="" -="">" <<cusername <<="" std::endl;
file="" "="" svn="" password="" entered="" by="" user="" -="">"<
|
|
|
|
|
Still haven't found the right discussion board?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
but reading is so hard
|
|
|
|
|
Hi, I am using Visual Studio 2005 C++/CLI. I have an application that draws the contents of a 200 by 200 two-dimensional array. I also need to redraw the screen when I change the orientation of the display. In Visual C++ MFC updates to the display seemed almost instantaneous (entire display repainted in the blink of an eye. But the way I am doing it now you can see the screen paint from top to bottom in about a second. Seems way slow to the way it was before. Is the C++/CLI GDI+ that much slower than before? Also, if I pull up a dialog box that covers part of my display and then close it, the part of the display that was covered appears blank. Is there a command that will repaint that part of the display without having to redraw the entire display?
Thanks
Buck
|
|
|
|
|
Hi,
are you saying you have 200*200 controls ? if so, was that fast in C++ MFC ??
if you did your own Paint handler, seems like you should show the code.
Are you creating lots of objects while painting ?
Are you forgetting to dispose of objects that need being disposed of ?
No, the repaint when uncovered should be automatic; it will not be if it's about
some lines, images, text that you draw yourself in the wrong way (that is outside
the Paint handler).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
It is a 200 x 200 array of structs. It is very fast in C++ MFC. No, I'm not creating a lot of objects while painting. Since the document does not repaint when the dialog box goes away I must be doing this outside the Paint handler. When I start my application I have the initial Form1.h file that I use to open a file that contains information to display. This stripped down code that creates a graphics object is shown below... Should I be doing this another way? I really don't understand "outside the Paint handler". How do I do this "inside the Paint handler"?
CWafer^ Wafer;
Graphics^ graphics;
BinDialog^ binDialog;
System::Drawing::Font^ drawFont;
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
BinData = gcnew array<bool>(33);
BinData->Clear(BinData, 0, BinData->Length);
graphics = this->CreateGraphics();
Wafer = gcnew CWafer();
binDialog = gcnew BinDialog();
drawFont = gcnew System::Drawing::Font("Courier New", 6);
DisplayWaferMap();
viewToolStripMenuItem->Enabled::set(true);
zoomToolStripMenuItem->Enabled::set(true);
toolsToolStripMenuItem->Enabled::set(true);
printToolStripMenuItem->Enabled::set(true);
printPreviewToolStripMenuItem->Enabled::set(true);
}
//---------------------------------------------------------------------------
private: System::Void DisplayWaferMap()
{
graphics->Clear(Color::White);
DisplayMapPerimeter();
DisplayMapText();
}
//---------------------------------------------------------------------------
private: System::Void DisplayMapPerimeter()
{
Pen^ blackPen = gcnew Pen(Color::Black);
Point point1;
Point point2;
double height;
double radius;
double radians;
float start_angle;
float sweep_angle;
float angle_of_incidence = 20; // In degrees
sweep_angle = 360 - (2 * angle_of_incidence);
radians = angle_of_incidence / 57.29578;
height = this->Size.Height - 100;
radius = height / 2;
Rectangle rect = Rectangle(50, 50, (int)height, (int)height);
switch (Wafer->FlatOrientation)
{
case FLAT_RIGHT:
start_angle = angle_of_incidence;
point1.X = (int)(radius + (Math::Cos(radians) * radius) + 50);
point2.X = (int)(radius + (Math::Cos(radians) * radius) + 50);
point1.Y = (int)(radius + (Math::Sin(radians) * radius) + 50);
point2.Y = (int)(radius - (Math::Sin(radians) * radius) + 50);
break;
case FLAT_DOWN:
start_angle = angle_of_incidence + 90;
point1.X = (int)(radius - (Math::Sin(radians) * radius) + 50);
point2.X = (int)(radius + (Math::Sin(radians) * radius) + 50);
point1.Y = (int)(radius + (Math::Cos(radians) * radius) + 50);
point2.Y = (int)(radius + (Math::Cos(radians) * radius) + 50);
break;
case FLAT_LEFT:
start_angle = angle_of_incidence + 180;
point1.X = (int)(radius - (Math::Cos(radians) * radius) + 50);
point2.X = (int)(radius - (Math::Cos(radians) * radius) + 50);
point1.Y = (int)(radius + (Math::Sin(radians) * radius) + 50);
point2.Y = (int)(radius - (Math::Sin(radians) * radius) + 50);
break;
case FLAT_UP:
start_angle = angle_of_incidence + 270;
point1.X = (int)(radius - (Math::Sin(radians) * radius) + 50);
point2.X = (int)(radius + (Math::Sin(radians) * radius) + 50);
point1.Y = (int)(radius - (Math::Cos(radians) * radius) + 50);
point2.Y = (int)(radius - (Math::Cos(radians) * radius) + 50);
break;
default: break;
}
graphics->DrawArc(blackPen, rect, start_angle, sweep_angle);
graphics->DrawLine(blackPen, point1.X, point1.Y, point2.X, point2.Y);
}
//---------------------------------------------------------------------------
private: System::Void DisplayMapText()
{
System::Drawing::Font^ drawFont = gcnew System::Drawing::Font("Ariel", 14);
SolidBrush^ blackBrush = gcnew SolidBrush(Color::Black);
float x_coord;
float y_coord;
float height;
float width;
height = (float)this->Size.Height;
width = (float)this->Size.Height;
x_coord = width - 50;
y_coord = height - 250;
graphics->DrawString( "Part Number", drawFont, blackBrush, x_coord, y_coord);
graphics->DrawString( ":", drawFont, blackBrush, x_coord + 150, y_coord);
graphics->DrawString( Wafer->DeviceName, drawFont, blackBrush, x_coord + 180, y_coord);
y_coord = height - 225;
graphics->DrawString( "Lot Number", drawFont, blackBrush, x_coord, y_coord);
graphics->DrawString( ":", drawFont, blackBrush, x_coord + 150, y_coord);
graphics->DrawString( Wafer->LotNumber, drawFont, blackBrush, x_coord + 180, y_coord);
y_coord = height - 200;
graphics->DrawString( "Wafer Number", drawFont, blackBrush, x_coord, y_coord);
graphics->DrawString( ":", drawFont, blackBrush, x_coord + 150, y_coord);
graphics->DrawString( Wafer->WaferNumber, drawFont, blackBrush, x_coord + 180, y_coord);
y_coord = height - 175;
graphics->DrawString( "Yield", drawFont, blackBrush, x_coord, y_coord);
graphics->DrawString( ":", drawFont, blackBrush, x_coord + 150, y_coord);
graphics->DrawString( "100%", drawFont, blackBrush, x_coord + 180, y_coord);
}
Buck
|
|
|
|
|
OK, the situation is clear, the remedy takes two parts:
SPEED
Math::Sin and Math::Cos are expensive methods.
And there is a lot of subexpressions like (Math::Cos(radians) * radius) + 50);
these get evaluated over and over, don't rely on the compiler to optimize them all
away but one or two of them. Instead calculate them yourself and store the result in
a local variable for reuse.
It may be so that it runs much faster in release build, but I would not count on it.
Calling a method in another class (such as Math::Cos) prevents a lot of optimizations,
basically the compiler does not trust every call with same argument will return same
result.
PAINT PROBLEM
The way you organized it, the wafer gets painted when you click a menu item or so,
just once. If your form gets disrupted (covered-uncovered, minimized-restored, ...)
(part of) the wafer is gone, what piece of code would redraw it for you ?
The right approach is to have a Paint handler, that gets fired thru the Paint event
(similar to a Click event for a Button). The Paint handler basically should contain
the code you now have in the menu item handler.
The Paint handler gets invoked automatically when the form got damaged, and also
when you call Invalidate().
Hence your menu item handler should just set up a few variables, maybe a show/hide wafer
flag or so, and then it should end on an Invalidate().
Happy painting !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc,
Thank you so much. The speed issue makes sense because when I was doing the same thing in MFC I was doing it a different way that did not use the sine and cosine math functions. I will see about getting a Paint handler to handle the painting instead of the menu item handler. This is the kind of Windows organization that I am not fluent in. I'm usually just happy if I can get something to work. You'll probably be seeing a post later today about printing the screen as I am now venturing into that.
Thanks again,
|
|
|
|
|
Hi Buck,
one thing I forgot to mention: if you have a complex drawing and need to apply
some transformation (scaling, rotation, whatever) to it, you can tell the
Graphics object to do that automatically for you, using its many XXXTransform() methods.
I trust they use the fastest way to apply the transformation !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Cool, that's nice to know because I do rotate the drawing. Using information gleened from Nishant Sivakumar code project article "Managed C++ and Windows Forms" I created a function in the Form1 class as follows...
protected: virtual void OnPaint(PaintEventArgs^ e) override
{
Graphics^ graphics = e->Graphics;
DisplayWaferMap(graphics);
}
And this seems to work the way you would want it, but there is another problem that may have a simple if statement check solution. The way I had this was that when the File->Open was invoked, a file was selected and the Wafer^ object instansiated acording to information in the file. Because 'DisplayWaferMap' uses the Wafer^ object the application dies because the Wafer^ object does not exist yet. Is there a method that will tell me if an object exists? Or should I instanciate the Wafer^ object in the Form1 constructor and set a variable myself (seems easy enough)? On the display speed issue I think I have a guess as to what is going between MFC and this. With MFC I beleive that I was painting the entire display (internally) and then issuing an Update() command that would then physically paint the screen. With the CLI code that I have, if the screen is physically repainted with each Graphics->DrawString() command then that's a huge number of physical repaints comapred to just one after all the information has been changed.
Buck
|
|
|
|
|
Hi Buck,
if (part of) your drawing is not available, your OnPaint should not even attempt to draw it;
the normal approach is having some test: if wafer were an object, it would initially be
null, so do a null test in OnPaint to skip it when wafer is not yet, or no longer, valid.
Basically what I am saying is: OnPaint should draw everything that is present in
your virtual drawing, that could be an arbitrary collection of items, it's completely up
to you.
BuckBrown wrote: if the screen is physically repainted with each Graphics->DrawString() command
it is not, this line belongs inside OnPaint, and it does not cause a new execution of
OnPaint.
If for some reason you would be repainting the same (or slightly changed) wafer, and
want the disturbance/flicker/whatever to be minimal, you may choose to make the
control you are drawing on (Panel, Form, whatever) be doublebuffered; there is a property
for that, it entails a hidden bitmap that gets drawn upon, then blitted onto the screen.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hello,
I have two String format of date time and would transform it in a datetime format and I would to do a substraction of this 2 datetime
can you help me,
thanks you,
aef
|
|
|
|
|
Hi,
The DateTime type has a Parse() method and a Subtract() method.
I fail to see a problem. It is all well documented in MSDN.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hi
i'm new at c++ and i have very simple question for you
"double(*)[2]" This code has defined in a function,can you explain me what does it mean ?
asdasd
|
|
|
|
|
This forum is for managed C++ question. Post this question in VC++[^] forum instead.
Prasad
MS MVP - VC++
|
|
|
|
|
Hello,
I want to program with matrix of String can you give me a syntax of this declaration
Thanks,
aef
|
|
|
|
|
array<String^, [your desired dimension here]>^ yourVariableName;
Replace [your desired dimension here] with an integer between 1 and 32 inclusive.
|
|
|
|
|
hello,
I try with this but it gives error,
and I tryed this
cli::array <string ^="" ,="" 2=""> ^ ListCapt = gcnew cli::array<string ^="" ,2=""> (100000,16);
but it gives 4 error;
but when I do this :
[code]
array < array < String ^ > ^ > ^ ListCapt= gcnew array < array < String ^ > ^ >(20);
cpt=117
for(int i=0;i<cpt;i++)
for="" (int="" j="0;j<15;j++)
" listcapt[i][j]="Convert::ToString(i+j);
[/code]
there" isn't="" error="" but="" in="" execution="" it="" give="" the="" exception
if="" you="" are="" an="" exemple="" me;
thanks
=""
<div="" class="ForumSig">aef
|
|
|
|
|
I just typed
array<String^,2>^ myMatrix = gcnew array<String^,2>( 100000, 16 ); into a C++/CLI project I'm working on right now and got no compilation error. I'm using VS2005 SP1. What errors are you getting?
|
|
|
|
|
|
|