|
Hi all of you. How can I convert COleVariant to COLORREF ?
I have used CMFCPropertyGridColorProperty to store a colorref into CMFCProperrtyGrid, but I need to retrieve correctly the colorref value, because CMFCPropertyGridColorProperty have been filled with COleVariant ...
I get the value just like this:
CMFCPropertyGridProperty* pProp = m_wndPropList.FindItemByData(TRM_PROPERTYGRID_COLORWINDOW);
pProp->GetValue();
but GetValue get me COleVariant, and I have there COLORREF value ... how can overcome this ? I get the following error:
error C2440: 'return' : cannot convert from 'const COleVariant' to 'COLORREF'
Thank you.
|
|
|
|
|
Since COLORREF is a DWORD , can't you just access the ullVal member of COleVariant ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
|
Hello all... how do I create array of char* . At the moment I have hardcoded the number of instances (large enough to hold tokens) but this should be generic. Example
int temp_array[2] = {0};
char* token1;
char* token2; As you can see, I might not know how many tokens I need at run time. I want something like this
char* [] tokens; How could I fix this? Thanks
modified 12-May-17 6:00am.
|
|
|
|
|
Create a variable for the array that is initially empty and a variable holding the size:
char **tokens = NULL;
unsigned tokenSize = 0;
Once you know the required number of items, allocate the array. How to do that depends if you are using C or C++:
tokenSize = items_to_store_in_array;
tokens = new char *[tokenSize];
tokens = (char **)malloc(sizeof(char*) * tokenSize);
If you need to change the size use realloc with C.
With C++ you should then avoid arrays and use a container like vector - C++ Reference[^] instead.
|
|
|
|
|
Jochen Arndt wrote: How to do that depends if you are using C or C++:
Well I should have mentioned that earlier..... I am using C. Can you please edit your question (or append the code for C)
|
|
|
|
|
The C code is there (the malloc call).
Use something like this (for two tokens):
tokenSize = 2;
tokens = (char **)malloc(sizeof(char*) * tokenSize);
tokens[0] = token1;
tokens[1] = token2;
free(tokens);
tokens = NULL;
tokenSize = 0;
|
|
|
|
|
Only addition to Jochens answer is to remove confusion to you typedef the char* pointer
ptrCount = 2;
typedef char* CHARPTR;
CHARPTR* charPtrArray = (CHARPTR*)malloc(sizeof(CHARPTR)*ptrcount);
Now it looks like any other array
The confusion exists because char** can be a couple of things in C you can't distinguish them without looking at the initialization code
1.) A pointer to a char* (always true)
2.) An array of char* (if initialized as such)
3.) A multidimensional char array (if initialized as such)
Number 3 in particular usually causes mass confusion with students learning C.
The typedef doesn't stop you assuming the wrong thing but it does give you language cues to what it is and is easier to read.
In vino veritas
modified 14-May-17 22:51pm.
|
|
|
|
|
std::vactor<char*> m_myArrayOfString ;
m_myArrayOfString.push_back(new char[17]);
...
...
in the end loop through vector and delete them one by one
for(auto ptr : m_myArrayOfString)
delete [] ptr ;
m_myArrayOfString.clear();
huzifa
|
|
|
|
|
Think of an array of chars as a 2d map.
So along the bottom the x axis can be considdered as an array of char pointers, each one pointing to a vertical array of chars going up in the y direction.
So point 0,0 is a char**
You can of course extend this to a 3 d map, with char***
Any point on the 2d map can be referenced by data[x][y]
SO first you alloc how many you need in the x direction: char** data = alloc(xMax)
Now each vertical collum can be alloced as data[0] = alloc(y1Max) data[1] = alloc(y2Max)
And so on.
|
|
|
|
|
the following are the related code,could someone can help me,
void CXXXStatic::PreSubclassWindow()
{
DWORD dwStyle = GetStyle();
SetWindowLong(GetSafeHwnd(),GWL_STYLE,dwStyle | SS_OWNERDRAW);
CStatic::PreSubclassWindow();
}
void CXXXStatic::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
}
CXXXStatic m_Static;
m_Static.Create("hello", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(100, 100, 200, 200), this,0x0301);
|
|
|
|
|
That is because SS_OWNERDRAW is not a bit value that can be O-red to the style but a masked value.
Use
SetWindowLong(GetSafeHwnd(),GWL_STYLE,( dwStyle & ~SS_TYPEMASK) | SS_OWNERDRAW); instead.
Or better:
ModifyStyle(SS_TYPEMASK, SS_OWNERDRAW));
|
|
|
|
|
Hello all. I am trying to re-use a file pointer at the start of the program and then close this when program is shutting down, after some work with it. So far I have come up with this
globals.h
=========
extern FILE* ptrLogFile;
file1.c
=======
#include "globals.h"
FILE* ptrLogFile = fopen("RequestsLog.log", "a+");
file2.c
========
#include "globals.h"
FILE* ptrLogFile = fopen("RequestsLog.log", "a+");
file3.c
========
#include "globals.h"
fclose(ptrLogFile);
But this is not what I am looking for. I want to initialize, using fopen() , the ptrLogFile just once (may be in globals.h ?) and then re-use it in file1.c and file2.c as long as I want. Finally close it in file3.c when the program is shutting down. How do I do this? Thanks
modified 9-May-17 9:17am.
|
|
|
|
|
You have to define and initialise the global variable within one source file:
FILE* ptrLogFile = NULL;
Then use it anywhere this way:
#include "globals.h"
if (NULL == ptrLogFile)
ptrLogFile = fopen("RequestsLog.log", "a+");
#include "globals.h"
if (NULL == ptrLogFile)
ptrLogFile = fopen("RequestsLog.log", "a+");
#include "globals.h"
if (NULL != ptrLogFile)
{
fclose(ptrLogFile);
ptrLogFile = NULL;
}
|
|
|
|
|
Thanks. I got it working. But the log file is not getting updated until I close my program. How do I update the log file even when the program is running?
|
|
|
|
|
Call fflush[^] after writing to the stream.
|
|
|
|
|
Don't do it that way. Create a function or library module that does all the work and then just call the actual logging functions anywhere in your code. Call the initialiser, to open the file, at the beginning of your main module, and the closing operation just before your main program terminates.
|
|
|
|
|
Here's how I deal with global variables. I have one header file, I call Globals.h, with these definitions :
#ifdef DEFINE_GLOBALS
#define Global
#define GlobalVar(Type,Variable,Value) Type Variable=Value
#else
#define Global extern
#define GlobalVar(Type,Variable,Value) extern Type Variable
#endif
Then, in one and ONLY one file do this :
#define DEFINE_GLOBALS
#include "include "Globals.h"
#endif
before I include headers that define variables.
Here are some sample definitions :
typedef FILE * PFILE;
GlobalVar( PFILE, PtrLogFile, NULL );
GlobalVar( size_t, LineCount, 0 );
|
|
|
|
|
Hi
basically my problem is how to get rid of flickering when i use customdraw.
I know about double bufering, bckgnderase and any other solutions, but all of them do not work in my case, because my customdraw is called for each item (when resizing window(mfc behavior)) and for some of them when multiselection happens. CustomDraw is called from OnNotify(need that because i am extending normal tree with columns like in listView - so it look smth like Grid with expandable rows).
Cause of all that behavior that i need, got no idea how to apply double buffering into this, cause there's none notification when to bitblt offscreen bitmap into screen.
Would appreciate any ideas.
|
|
|
|
|
|
Richard MacCutchan wrote: See WM_SETREDRAW message (Windows)[^].
Same problem like with bitblt there's no proper place to call that one. MFC calls NM_CUSTOMDRAW for each element. So i've got no control over this "message loop".
|
|
|
|
|
|
|
Actually using this one as base. Anyway thx for reply.
|
|
|
|