|
Thnx for the reply on my message,
But actually I don't just want to copy some prepared codes where you just have to code for example: SendText("Hi how are you") and the rest goes by itself.
I want to know what I've done vrong with my code and what do I have to change in my code or what code do I have to add in my code.
I've seen some peaces of code using WriteString() and ReadString() with CArchive (wich needs also CSocketFile). I've seen also some codes using Send() and Receive of CSocket class.
When I know how to use these codes I can alway encapsulated them just like NDK application you reffered it to.
So I hope you can help me more about WriteString() and ReadString() and I hope other guys can help me too, you are all welcome.
If my application works, I forget all my problems.
|
|
|
|
|
I am trying to pass a pointer to an object to a function, and have this function to the work of creating the object. Although the object is assigned properly within the method, upon returning to the calling function, the object pointer that was passed has not changed. Could someone explain to me what is going on here?
I have an abstract class A and an inherited class B
<br />
Class A { doSomething(){} }<br />
<br />
Class B : A{<br />
int x;<br />
B(int x){<br />
this->x=x;<br />
}<br />
}<br />
Now, I want my class C to have a method that creates a pointer to A, passes this to a function, and that function changes the pointer so that it points to a new object of type B.
<br />
Class C {<br />
getB(){<br />
A* a;<br />
FindIt(a);
}<br />
<br />
FindIt(A* a){<br />
int x=1;
B* b = new b(x);
a = (A*)b;
}<br />
}<br />
So, when I debug...after the call to Find It, a is not pointing at the correct memory address. What is going on?
whitee
|
|
|
|
|
You were passing a copy of the "a" pointer to FindIt(). You need to pass it by address(or reference).
Class C {
getB(){
A* a;
FindIt(&a);
}
FindIt(A** a) {
int x=1;
B* b = new b(x);
*a = (A*)b;
}
}
|
|
|
|
|
I have initialized DX7, i have two buffers.
But I cannot figure out wich interface that have functions for rectangles, lines and so on.
the area I want to paint on is a LPDIRECTDRAWSURFACE7 interface. Can I through that get hold of an interface that has line/arc/rectangle functions?
|
|
|
|
|
I'm trying to use wglUseFontBitmaps to display some text in OpenGL.
now, it's working fine, I'm doing something like :
m_iDisplayListBase = 1000;
glDeleteLists(m_iDisplayListBase, 256);
m_iDisplayListStart = glGenLists(256);
BOOL b = wglUseFontBitmaps (m_hDC, 0, 256, m_iDisplayListBase);
...
glListBase(m_iDisplayListBase);
glColor4f( 0.8, 0.1, 0.8, 1);
glRasterPos3i( 20, iHeight-10 - m_iFontHeight, 1);
glCallLists (24, GL_UNSIGNED_BYTE, "Hello Win32 OpenGL World");
Now, the questions.
1 - When using glGenLists to generate a number of empty display lists ( to be filled by wglUseFontBitmaps ), it returns the number (ID?) of the first display list ? so, should the argument to glListBase be ID + someArbitraryValue ? or will this be done automatically ?
2- When using wglUseFontBitmaps, do I need to do something else if I want to recreate the display lists for a different font size ? can I reuse the same "font bitmaps" ?
Thanks.
Max.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
1 - When using glGenLists to generate a number of empty display lists ( to be filled by wglUseFontBitmaps ), it returns the number (ID?) of the first display list ? so, should the argument to glListBase be ID + someArbitraryValue ? or will this be done automatically ?
What is actually happening is that the glListBase(n) is setting the base of the next set of calls to n. In your case your Display list base index for your font. the function glCallLists() will generate one call per ascii value, thus you generate a full 256 count for your font. But the actual call is the combination of the last glListBase(n) adding the ascii value from the glCallLists() for each character.
Maximilien wrote:
2- When using wglUseFontBitmaps, do I need to do something else if I want to recreate the display lists for a different font size ? can I reuse the same "font bitmaps" ?
I have 3 different font selections in my program. Remember that the callLists is the sum of the base plus the ascii value. So you allocate a new set of 256 lists, I would suggest switching to an index variable name that reflects the font so you don't get confused.
However, remember that your driver may handle display lists in system memory or compiled and stored on the graphics card. You are generating 256 bitmap image display lists for every font. If you want to have multiple fonts on the screen at the same time, you will need three different sets of display lists. If you want the user to choose his font, do so ahead of building the font, and generate only one from the user definition. Don't use more memory than you need to. You can also cheat, make sure the text is in 7bit form (0-127 ASCII) and only generate 128 display lists. If you do, don't forget to check the string or you will get unknown results for any >127 values.
I rewrote this code as I pasted to remove some "stuff" hope it helps. You can also look into texture based fonts which may be much faster on some hardware. Google for OpenGL tutorials at "Nehe" and you will find text tutorials.
<br />
int BuildFont(char *fontname, int point, int bold)<br />
{<br />
GLint base;<br />
HFONT__ *font;<br />
struct HDC__ *h_DC;<br />
<br />
base = glGenLists(256);<br />
font = CreateFont(point,
0,
0,
0,
bold ? FW_BOLD : FW_NORMAL,
0,
0,
0,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FIXED_PITCH,
fontname);
<br />
h_DC = GetDC(NULL);<br />
SelectObject(h_DC, font);
<br />
wglUseFontBitmaps(h_DC, 0, 256, base);
return base;<br />
}<br />
m_LargeTextBase = BuildFont("Arial Bold", LargeTextPitch, LargeTextBold);<br />
m_SmallTextBase = BuildFont("Arial Bold", SmallTextPitch, SmallTextBold);<br />
m_MediumTextBase = BuildFont("Arial Bold", MediumTextPitch, MediumTextBold);<br />
...<br />
glListBase(m_SmallTextBase );<br />
glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);<br />
...<br />
glListBase(m_MediumTextBase);<br />
glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);<br />
...<br />
glListBase(m_LargeTextBase);<br />
glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);<br />
<br />
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Thanks for the Nehe reference, I will look at those tutorials tonight ...
I thought about using a couple of different font size display lists. I will make my life a bit easier; maybe that will be enough.
Thanks again.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I have C background but I need something like pointer so store two double variable data. Could anyone show me how or post some tutorial website here? Thanks.
|
|
|
|
|
One way:
double d1 = 5.1;
double *p1 = &d1; Another:
double *p1 = new double;
*p1 = 1.8;
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thx
I am using VC++, any easier class in MFC? The way you used seemed like C.
|
|
|
|
|
jw81 wrote:
any easier class in MFC?
What I provided was not easy?
Are you sure that you understand what you are asking? A pointer in C is the same pointer in C++. Encapsulating a simple pointer into a C++ class is unnecessary.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
My mistake, I was thinking abt linked list. Sorry abt the confusion. Does VC++ linked list same as C?
Thanks.
|
|
|
|
|
yes; all C constructs are C++ compatible.
but I would suggest using either MFC collections or STL collections
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thanks Maximilien,
This is the actual question I am asking, could you suggest any MFC function that I can use for such case (linked list)? There are quite a lot of solution from MFC but I dont know which one is the best. If it is too difficult to show here could you post any url related to such case? Thanks.
|
|
|
|
|
jw81 wrote:
I can use for such case (linked list)?
Look for Collection Classes in MSDN. Some of them are
or In STL
"I Think this Will Help"
Alok Gupta visit me at http://www.thisisalok.tk
|
|
|
|
|
store where and how ?
double* d1;
double* d2;
d1 = new double;
*d1 = 0.4;
d2 = new double;
*d2 = 0.3;
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Here is the
Screen Shot
The problem is that background is not solid, it has gradient so I can't erase background of my controls with solid rectrangle as defauld controls do.
(The code you've posted before also seems to be filling only solid rectangle)
rrrado
|
|
|
|
|
Then the solution is to forward the WM_ERASEBKGND message of a control to the wnd proc of the parent dialog that is responsible for drawing a gradient background. Before passing a DC handle, set the viewport origin to match the control position in the dialog.
Another problem with group boxes is correct painting of contained sibling controls. If this problem will arise, try this :
void myGroupBox::PreSubclassWindow()
{
ASSERT(::GetWindowLong(::GetParent(m_hWnd), GWL_STYLE) & WS_CLIPCHILDREN);
ASSERT((::GetWindowLong(m_hWnd, GWL_STYLE) & BS_TYPEMASK) == BS_GROUPBOX);
ModifyStyle(0, WS_CLIPSIBLINGS);
SetWindowPos(&CWnd::wndBottom, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
CButton::PreSubclassWindow();
}
Group boxes are a common headache for all programmers. The simplest solution is to avoid gradient background and make it just lighter than common COLOR_BTNFACE , 75 percent - that will do and look neat.
One always gets the deserved.
http://www.silveragesoftware.com/hffr.html Update your source code with my tool HandyFile Find And Replace!
|
|
|
|
|
Thank you very much for your help, but finally I've found the easiest solution, without owner drawing nor any message handling, it seems that
all I need to use this function on my dialog in OnInitDialog():
EnableThemeDialogTexture()
rrrado
|
|
|
|
|
WOW !!!! in fact I have to thank You!!! I always used to invent a wheel for my dialogs in respect to they look, and never thought there's a function like this!!!
One always gets the deserved.
http://www.silveragesoftware.com/hffr.html Update your source code with my tool HandyFile Find And Replace!
|
|
|
|
|
I have a critical section that enables thread-safe reading from / writing to a CMapStringToString object.
The CMapStringToString could possibly grow in size to have around 200000 entries, where the 'key' is a string of <=6 characters, and the value will, on average, be around 300 characters.
Firstly, does anyone know how much memory a CMapStringToString object with 200000 entries with keys 6 characters long and values 300 characters long will actually use?
Secondly, when I call the Map's Lookup() function, will this start to take a long time to return if my map grows to this kind of size? Would this slowing down make it unsuitable to use inside a critical section which is probably being accessed by a different thread eg. 4 times per second?
Thanks for any thoughts anyone might have,
Matt
|
|
|
|
|
Firstly, you should set your initial block size to a large number to create more hash buckets, thereby separating your strings into smaller sets and decreasing the search time.
If you need to access this many elements so frequently via multiple threads, I would suggest that you create a higher level hash table (of smaller size) that would contain locks (critical sections) and pointers to individual sections (hash tables) of the entire data set. By doing this, you will get higher concurrency at the cost of more memory usage. This way, you would lock only a section of the set that you were interested in, rather than the entire set.
onwards and upwards...
|
|
|
|
|
I have a couple of questions about using the CCriticalSection class. Firstly, is there any difference between the way the critical section works by using it in the following two manners:
1)
CCriticalSection blocker;
blocker.Lock();
// Do something
blocker.Unlock();
2)
CCriticalSection blocker;
CSingleLock singleLock(&blocker);
singleLock.Lock();
// Do something
singleLock.Unlock();
Also, am I correct in saying that using either of these methods, no thread will time-out when waiting for the critical section to become free - they will just wait until it's they're turn to use the code?
Any comments would be much appreciated,
Thanks,
Matt
|
|
|
|
|
Hi Matt
The CCriticalSection class is the lock that is accessed from more than 1 thread and ensures that if 1 thread has called CCriticalSection::Lock (not having called CCriticalSection::Unlock yet), another thread's call to CCriticalSection::Lock will block - effectively suspending the second thread until the first calls CCriticalSection::Unlock.
The CSingleLock class is simply a smart-pointer style helper class that acts on the CSyncObject that is passed in with it's constructor - in essence, it just calls the CSyncObject::Lock in it's constructor and CSyncObject::Unlock in the destructor. That way you can have the SyncObject's Unlock method automatically called when the CSingleLock local variable goes out-of-scope....
but an example says a thousand words;
CCriticalSection csGlobal; // global variable, or such..
void Thread1()
{
CSingleLock lock(&csGlobal);
// do stuff
}
void Thread2()
{
CSingleLock lock(&csGlobal);
// do stuff
}
So you can see that the smart-pointer style local CSingleLock instances really just capitalise on the C++ destructor to help you remember to call csGlobal.Unlock. Without the CSingleLock, you could end up writing (faulty) code like this;
void Thread3()
{
csGlobal.Lock();
// do some stuff
if (bFailed)
return; // !!!! didn't call csGlobal.Unlock();
// do more stuff
csGlobal.Unlock();
}
Lastly, the explicit Lock/Unlock methods on CSingleLock is really if you can't wait for the destructor, and need to Unlock and possibly Lock again.
I hope this makes sense.
Martin
|
|
|
|
|
If I use a class which has 10 methods and 10 attributes, but I only access/use 5 methods and 5 attributes from that class in my program, will the resultant executable also include code/data for the other 5 methods and attributes ?
I suppose I'm asking if the linker is clever enough to discard unused functions and data.
PS. I'm using Visual C++ 6.
|
|
|
|
|