|
void CChildView::sortData(LPCTSTR sendData)
{
TCHAR buffer[1024];
_sntprintf(buffer, 1024, _T("%s"), sendData);
DisplayData(buffer);
}
|
|
|
|
|
typedef wchar_t TCHAR; // UNICODE
typedef char TCHAR; //ANSI, DBCS
typedef const TCHAR* LPCTSTR;
Therefor, if you are compiling a UNICODE program then LPCTSTR is defined as const wchar_t*, otherwise it is defined as const char*.
If want to be able to create ANSI and UNICODE version of your code, then you need to use TCHARs and the macro _T()(or TEXT()), along with the functions define to use TCHARs (normaly they start with _tc???()).
If all you need to work with is ANSI, then you can use plain old C-strings: char, char*, const char*.
size of in BYTEs = (string length in TCHARs)/sizeof(TCHAR).
byte_len = _tcslen(str)/sizeof(TCHAR);
byte_len = strlen(str)/sizeof(char); // equal to strlen()/1
byte_len = wcslen(str)/sizeof(wchar_t); // wcslen(str)/2
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Does anyone know any common/basic time functions in C / C++?
I want to write a frequency function that will call another function, every set period. For example, if the period was set for every 5 seconds, then the function will 'tic' every 5 seconds.
I notice there is no built-in functions for this sort of clock / tic functionaility. What is the easiest way? Or the best most efficient way or implementing a clock / tic function?
C method first, then if it's better, C++.
|
|
|
|
|
|
I was looking for a non-Visual C++ specific way. Someway by the standard C library. I believe SetTimer() is a Microsoft C++ function.
|
|
|
|
|
SetTimer() just a Windows API. the only other thing I can think of is to spawn another thread and have it execute an infinite loop that calls Sleep() for the amount of milliseconds you need, then call the function you want it to execute
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Or the secondary thread can call WaitForSingleObject with a timeout.
That way, it is easy to get the thread to STOP if you set an event, or else it will exipre over the itme interval and return WAIT_TIMEOUT . This prevents the need to KILL the thread to get it to stop before the timeout period has elapsed. If you want the thread to respond to messages, then use the MsgWaitForMultipleObjects . Having the thread Sleep() just makes other parts of the application unresponsive and is poor design, such as in system shutdown
The timing will not be terribly precise, but if you can tolerate +-1 second or less, you are probably fine.
|
|
|
|
|
I have seen a lot of discussion and examples on sub-classing existing windows controls (i.e. MFC's CEdit) to override or add your own functionality. However, I have found virtually no information on how Window's native controls are created in the first place. WinCtrl fairy maybe? I realize that they are part of the OS and possibly beyond mere mortals.
We have combo boxes, tree contols, list controls, and so on and I have examined creating windows at the API level, that is CreateWindow(...). Is it possible to create an entirely new type of window/control from scratch? Some insight into the "black-box" of windows and controls would be interesting.
Ross White
|
|
|
|
|
Yes. It all starts with a call to RegisterClassEx . Then you define the icons, menus, window message handler, etc. for your totally new 'custom' window type. Typically all this code and the resources required for the menus, icons, brushes, etc. is put into a DLL and then you export a function that registers these custom windows.
For example, you get a many of the 'normal' classes registered when your MFC application calls InitCommonControlsEx .
|
|
|
|
|
|
Yes. Look at the RegisterClassEx function and the WNDCLASSEX structure. This will define the parameters of your new control such as icons, menues, and window procedure. You will have to write your own WndProc and handle any messages you need to draw the control, handle mouse clicks, etc. You most likely would write this code in a dll and export a function to call RegisterClassEx to register your control class before calling CreateWindowEx to create your control.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Thank all for the input. I will have to go back and do some more home work!!
Ross White
|
|
|
|
|
hello!
can anybody tell me how can i create check box in the group box dynamically.
|
|
|
|
|
Find the window handle of your group box.
Do a Create on the checkbox control window and make sure it is inserted in Z-Order AFTER the group box window. That will effectively place the checkbox 'in' the group box. The Z_Order will affect the tab order, which is one of the criteria the group box uses to determine which controls are part of the 'group'. Also, certain controls must have the WS_GROUP style set, all child controls from one with WS_GROUP set untilt the next one with WS_GROUP set are considered a single group.
For example:
Group Box - WS_GROUP
CheckBox - WS_GROUP
CheckBox - NO WS_GROUP
CheckBox - NO WS_GROUP
CheckBox - NO WS_GROUP
Push Button - WS_GROUP
This makes for four checkboxes all part of same group.
|
|
|
|
|
I am trying to set a different font inside a grid tab. The following code is a snippet of what I’m doing. When I run the application it crashes! Has anyone used the function call SetTabFont? And if so can you share some insight on how to properly use this thing. The commented code is what I’m inputting to try and get my desired response.
Thanks for any help, Steve…
void CProcessGrid::OnSetup()
{
CUGCell cell;
CUGTab mTab;
SetNumberSheets(3);
AddTab("Procedure", 0);
AddTab("Parts", 1);
AddTab("Tools", 2);
SetTabWidth(500);
SetCurrentTab (0);
//************ Change Font Size **********[SMB 06/20/05]
//
//CFont *mFont;
//int fontIndex;
//fontIndex = AddFont("Arial", 8, 2);
//mFont = GetFont(fontIndex);
//mTab.SetTabFont(mFont);
//
//*****************************************************
|
|
|
|
|
Is it possible that the mTab object hasn't been created yet (not a window yet)?
|
|
|
|
|
( in VC6 )
I have a DLL from a 3rd party.
there is only one function in the DLL which is declared like this in the simplist documentation :
int __stdcall Function( long,double*, long , long );<code><br />
<br />
in my code I do this : <br />
<br />
<pre>
typedef int (*FunctionProc)(long , double*, long, long );
double* p;
int iRes = FunctionProc( 1, p, 2, 3 );
}</pre><br />
<br />
When I run this, I get a ESP error telling me the calling convention is not good between the DLL function and the function prototype I use.<br />
<br />
I changed the calling conventions of my sample project from __cdecl to __stdcall ( in the project settings ) and it looks like it works, the Function gets called without crashing.<br />
<br />
Is there a way to "transform" the function calling convention ? <br />
<br />
in my real application, I would like not to change the calling convention if possible, I don't really know the implications.<br />
<br />
Thanks.<br />
<br />
Max.<br />
<br />
<br />
<hr><a href="http://www.thesorus.qc.ca">Maximilien Lincourt</a><br />
Your Head A Splode - Strong Bad
|
|
|
|
|
I'd use __cdecl . It has always worked well for me in the past
|
|
|
|
|
No because the caller has been built with a specified calling convention and the stack must be set up accordingly.
|
|
|
|
|
Why not change the typedef
typedef int (__stdcall *FunctionProc)(long, double*, long, long);
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
ok, I think I typo-ed somewhere ...
I do this :
typedef int ( __stdcall * FunctionProc)(long , double*, long, long );
and it seems to "work"...
Thank.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
That is perfectly acceptable
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
I have an SDI app with a splitter and two views. The left view is a tree view and I'm trying to make the app come up with the last selection visible/active.
The menus/toolbars are indicating that the view is active but the focus/selection mark in the tree control acts as if it is not the active view. Part of the problem may be that the EnsureVisbile() call doesn't actually make it visible (the selection is hidden under a scroll bar). I don't know if that is what is causing the trouble or if the fact that the view really isn't the active view (in terms of mouse, keyboard) is why they EnsureVisible() isn't working (the chicken/egg thing).
I'm using a timer in the MainFrame and forcing the active view after 300ms using SetActiveView(). Is there something else I should be doing to make the view act as if I just clicked on the item? Any idea why the EnsureVisible() isn't placing the selected item within sight?
Thanks.
|
|
|
|
|
Can someone please tell me what i am doing wrong here. I can load the XML file fine but when i select the node that i want and try to retrieve the text, i get nothing back.
std::string value;
HRESULT hr;
MSXML2::IXMLDOMDocumentPtr pDocument;
MSXML2::IXMLDOMNodePtr ptagNode;
_bstr_t mybstrtagResponseKey = "//Response//ResponseKey";
_bstr_t mybstrtagResponseText = "//Response//ResponseText";
_bstr_t myxmlfile = "C:\\sample.xml";
// Create XMLDOMDocument
hr = CoInitialize(NULL);
hr = pDocument.CreateInstance("Msxml2.DOMDocument.4.0");
if (FAILED(hr))
{
}
try
{
// Load xml file.
if (pDocument->load(myxmlfile)!= VARIANT_TRUE)
{
}
else
{
ptagNode = pDocument->selectSingleNode(mybstrtagResponseKey);
//if text exists, get it...
while (ptagNode)
{
value = ptagNode->text;
}
}
}
|
|
|
|
|
It doesn't appear that you're setting the root:
You're not setting the root:
MSXML2::IXMLDOMDocumentPtr plDomDocument = NULL;
MSXML2::IXMLDOMElementPtr pDocRoot;
HRESULT hr = plDomDocument.CreateInstance(MSXML2::CLSID_DOMDocument);
if (SUCCEEDED(hr))
{
BSTR xml = _com_util::ConvertStringToBSTR(response);
variant_t vResult = plDomDocument->loadXML(xml);
if (((bool)vResult) == TRUE)
{
MSXML2::IXMLDOMElementPtr pDocRoot = plDomDocument->documentElement;
CComPtr<MSXML2::IXMLDOMNode> pDisp = pDocRoot->selectSingleNode(_T("Disposition"));
if (pDisp)
...
|
|
|
|