|
|
CGDIObject* works with any GDI Object:
The CGdiObject class provides a base class for various
kinds of Windows graphics device interface (GDI)
objects such as bitmaps, regions, brushes,
pens, palettes, and fonts. <small>from MSDN</small>
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Thanks for all your help!!
Rob
|
|
|
|
|
Instead of having to worry about the SelectObject() calls, you can also do:
dc.SaveDC(); // save state of DC
....
dc.RestoreDC(-1); // restore state of DC (i.e. remove all selected objects in between)
dc.DeleteDC();
delete GDI objects.
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
Thank you - this might make things cleaner sometimes.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I've created a DLL from a class of mine where i use two std::vector<> members to store something. My problem is that when i insert an element on the vector, the first operation on the vector (clear it, read the first element,etc) cause an error on the heap:
File: dbgheap.c
Line: 1044
Expression: _CrtIsValidHeapPointer(pUserData)
HEAP[Print.exe]: Invalid Address specified to RtlValidateHeap( 28d0000, 28e3bd0 )
Using the class inside the program works well. It's a problem of the STL, something to include in the DLL compiling options?
|
|
|
|
|
Gian wrote:
It's a problem of the STL, something to include in the DLL compiling options?
It sounds more like it's a DLL-boundary issue with whatever chunk of memory you are trying to push onto the vector.
Perhaps some sample code would help.
-pete
|
|
|
|
|
my dll header is
#ifndef LFONTRENDERER_H
#define LFONTRENDERER_H
//--------------------------------------------------
# define GFONT_API __declspec(dllexport)
#include <string>
#include <vector>
#ifdef _WIN32
#include <windows.h>
#endif // _WIN32
#include <gl gl.h="">
//--------------------------------------------------
typedef unsigned int uint;
typedef unsigned char byte;
#define DEFAULT_HEIGHT 99999
struct LCharCoords
{
GLfloat left;
GLfloat top;
GLfloat right;
GLfloat bottom;
bool enabled;
float widthFactor;
};
struct LFont
{
std::string name;
GLuint textureId;
uint defaultHeight;
uint height;
float widthScale;
bool italic;
GLfloat angle;
GLfloat r, g, b;
LCharCoords chars[256];
};
struct LStringData
{
std::string str;
uint font; // the font to be used
uint height; // the height of the font
GLfloat r, g, b; // the color
GLfloat angle; // the rotation angle
GLfloat x, y; // the position
float widthScale; // width scale
bool italic; // true if the font is italic
};
//--------------------------------------------------
class GFONT_API LFontRenderer
{
public:
// default constructor, initializes the object
LFontRenderer();
// the destructor, automatically called by delete
virtual ~LFontRenderer();
// returns the number of fonts loaded
uint GetFontCount();
// returns the name of the given font, index _must_ be smaller than GetFontCount()
const std::string& GetFontName(uint index);
// sets the active font, this function is also available in a version that takes the index as parameter
void SetActiveFont(const std::string& name);
// sets the active font, this function is also available in a version that takes the name
// of the font as parameter
void SetActiveFont(uint index);
// returns the index of the active font, throws an exception if no fonts are loaded
uint GetActiveFont();
// this function loads a font from a file and adds it to the list of fonts it returns the index of
// the new font. The font name paramater is a name for the font that can be used with
// SetActiveFont() etc.
uint LoadFont(const std::string& fontname, const std::string& filename);
// removes all fonts and clears any memory allocated
void Clear();
// sets the height of the current font
void SetHeight(uint height);
// sets the color of the active font
void SetColor(GLfloat red, GLfloat green, GLfloat blue);
// returns teh height of the active font
uint GetHeight();
// call this to get the color of the active font
void GetColor(GLfloat &red, GLfloat &green, GLfloat &blue);
// call thos method to output a string
void StringOut(float x, float y, const std::string &string);
// this method draws all the strings
void Draw();
// this methods sets the width scale of the active font
void SetWidthScale(float scale);
// this method returns the width scale of the active font
float GetWidthScale();
// this method sets the rotation angle for the active font
void SetRotation(float angle);
// this method returns the rotation angle for the active font
float GetRotation();
// this function is used to set either the active font should be italic or not
void SetItalic(bool value);
// this function returns true if the active font is italic
bool GetItalic();
// this function returns the width of the string. font metrics of the active font
// are used
uint GetStringWidth(const std::string &string);
protected:
// used internally
uint m_strCount;
// the index of the active font
uint m_activeFont;
// the array of fonts
std::vector<lfont> m_fonts;
// the strings to be rendered
std::vector<lstringdata> m_strings;
// the size of the viewport
uint m_viewTop;
uint m_viewLeft;
uint m_viewWidth;
uint m_viewHeight;
#ifdef GL_VERSION_1_3
// used internally, the number of supported texture units;
uint m_textureUnits;
#endif // GL_VERSION_1_3
};
//--------------------------------------------------
#endif // LFONTRENDERER_H
|
|
|
|
|
in
// the array of fonts
std::vector m_fonts;
// the strings to be rendered
std::vector m_strings;
the first is the template of LFont and the second of LStringData (the < and > are missing in the post)
|
|
|
|
|
In my OnClose I save a bunch of stuff to the registry.
int res = RegCreateKeyEx(keyHandle1, "ABC", 0, "",
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&keyHandle2, &disp);
if<code>(!res)</code>
{
AfxMessageBox ("exiting");
CMDIFrameWnd::OnClose();
}
I know its better to say res != ERROR_SUCCESS, but anyways in the above if the key gets created or opened I want to exit the app. There is more code after this block. If I run as is, it crashes. I thought CMDIFrameWnd::OnClose(); would terminate the app...? Do I need to call PostQuitMessage explicitly?
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
I thought CMDIFrameWnd::OnClose(); would terminate the app..
No, it just closes the window. If you don't want to execute the rest of your code add a return; after CMDIFrameWnd::OnClose();
--
karl
|
|
|
|
|
First, as you said, typing if(!res) is bad practice. You should apply unary negation operator only to boolean expressions. FYI, C# prohibits such code.
But your question was not about that. I'd suggest using PostQuitMessage, 'cause OnClose is a simple message handler. It contains only code relevant to closing frame window, so semantically it is not the same as quitting the application.
However, I'm not sure if replacing OnClose with PostQuitMessage is going to solve the problem. Since the application crashes, it's most likely something else. Why don't you run it through debugger, step by step, and see where it crashes? Usually this helps.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
Thanks! I shall test further....
Appreciate your help,
ns
Once I put in the return in the if block, it didnt crash....so apparently I shouldnt try to execute any more code after OnCLose is called...
|
|
|
|
|
hello,
i'd like to convert rtf files into standard bitmap format, like bmp or jpeg.
the solution i have now is to open the rtf and print with a simulated windows
printed which generates a bitmap. but it would be good to find a direct solution,
maybe someone knows how to do this, or a product/library, which can do this?
thanks
enrico
|
|
|
|
|
Sir, I want to access Webcam by capturing images through VC++. How can I do it???
C.R.Naik
|
|
|
|
|
There are image capture examples in the DirectX SDK
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Would you please tell me from where can I get that help and example?
C.R.Naik
|
|
|
|
|
I am using MS Word automation in my C++ project to create a Word document that contains several tables. I've been able to create the document and give it a specific format such as font sizes, paragrpah aligment...
My problem is that i am not capable of center a table. This is the code i use:
//get the range
oRange = oSelection.GetRange();
oTables = Doc.GetTables();
//try to center the paragraph where the table will be placed
oParagraphs=oRange.GetParagraphs();
oParagraphs.SetAlignment(1);
// Create a 5x5 table
oTable = oTables.Add(oRange,5,5,covTrue,covTrue);
But this doesn't seem to work, the table appears with left aligment.
Has anyone tried to center a table?
Thanks
|
|
|
|
|
Hi, everyone!
Look at the following codes,
--------
const char* p = "12345";
char* q = "54321";
--------
If I want to release the memory, should I use
--------
delete[] p;
delete[] q;
--------
or should I use
--------
delete p;
delete q;
--------
Thanks in advance,
George
|
|
|
|
|
You don't need to release the memory of these variables because they aren't allocated on heap but on stack. Defining char* q ="54321"; is the same as defining char q[6] = "54321"; .
You only need to use delete/delete [] for variables created with new/new [].
--
karl
|
|
|
|
|
Thanks, karl buddies!
George
|
|
|
|
|
Rule of thumb: You did not call new , you do not need to call delete .
For
char* r = new char[MAX_PATH+1];
you would call
delete[] r;
since you did a new[] .
But this is one of the cases where it does not matter, since char is an integral type and as such has no constructor or destructor.
The difference between delete and delete[] is that delete[] calls the destructor of every item to be deleted, whereas delete calls only the destructor of the first item.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Thanks, jhwurmbach buddies!
George
|
|
|
|
|
jhwurmbach wrote:
But this is one of the cases where it does not matter, since char is an integral type and as such has no constructor or destructor.
This is true on most, but not all compilers. According to the standard, new must be deleted, and new[] delete[]'d.
There is no guarantee that the compiler implements new[] "on top of" new. It could even use different heaps for that!
Nur wer feige ist tötet Liebe durch das Wort allein [sighist] | [Agile Programming] [doxygen] If you look for evil in me you will find it whether it's there or not.
|
|
|
|
|
Thanks, peterchen buddie!
George
|
|
|
|