Tuesday, April 6, 2010

Knowledge Base for VC++

Recently our Team has done a project in VC++.

Find below some useful links and other information collected by our Team member while doing this project.

1.The Following Links for know about Files in c++ CplusPlusTutorial for Files CplusCplus Tutorial for Files
2.Useful tutorial about create MFC Dialog MfCDialog
3.Any error occurred during compilation in MFC dialog based application vc++6.0 following link will be useful for handle that. VC++ Error Message
4.When I Run Cpp program it show error c1010 precompiled directive
Include header statement in your cpp file
Using namespace std;
5.When error occur on reading a file, like getline is undeclared identifier
Put #include header file in your cpp program
Refer this link if any clarification
6.Call Exe from MFC Exe ShellExecuteEx
If you want to execute a exe file form the mfc dialog application in vc+6.0 we can use ShellExecute or System or ShellExecuteEx Funtion Better Use the ShellExecuteEx funtion beacuse this function We can run any (.exe)file using ShellExecuteEx command it will handle the time taken to complete the loading process , onces it completed executing return 0 otherwise wait for the process until complete.
7.How to call Firefox.exe through command line parameter
The Following link will be useful for how to call every command through commandlineargument
Command Line Parameters
8.To Changing backcolor of dialog follow this link
Change Background color of dialog in mfc
9.How to display a string in window or button etc at runtime using variable
In Vc++6.0 all string are in lpcstr format so you can declare variable as normal string and caste to c.str() and pass it to function.
String sample;
10.How do we remove file from a folder ?
Use the following code
If( remove( "path”)!= 0 )
perror( "Error deleting file" );
puts( "File successfully deleted" );
return 0;
11.How do we pass variablename for giving path to open dynamic file at run time
Convert the string variable name to c.str(). and pass it the ifstream function
12.How do we set font for statictext or button caption ,radiobuttons etc.,
CFont m_Font; put this in header file of dialog
Add the following code to the initdialog
memset(&lf, 0, sizeof(LOGFONT)); // zero out structure
lf.lfHeight = 12; // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial"
VERIFY(m_Font.CreateFontIndirect(&lf)); // create the font
Call through member function
Follow this link is useful
13.How do display file contents or button using loop in dialog window continuously
We can call Doevents Function it repaint the window for each iteration .
void DoEvents() // for display at a time
MSG msg;
14.ADD PAGE UPAND PAGE DOWN in dialog window
How to Trigger function when pagdown and page up key is pressed
Follow this link
15.How do we change the title of the dialog Windows ?
If we create the mfc dialog application in some sample name, we want to rewrite the title name of the dialog window
Write this code on InitDialog
SetWindowText(“This is new title”);
16.How to display color text in button or label ,static text ?
Using OnCtlColor() function we can display color text
When this function called by program?
If we have create control at runtime ,it will call after creating control
(i)Decalaring function OnCtlColor() as a protected in dialogheader file
HBRUSH CclassnameDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
(ii)Define function with in DlgCpp file.
HBRUSH CRefreshcontDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID()==controlid )//if(nCtlColor==CTLCOLOR_BTN)
pDC->SetTextColor(RGB(255, 0, 0));//redcolor
pDC->SetBkColor(RGB(255, 255, 255));//background white color
return hbr;
17.How to set a pageup and down event in dialog mfc?
Add PreTranslateMessage function to your code by right click on dialogbox ,click classwizard and click add the function and click ok. In coding window write the following message.
OnKeyDown(pMsg->wParam, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
After that the same procedure followed by adding the PreTranslateMessage function to dialog window ,like that this function (WM_KEYDOWN) is added to your code window, OnKeyDownEvent catch the pageup or down when user press the key
if ( nChar == VK_PRIOR )
OnVScroll(SB_PAGEUP, 0, NULL);
else if ( nChar == VK_NEXT )
When we press page up or down , this keydown will call vscroll function for move the cursor positon to pageup or down.
18.How do we capture the button position in dialog window in mfc?
We use GetDlgItem function for getting the id of the control and use following code.
POINT pts;
CWnd *pwnd = GetDlgItem(IDC_BUTTON1);
pts.x = rc.left;
pts.y = rc.top;
19.How we will open multiple tabs in the firefox using command line arguments?
Firefox.exe www.google.com www.codeguru.com www.qualitypointtech.com

More Articles...

You can bookmark this blog for further reading, or you can subscribe to our blog feed.

No comments:

Search This Blog