|
in MSDN there is one example given
Example
The following example demonstrates the use of CString::operator LPCSTR.
// If the prototype of a function is known to the compiler,
// the LPCTSTR cast operator may be invoked implicitly
CString strSports(_T("Hockey is Best!"));
TCHAR sz[1024];
lstrcpy(sz, strSports);
// If the prototype isn't known, or is a va_arg prototype,
// you must invoke the cast operator explicitly. For example,
// the va_arg part of a call to sprintf() needs the cast:
sprintf(sz, "I think that %s!\n", (LPCTSTR) strSports);
// while the format parameter is known to be an LPCTSTR and
// therefore doesn't need the cast:
sprintf(sz, strSports);
// Note that some situations are ambiguous. This line will
// put the address of the strSports object to stdout:
cout << strSports;
// while this line will put the content of the string out:
cout << (LPCTSTR) strSports;
|
|
|
|
|
Hi,
Try GetBuffer methode of CString.
e.g
char *t;
CString str = "teste";
t = str.GetBuffer(10);
|
|
|
|
|
Hello all,
I had a few questions in regards to Dialog windows, and wonder if anybody otu ther knew any of this stuff.
1) I open a dialog window in an MDI, and it ALWAYS is on top of a the MDI Window. I want it to be underneath the MDI window if I click on it.
2) The Dialog windows can be moved outside of the area of the MDI mainframe. I don't want this either. Anybody know how to do that?
Thanks a whole bunch,
NickOne
|
|
|
|
|
NickOne wrote:
I open a dialog window in an MDI, and it ALWAYS is on top of a the MDI Window. I want it to be underneath the MDI window if I click on it.
It cannot be a child of the MDI window then, it will need to be a child of the desktop, or NULL.
NickOne wrote:
The Dialog windows can be moved outside of the area of the MDI mainframe. I don't want this either. Anybody know how to do that?
That's a bit harder - you'll need to handle WM_MOVE ( from memory ) and when it goes outside the MDI area, move it back yourself. It will be a bit ugly ( it will jitter ).
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Put your dialog inside an MDI child.
I don't knows how easy or how hard it is to make it works. You will have to resize the MDI child to fit around the dialog (unless the dialog can itself be resized).
However, I generally do not recommand it since you will have a side effect on command like tile if the dialog is constrained or it can look bad if controls on the dialog are not move appropriatly.
Also, if the MDI client is small (the user can resize it) and the dialog is big, it will be harder to see it...
If neither of these potential problems affect you, then go ahead and try it... I know it was possible with Borland and OWL but I don't knows with MFC since we now avoid MDI child dialogs and I do less UI since I uses VC...
Philippe Mori
|
|
|
|
|
NickOne wrote:
1)
NickOne wrote:
2)
You should be able to accomplish both of these, at least in part, by creating your dialog as a child of the MDI client window. You will, however, have to add code if you wish to make it act like a normal MDI child (bring to front on mouse click, get cycled through by CTRL+TAB, highlight the title bar when active). You could get around this if you're using MFC by using a CFormView instead of a CDialog, and just modify the window style to give it a dialog border.
Shog9
--
Maybe Java is kind of like God, it "works in mysterious ways". It seems like your apps are running slowly, because in the backgroud Java is solving world hunger, or finding the cure to cancer.
- Ryan Johnston, Don't die java!
|
|
|
|
|
I am not able to get a string value from the registry. I have looked over all the posts regarding this and have not found a solution. Here is my code:
HKEY hKey = NULL;
CHAR szBuf[100];
LPDWORD lpdwLength;
CString strReturn;
::RegCreateKeyEx(HKEY_CLASSES_ROOT, "CLSID", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hKey, NULL);
::RegQueryValueEx(hKey, "E1", 0, 0, (LPBYTE)szBuf, lpdwLength);
::RegCloseKey(hKey);
The value of szBuf after this runs is garbage, but the value is definately in the registry.
Does anyone have a code example?? MSDNs code example link for RegQueryValueEx() doesnt
link to code (go figure...) but rather to an explanation that is of no help.
Nish?? You out there??? HELP!!!
Thanks guys and gals.
Is it football season yet?!?!?!?
|
|
|
|
|
A comment: ALWAYS check the return value from a function that returns one.
Ex:
HKEY hKey = NULL;
CHAR szBuf[100];
LPDWORD lpdwLength;
CString strReturn;
LONG lResult = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, "CLSID", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hKey, NULL);
lResult = ::RegQueryValueEx(hKey, "E1", 0, 0, (LPBYTE)szBuf, lpdwLength);
::RegCloseKey(hKey);
by knowing the return value, you will know what is going wrong.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
lpdwLength should be the address of a dword, not an uninitialised pointer pointing into randomness.
The value in that dword is size of the buffer you're passing in, or 0 if you're not passing a buffer. After the call it's the size of the buffer required (or the size of the buffer that was used (same thing)). It kinda says all that in the MSDN docs.
So, something like this might work (beware, it hasn't seen a compiler). Or you can try a wrapper class, like the one I wrote about here.
HKEY hKey = NULL
long ret = ::RegCreateKeyEx(
HKEY_CLASSES_ROOT,
"CLSID",
0,
NULL,
REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
NULL,
&hKey,
NULL);
if (ret == ERROR_SUCCESS)
{
CHAR szBuf[100];
DWORD dwLength = sizeof(szBuf);
ret = ::RegQueryValueEx(hKey, "E1", 0, 0, (LPBYTE)szBuf, &dwLength);
if (ret == ERROR_SUCCESS)
{
}
::RegCloseKey(hKey);
}
else
{
}
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Len,
Thanks for the advice. I am still learning how to decipher the cryptic documentation that is MSDN...
Anyways, I tried this and now get "access violation reading location ..." during the query. The access specifier is set to
KEY_READ | KEY_WRITE | KEY_QUERY_VALUE
Any suggestions???
|
|
|
|
|
Try using KEY_ALL_ACCESS?
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
I have two dialog based programs. one is Microsoft Automation. and the other one calls first dialog-based app.
To call first dialog-based app ( let me just say it app2) from first dialog-based app ( app1), I used ShellExecute();
anyway, It is working fine if you compile and execute app1.exe within VC++ 6.0.
if you go to mycomputer-> right click-> window explore->go to app1 folder->debug-> app1.exe, and it is not working anymore.
the error at, which is in app2
<br />
_Application application;<br />
if(!application.CreateDispatch("Word.Application)<br />
{<br />
AfxMessageBox("Couldn't create Word.Applicaiton");<br />
<br />
}<br />
if I go back to run and execute app1.exe it works again. but not from double clicking on app1.exe in window explore.
I know that's OLE initialization problem where i declare
<br />
if(!AfxOleInit())<br />
{<br />
AfxMessageBox("Couldn't create OLE COM");<br />
}<br />
<br /> it is in BOOL Capp2App::InitInstance(). From my knownladge, if OLE libs didn't get initialized, I couldn't createDispagech("Word.Application");
How can I initialize OLE Lib evertime i use so i don't have to execute app1.exe inorder to get Word.Application?
|
|
|
|
|
Hi!
How can I put an clickable email and weblink on a dialog (like the about dialog)?
The email-link should open the standard email program on the system and the weblink should open the standard browser.
Thanks for any help!
Dirk
|
|
|
|
|
|
Thank you!
|
|
|
|
|
I have head file and cpp file are written in C++. There is a GetItem() in it. I used it in a C file to create a lib file. The compile is fine. Then I use this lib file in a C++ application and got a Link2001 link error which says "unresolved external symbol _GetItem".
Anyone knows how to fix this problem? Thanks.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
You need to reference the library where the _GetItem function is implemented.
|
|
|
|
|
you should link the .lib
if in vc, should be at "project setting"->link->object/library type in the libary name will be ok
i am realfly8)
|
|
|
|
|
Also, if the GetItem implementation is in a C file do not forget the extern "C" stuff:
extern "C"
{
#include "Header_in_C_That_Contains_GetItem.h"
}
Best regards,
Alexandru Savescu
|
|
|
|
|
Hello,
I've searched the MSDN to no avail...
I've created a CSlider control on a DialogBar and am constantly getting an assertion error (hWnd is not valid) when I try to set the range (CSliderCtrl::SetRange(0, 50, FALSE)). It's as though I'm trying to set it before the slider control window is 'valid' (or created?), however, the error occurs after I see the slider physically on my DialogBar, so I know it exists at the time I try to SetRange().
If I 'ignore' the first assertion error, all subsequent executions work fine.
At what time in the code execution (standard wizard or MFC methods) may I set the slider control's parameters without error? Or does anyone know what is going wrong with this scenario? I really want to learn. Thanks!
JennyP
|
|
|
|
|
The easiest thing to do would be to put a check on the slider's hWnd member:
if( m_SliderCtrl.m_hWnd == NULL )
{
m_SliderCtrl.SetRange(...);
}
That'll stop it asserting.
You need to make sure that the OnInitDialog member has been called first (by the framework, that is, don't call it yourself.)
I've also found that doing an UpdateData( FALSE ); call before you first access the control makes sure that the control variable is actually initialised properly
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Thanks for the reply. I ended up calling UpdateData(FALSE) in the CMainFrame just after this dialog bar is created (and initializing other aspects such as ticks, range, etc.). It doesn't feel very like good OOD, but it's the one sure place that I can consistently initialize my DialogBar controls.
Also, I assume in the code fragment you wrote, you meant to write a != NULL instead of a == NULL?
Thanks!
JennyP
|
|
|
|
|
JennyP wrote:
Also, I assume in the code fragment you wrote, you meant to write a != NULL instead of a == NULL?
Yeah, sorry
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I would like to see all the ICMP messages coming to my machine. I wrote the following code but I can not read anything from the socket. Where is my mistake ?
SOCKET hSocket = ::socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
while (true)
{
sockaddr_in from;
int nFromlen = sizeof(from);
int nRead = recvfrom(hSocket,pRecvBuf,1024,0,(sockaddr*)&from,&nFromlen);
}
When I ping another machine from dos prompt I expect to catch something but nothing happens and recvfrom blocks. I have admin privileges. Can someone help me on this subject please. I could not solve it.
Thank you
Orcun Colak
|
|
|
|
|
Dear All,
is there any way to develop plugin for IExplorer. if yes then plz
if some one of you can reffer me to the materail for this help.
any code examples or any tutorial on the net.
waiting for reply.
omar lodhi
|
|
|
|
|