|
When I use MFC New Feature pack (VC++ 2010) e.g. MFC Property Grid control in my application by adding them directly to resource designer while running the application, MFC new controls appear with no style but the controls Like CButton appear correctly?
What's the problem , please Help
|
|
|
|
|
Hi
I want to change the image of button on mouse over. When the mouse pinter will be on button it should change the image of the button and once pointer come out from button it should come to its original state. My button havinf owner draw properties and I want to create the button at runtime.
Please provide me some same code
Thanks
|
|
|
|
|
|
I Have a CString which contains port names.
CString cs = "COM1";
char portname[5];
1. What is the memory representation of cs above (I have this question since I think it is multibyte/wide char)?
2. How to copy above cs into portname ? I need portname to contain
{'C','O','M','1','\0'}
Thanks
JC
|
|
|
|
|
|
TCHAR path[ MAX_PATH ];
Cstring str;
_tcscpy(path, str);
|
|
|
|
|
1/
The memory representation will change depending on whether the UNICODE define is there or not. The default changes depending on which version of Visual studio you have. VS6, it's char. I think all later ones, it's w_char, or 16bits.
2/ There's a conversion to LPCTSTR operator in the CString class, so you can pass it to const TCHAR * parameters of other functions. So, your question is trivial:
lstrcpy (szBufferOut, sMyString);
Have a look at the following article for more help:
The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^]
Good luck,
Iain.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
Hi,
You've got two problems here:
- Converting from potentially wide to narrow charcaters
- Getting rid of any const
The first means that you can't use something like _tcscpy and TCHARs as you want real, honest, chars, not chars or wchar_ts depending on some preprocessor macro. The second means you've got to do a real copy and you can't just use an implicit conversion.
To solve the second problem you've got to do a copy. To solve the first you either copy the string using wcstombs or strcpy depending on whether the CString is encoded as unicode as not. You can either use the preprocessor to select which function you use, but that's really sucky like most uses of the preprocessor in C++ (avoid it like the plague) or you can use function overloading:
void to_narrow( const CStringA &to_convert, char *out )
{
...
}
void to_narrow( const CStringW &to_convert, char *out )
{
...
}
I haven't bothered including the code as there's another way you can do the conversion which relies more on the C++ standard library and has less pointers flopping about and confusing the issue. In this version I'm returning a std::vector<char> as it sorts out any memory management for the caller:
std::vector<char> to_narrow( const CStringA &to_convert )
{
const char *convert_start = to_convert;
const char *convert_end = convert_start + to_convert.GetLength() + 1;
return std::vector<char>( convert_start, convert_end );
}
std::vector<char> to_narrow( const CStringW &to_convert )
{
const wchar_t *convert_start = to_convert;
std::vector<char> output( to_convert.GetLength() * 4 + 1 );
output.resize( wcstombs( &output[ 0 ], to_convert, output.size() ) );
return output;
}
The supperfluous +1s everywhere are due to CString::GetLength not including the terminating '\0' character in the length. The *4 is just in case Microsoft ever support utf-8 as a character set - it gives the oodles of space for really weird characters
Any questions just shout.
Cheers,
Ash
PS: This code was written from memory and isn't tested, there might be some problems but the idea's sound and in use all over the place.
|
|
|
|
|
Hi All,
I am trying to get a splitter window for MDI when a Menu Item in Menu is clicked. The splitter window is been created but when i am trying to drag that Splitter it is not able to split also it is not performing the events of the pane. (i.e) if in Pane2 of the splitter i am having a Button Control it is not been handled.
Help me out!
Thanks,
Uday.
Here is the Code.
-----------------
void CMainFrame::OnMytreeTree()
{
CCreateContext ctx;
ctx.m_pNewViewClass = RUNTIME_CLASS(CudayView);
// GetActiveDocument() call before you destroy m_splitter.
ctx.m_pCurrentDoc = GetActiveDocument();
//ASSERT(ctx.m_pCurrentDoc!=NULL);
// m_pSplitter !=NULL when there is a visible splitter.
if (m_pSplitter)
{
// Destroy splitter window.
delete m_pSplitter;
m_pSplitter = NULL;
// Create and initialize CMyView.
SetActiveView((CView*)CreateView(&ctx));
GetActiveView()->OnInitialUpdate();
}
else
{
if(m_pSplitter == NULL)
{
//MDIGetActive()->DestroyWindow();
// Create new splitter window.
m_pSplitter = new CSplitterWnd;
if (!m_pSplitter->CreateStatic(this, 1, 2))
{
TRACE0("Can't create splitter window.\n");
return;
}
else
{
if ((!m_pSplitter->CreateView(0, 0,
RUNTIME_CLASS(CMyTreeView),
CSize(200, 0), &ctx))
||(!m_pSplitter->CreateView(0, 1,
RUNTIME_CLASS(CFirstView),
CSize(500, 0), &ctx)))
{
TRACE0("Can't create one of the splitter panes.\n");
return;
}
// Initialize the two panes (each containing a view
// associated with the current document).
((CView*)m_pSplitter->GetPane(0, 0))->OnInitialUpdate();
((CView*)m_pSplitter->GetPane(0, 1))->OnInitialUpdate();
SetActiveView((CView*)m_pSplitter->GetPane(0, 0));
}
}
}
// Redisplay frame.
RecalcLayout();
}
|
|
|
|
|
Hello everybody.
I'm trying to use OCILIB driver for oracle under Mvisual studio 6 and i need some help to accomplish some duties.
in my work i need to include a lib file a dll file and a header file; like
. oclib.h
. ociliba.dll
. ociliba.lib
to include the header file, i put the file under "C:\Program Files\Microsoft Visual Studio\VC98\Include"
the question is: how could i use the dll and the lib files in my project (i'm using visual studio 6)
it's a kind of an easy task but i never tried to include dll or lib files into my projects.
Thank you very much
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
One way is like this - its suitable for small projects I guess :-
a) go to Project Settings (ALT F7)
b) Select The Link Tab
c) Set Category to Input
d) In the Object/library modules box, put oci.lib and a space after it - put it at the front for now unless there is a 'collision' in the build/link stage
e) In the Additional Library Path box, enter in the path to the .lib module
Obviously you include the ocilib.h file with a #include "ocilib.h" ... not sure If I agree with where you put it .. I usually put 3rd party modules in a '3rdParty' Folder
Projects
\3rdParty
\bin <- Libs, dlls
\inc <- Headers
In your case they are probably under the Ora92 (or whatever version) directory - they could be left there
To Pick up the headers from the structure above or where you have them, you could :-
a) go to (again,under project setting) C++ Tab,
b) Select Category 'Preprocessor'
c) Put the directory ie drive:\Projects\3rdParty\inc in the additional include directories
You can also change (independantly) the settings or ALL projects, by going Tools -> Options -> Directories, and using the 'Show Directories For' dropdown and adding the directories for include files, library files etc - some people prefer this approach.
For larger projects, I tend to use a modified version of the 1st approach, but I allow for different versions of components by using environment settings (that means I dont need to change the basic build within a project), but see if you can get going in 'simple mode' first
hope this helps
'g'
|
|
|
|
|
Thx for the answer.
it works now. thx you verry much for this help.
"The Ultimate Limit Is Only Your Imagination."
modified on Sunday, May 23, 2010 6:54 PM
|
|
|
|
|
not sure where thats coming from, and Im sure you'll appreciate, trying to debug something like this remotely is hard
- have you started a new project from scratch or are you extending something else you've found ?
- have you just installed MSVC and proved it can compile a simple 'hello world' ?
What kind of project are you attempting to create - console, gui/MFC, Dialog box - not that it should make too much of a difference
If you're a rank beginner, I do feel your pain, and yes, it is hard to find your way around .. I often find the safest way to start with a new API for example is to build myself a little console test harness - start with a console 'hello world' program, build that, then start adding eg the oci stuff to it it.. when thats done and working, then think about applying that knowledge to something bigger/the main project .. that way if something goes wrong, you always have your test harness to refer to - its not quite 'unit testing' but a good start
Its been a long time since Ive worked with oci (and never 'directly') - tell me about what you're trying to do and I might be able to suggest an approach
'g'
|
|
|
|
|
for that error it was the " that i added to the path when including the lib. now it's gone when i erase it
For the oci, i m trying to put on screen the data from an Oracle DB using C++ and this to integrate it into a larger team work. so my part is to begin with the ocilib driver.
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Hi, I am a C++ beginner. I have an NT Service I need to publish on the net for download but I don't want any one to be able to start except me or the one I authorize. When you download the service executable you could install the service but you should not be able to start it. One of the ideas is to protect the service executable with password, this way, in theory, only the one who has the password can start the service. Lots of EXE Password protectors on the net, but once I use one of them to protect the service executable the service doesn't start at all. The reason is obvious; NT services has no message pipe a user could use to enter the password. I even used Themida to protect the service as described on their KB (they say their software can protect NT Services) but looks like Themida actually corrupts the service executable too as it doesn't start anymore. I have the source code of the service and I use [service /i] and [service /u] to install/uninstall the service, but I don't know how to pass the password as a command line parameter to the service when I start it. the SCM attempt to start it.
If the password protecting is a bad idea, could some one guide me on how to reach my goal, my goal is: my service should not be started by anyone except me.
Thanks
modified on Sunday, May 23, 2010 3:52 PM
|
|
|
|
|
Hi,
Not sure if this helps as an idea, but if you decouple the concepts of "service start" and "service can do something useful" you might find another way into the problem.
So when the service first starts up it just sits there, doing nothing. It rejects all requests over it's external interface (over RPC, TCP, shared memory) until something comes along and tells it to activate. The thing that tells it to activate is another, fairly small, application that's password protected. Only the person that knows the magic mantra to get the activation process running (i.e. it's password) can switch the service from dormant to active.
There are some problems with this approach:
- Securing the link between the thing doing the activation and the service. Quite how you sort the trust out to stop some bad guy reverse engineering your protocol could be an interesting challenge.
- if the service has to do something before the first interactive user logs in then this won't work. Sorry, back to the drawing board!
Hope this provides some food for thought,
Cheers,
Ash
|
|
|
|
|
Delicious food Ash, thanks, but unfortunately, my service should do the hard job before user logon, which means it should rely on itself on the matter of being active/inactive.
from your post I understand that a service password protecting is not good, but I need to know; is it possible? The guys at Oreans say that it's possible and their product could do it without even having the source code of the service but it doesn't work! any ideas? thanks
|
|
|
|
|
Oh well, forget my post then
I have no idea why your third party product doesn't work. I'd wave the prospect of an order at them and see if that makes them sort out your problem, it often works for me!
Cheers,
Ash
|
|
|
|
|
I did, I contacted them and literally said: "This problem is the only reason why I will not order your product", I'm still waiting for their response!
Thanks
|
|
|
|
|
I have the following code:
....
private:
void __fastcall WMQueryEndSession(TWMQueryEndSession& Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_QUERYENDSESSION, TWMQueryEndSession, WMQueryEndSession)
END_MESSAGE_MAP(TForm)
.....
void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession & Message)
{
Message.Result=0;
}
Compiled by C++ Builder 2010, the code works improperly. Although it prevents the computer from shut down, but it also closes my application. The code below fixes the problem, but it is not stable (sometimes does not work) and the such long delay in 10 seconds is not acceptable in my case:
void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession& Message)
{
Sleep(10000);
Message.Result=0;
}
Does enybody know how to fix the problem? Thanks.
|
|
|
|
|
I had a simular problem and had to check for 2 messages WM_ENDSESSION or WM_QUERYENDSESSION. Then set a flag to indicate shutdown, this flag was then used in an OnClosing event that by default cancelled the close to minimize to the system tray
|
|
|
|
|
ARopo wrote: I had a simular problem and had to check for 2 messages WM_ENDSESSION or WM_QUERYENDSESSION. Then set a flag to indicate shutdown, this flag was then used in an OnClosing event that by default cancelled the close to minimize to the system tray
Thank you for your answer. Hovewer your suggestion will not work in my case as WM_ENDSESSION is calling Application->Termiante() which terminates program even if the flag in OnClose event is set to hide or none and the application is minimized to the systray. Calling Application->Termiante() by WM_ENDSESSION (even if application returns zero to WM_QUERYENDSESSION message) is recent bug of C++ Builder 2010. Previous versions of the compiler worked properly and did not call Application->Termiante() if application returned zero to WM_QUERYENDSESSION message. Does anybody know how to fix or bypass this bug of the C++ Builder 2010?
|
|
|
|
|
Hi,I would like to know how can I create various string from some given characters eg:
given characters: a, b
I would like to generate the following strings:
aa
ab
ba
bb
What I have thought of is having (for 2 inputs only) two for-loops one inside another, and then loop each to the number of inputs which in this case is 2 and the output strings will be 2*2 0 4 strings and as the number increases the number of output strings will increase by multiplying n*n (n-times)
|
|
|
|
|
|
Sounds like home work, but I'll explain it any way.
This is a simple binary example; where 'a' implies bit not set and 'b' implies bet set.
Possible solutions:
for( int i = 0; i < 4; ++i )
{
if( 2 & i )
std::cout << "b";
else
std::cout << "a";
if( 1 & i )
std::cout << "b";
else
std::cout << "a";
std::cout << std::endl;
}
OR
char c[2] = { 'a', 'b' };
for( int i = 0; i < 4; ++i )
{
std::cout << c[1 & (i>>1)];
std::cout << c[1 & i];
std::cout << std::endl;
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|