|
Can you more explain and some detail of your program?
|
|
|
|
|
Hi,
Yes, but I think the problem may be solved now.
http://i91.photobucket.com/albums/k282/Benchmark_Avionics/Properties.png[^]
Someone informed me that a recent change in the game program included some libraries that require now that we statically link the program. So, I have recompiled and will not test this in the morning.
Thanks guys for your ideas. I'll let you know if this was the problem for everyone's future reference.
As I am using MS DirectInput and DirectSound in this project, I was worred it had to do with DirectX, but seems it has to do with the recent game update.
|
|
|
|
|
Glad you found the answer.
|
|
|
|
|
Sorry for my poor English.
Is it the issue of debug version and release version ?
|
|
|
|
|
No, we tested that, but it may be solved now. (See above).
|
|
|
|
|
Hi,
How to restrict the number of objects created for a class??
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
It is hard to know with such a general description - do you have more details?
Basically I guess you have to count them, you could have a static int member of the class, initialised to zero, that you increment in all constructors, and when you reach a limit you do something like throwing an exception.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
cp9876 wrote: you do something like throwing an exception.
Only if there is no other solution which would almost never be the case.
led mike
|
|
|
|
|
That's why I like code project - I learn things! Putting this sort of functionality in some sort of factory is a much better idea.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Do some research on reference counting and factory patterns
led mike
|
|
|
|
|
narayanagvs wrote: How to restrict the number of objects created for a class??
- Make the constructor private.
- Add a static factory method (eg:
CreateInstance() ) to the class. The method should count the number of instances served up and use this value to control the behavior of the CreateInstance() method.
- In the object's destructor, decrement the instance count (held as a static member).
/ravi
|
|
|
|
|
THis issue is addressed by the singleton design pattern (yes, despite of the name, the singleton can also allow more than one instance of the related object). You can find a complete reference of the signleton in the following book: Design Patterns: Elements of Reusable Object-Oriented Software [^].
BTW you can also find some singleton related stuff on google.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
hi.
I have a MDI program done in CFormView which have a scrollbar control. when I minimize the child window and use the scrollbar of the child window, the scrollbar control in the CFormView follows the scrollbar of the child window.
How can I the make the scrollbar control independent of the scrollbar of the child window?
Thank you.
|
|
|
|
|
Hi,
are you setting the parent of the second control bar to the child window?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
hi.
control bar refers to toolbars, status bars, dialog bars and rebars?
Im don't use any of them. I only have menu.
|
|
|
|
|
Hello,
Can someone please tell me how to convert from CString to const* char?
I used the following from msdn website:
<br />
const size_t newsize = 100;<br />
char nstring[newsize];<br />
strcpy_s(nstring, orig);<br />
strcat_s(nstring, " (char *)");<br />
cout << nstring << endl;
But it requires that I compile with clr. When I do that, my classx.cpp (all my class function) are considered errors.
When I don't modify the property of my solution to clr, I still get two errors:
fatal error C1190: managed targeted code requires a '/clr' option
Is there any other way to convert without using clr?
Thank you.
--Star
|
|
|
|
|
This is not clr code, I can't imagine how it gives you this error.
The CString class has a GetBuffer method that returns a char *. Not sure if it is char or TCHAR, but so long as you're not building Unicode, they are the same.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
Why dont you use the "strcpy" and "strcat" respectivily instead of using "strcpy_s" and "strcat_s". Since the later 2 functions have more securuty enchancements you problem could be related with that.
Manoj
Never Give up
|
|
|
|
|
manojkumarrai wrote: Why dont you use the "strcpy" and "strcat" respectivily instead of using "strcpy_s" and "strcat_s".
I guess, one should always use enhanced versions of functions. Isn't it ?
manojkumarrai wrote: have more securuty enchancements you problem could be related with that.
.
How could be that ?
Prasad
MS MVP - VC++
|
|
|
|
|
In addition to previous reply, have a look at CString::operator LPCTSTR .
Again, it depends on project settings.
Prasad
MS MVP - VC++
|
|
|
|
|
HELP! Caption bar buttons don't work on XP display. The minimize/restore/close buttons appear very big on XP and hence when you click on the upper left corner of the minimize button on XP, nothing happens. YOu have to move the mouse the lower right corner of the minimize button to get it to work. Could someone please tell me what i need to do to get the captionbar buttons to work on XP display. Thanx in advance.
////////////////
// Draw min, max/restore, close buttons.
// Returns total width of buttons drawn.
//
int CCaptionPainter:rawButtons(const PAINTCAP& pc)
{
ASSERT(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
DWORD dwStyle = wnd.GetStyle();
if (!(dwStyle & WS_CAPTION))
return 0;
ASSERT(pc.m_pDC);
CDC& dc = *pc.m_pDC;
int cxIcon = GetSystemMetrics(SM_CXSIZE);
int cyIcon = GetSystemMetrics(SM_CYSIZE);
// Draw caption buttons. These are all drawn inside a rectangle
// of dimensions SM_CXSIZE by SM_CYSIZE
CRect rc(0, 0, cxIcon, cyIcon);
rc += CPoint(pc.m_szCaption.cx-cxIcon, 0); // move right
// Close box has a 2 pixel border on all sides but left, which is zero
rc.DeflateRect(0,2);
rc.right -= 2;
dc.DrawFrameControl(&rc, DFC_CAPTION, DFCS_CAPTIONCLOSE);
// Max/restore button is like close box; just shift rectangle left
// Also does help button, if any.
BOOL bMaxBox = dwStyle & WS_MAXIMIZEBOX;
if (bMaxBox || (wnd.GetExStyle() & WS_EX_CONTEXTHELP)) {
rc -= CPoint(cxIcon, 0);
dc.DrawFrameControl(&rc, DFC_CAPTION,
bMaxBox ? (wnd.IsZoomed() ? DFCS_CAPTIONRESTORE : DFCS_CAPTIONMAX) :
DFCS_CAPTIONHELP);
}
// Minimize button has 2 pixel border on all sides but right.
if (dwStyle & WS_MINIMIZEBOX) {
rc -= CPoint(cxIcon-2,0);
dc.DrawFrameControl(&rc, DFC_CAPTION, DFCS_CAPTIONMIN);
}
return pc.m_szCaption.cx - rc.left - 2;
}
|
|
|
|
|
|
I'd like to use this function instead.... But I'm not sure how I can incorporate it instead of DrawFrameControl if OS ix XP, any ideas?
BOOL
PaintThemeCaptionMaxButtonNormal(
IN CONST HWND hWnd,
IN CONST HDC hDC,
IN CONST POINT ptTopLeft
)
{
BOOL bRet = FALSE;
if (hWnd && hDC)
{
HTHEME hTheme = OpenThemeData(hWnd, L"WINDOW");
if (hTheme)
{
SIZE sz;
if (S_OK == GetThemePartSize(
hTheme, hDC, WP_MAXBUTTON, MAXBS_NORMAL,
NULL, TS_TRUE, &sz))
{
RECT rc;
if (SetRect(&rc, 0, 0, sz.cx, sz.cy) &&
OffsetRect(&rc, ptTopLeft.x, ptTopLeft.y))
{
bRet = (S_OK == DrawThemeBackground(hTheme,
hDC,
WP_MAXBUTTON, MAXBS_NORMAL, &rc, &rc));
}
}
CloseThemeData(hTheme);
}
}
return bRet;
}
|
|
|
|
|
hi,i am new to visual C++ programming. i have a simple visual C++ program that involves basic sql transactions and if a query fails then i have tried to rollback all the previous transactions as well. I am using MS SQL Server. the problem is that the rollback is not working in the tables in the server while when i run the program in the debug mode it shows that the rollback feature is working as it returns a positive integer from the rollback() function. the program shows no errors or warnings.
Can anyone provide some suggestions? For testing i have used three queries in which the third one has been intentionally left wrong. I need the first two queries to be rollbacked when the error occurs in the third query.
Would be glad if you can point out other errors as i am still learning C++ programming...
Attached is the code:
<br />
class test<br />
{<br />
<br />
public:<br />
void testmethod()<br />
{ CDatabase dbobject[100];<br />
static int counter=0;<br />
char query [3][100]={{"Insert into product values (1,'keyboard')"},{"Insert into product values (2,'mouse')"},{"Insert into product values (2,'cable')"}};<br />
try<br />
{<br />
for(int i=0;i<(sizeof(dbobject)/sizeof(dbobject[0]));i++)<br />
{<br />
dbobjectIdea.OpenEx(_T( "DSN=mytest" ),CDatabase::noOdbcDialog );<br />
dbobjectIdea.BeginTrans();<br />
dbobjectIdea.ExecuteSQL(queryIdea);<br />
dbobjectIdea.CommitTrans();<br />
cout<<"Query Execution Successful\n";<br />
counter++;<br />
dbobjectIdea.Close();<br />
}<br />
}<br />
catch (CDBException *pEx)<br />
{<br />
pEx->ReportError();<br />
dbobject[counter].Close();<br />
for(int j=counter-1;j>=0;j--)<br />
{ dbobject[j].OpenEx(_T( "DSN=mytest" ),CDatabase::noOdbcDialog );<br />
dbobject[j].BeginTrans();<br />
int c = dbobject[j].Rollback();<br />
dbobject[j].Close();<br />
cout<<"SQL Query Rollbacked!\n";<br />
}<br />
}<br />
}<br />
};<br />
void main()<br />
{<br />
test t;<br />
t.testmethod();<br />
}
|
|
|
|
|
Sorry for my poor English .
I can't tell you the reason of error . It is different in debug and release , so you can debug in release state .
Project settings -> link -> Generate debug info (selected)
Project settings -> C/C++ -> Debug info(select program database)
Project settings -> C/C++ -> Optimizations(select disable(debug))
Then pass F5 to run program used for debug .
我不能够告诉你错误的原因。debug 版本和 release 版本是不同的,你可以在release状态下调试。你做如下设置
Project settings -> link -> Generate debug info (selected)
Project settings -> C/C++ -> Debug info(select program database)
Project settings -> C/C++ -> Optimizations(select disable(debug))
然后就可以f5进行运行调试了。
|
|
|
|