|
Hi Alton
Sounds like you've forgotten to add the following to the beginning of your control:
void AfxEnableControlContainer( );
You can't contain a control without it
Tom
|
|
|
|
|
|
Hi Alton
Glad I could help
Personally, I put it into my InitInstance method or as near to the POE as possible. Doesn't really matter though, as long as it's called before you attempt to embed your object.
Tom
PS, thanks for the feedback
|
|
|
|
|
Im new to C++ and so im not to sure how comboboxes work and how to populate tham, but this was my best guess:
LPCTSTR intList[] = {"one","two","three",}; <br />
HWND hList;<br />
hList = GetDlgItem(IDC_COMBO1);<br />
for (int i = 0; i < 3; i++) <br />
{ <br />
SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)"hello"); <br />
}
but doesnt seem to be correct.
What am i doing wrong?
|
|
|
|
|
ceejeeb wrote: but doesnt seem to be correct.
Why?
If you are working with a combobox, you need to send a CB_ADDSTRING message instead.
Have you tried:
SendMessage(hList, CB_ADDSTRING, 0, (LPARAM) intList[i]);
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
you should have added a member variable for you combobox and then you can simply used
<br />
m_VariableOfYourComboBox.AddString( "hello" );
|
|
|
|
|
You are assuming MFC. The OP provided nothing which indicated that was being used.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I agree with Maximilien its easy declare a variable for combobox and use of m_Combo.InsertString or m_Combo.AddString
|
|
|
|
|
Hi to you all,
In a Dialog, I use an Edit element to enter a key value for new objects. I use the same dialog somewhere else to select one of the objects and I then replace this CEdit element with a CComboBox from which the value can be selected. I would likt to use the same CString variable. In the current version, this CString is connected to the CEdit object in the DoDataExchange by a DDX_Text(pDX,.....). I would likt (in the OnInitDialog routine) to disconnect this CString from the CEdit element, and reconnect it (with a new DDX_Text probably) to the CComboBox element. Is there a way in which one can disconnect the data exchange? Or should I take the DDX_Text for this element out of DoDataExchange and put it in OnInitDialog altogether?
Anyone have any suggestions?
Thanks in advance
William
|
|
|
|
|
Wim Engberts wrote: ...this CString is connected to the CEdit object...
Use a CEdit member variable instead. For the combobox control, use a CComboBox member variable.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
David,
This is indeed what I do, however, I would like both controls to do their data exchange with the same CString variable, since I always show only one of the two (either the CEdit or the CComboBox), depending on the mode that I have selected for the dialog.
I am now experimenting with a double DDX_Text in the DoDataExchange routine (referring both controls to the same CString). This compiles fine and it also seems to work properly. However, when starting the classwizard, I get an error. So far I have been able to go around this by putting the second DDX_Text outside of Microsoft's automatic data map (so putting it behind the "//}}AFX_DATA_MAP" line). So far, this seems to work properly.
Regards,
William
|
|
|
|
|
While ClassWizard is nice, do not let it ultimately govern how you lay out your code. It's meant to solve a problem a particular way, but that does not mean that other ways can't also be employed.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hello,
what is wrong with my application? i got an error message when i try to execute it.
The procedure entry point GetThreadId could not be located in the dynamic link library KERNEL32.dll
#include "stdafx.h"
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
GetThreadId((HWND)111);
return 0;
}
thank you
|
|
|
|
|
What version of Windows are you running it on? According to this[^], it's not available on all versions.
Chris Meech
I am Canadian. [heard in a local bar]
Nobody likes jerks. [espeir]
The zen of the soapbox is hard to attain...[Jörgen Sigvardsson]
I wish I could remember what it was like to only have a short term memory.[David Kentley]
|
|
|
|
|
hmm.. i am using windows xp
but how then i can send message to the thread process...?
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
HANDLE pKhwnd;
pKhwnd = CreateThread(0, 0, pKhookThread, &hInstance, 0, 0);
WaitForSingleObject(pKhwnd, 10000);
PostThreadMessage(GetThreadId(pKhwnd), WM_DESTROY, 0, 0);
FileWrite("Application Terminated");
return 0;
}
what function i have to use to get thread id?
|
|
|
|
|
Not knowing what your thread function does, just because you create a thread, what makes you think it will accept or handle your message? Possibly some of the articles here[^] might help you out.
Chris Meech
I am Canadian. [heard in a local bar]
Nobody likes jerks. [espeir]
The zen of the soapbox is hard to attain...[Jörgen Sigvardsson]
I wish I could remember what it was like to only have a short term memory.[David Kentley]
|
|
|
|
|
that thread listens for messages so WM_DESTROY should terminate thread process...
|
|
|
|
|
|
Please don't spam the forum with posts like this. If you don't have a clue, you should just for once try to _not_ post a reply to a question. In this case, the parameters are perfectly legal, and has absolutly nothing to do with his problem. The only thing this kind of reply is doing is to make the question look answered, and it will not show up when clicking the 'unanswered questions' link above. Thus, instead of helping, these kind of posts actually reduces the chance of getting an answere to a question. If this was just a one-timer, I wouldn't be bothered, but you do this over and over again.
|
|
|
|
|
How would one declare a function pointer and initialize an array of those pointers to different constructors. I'm declaring an array of structures like the following
typedef struct tagExtractOps
{
CString strExtractName;
int nCtorCount;
CTOR* pConstructors[];
} ExtractOps;
const int NUMBER_OF_OPS = 3;
ExtractOps[NUMBER_OF_OPS] = {"OP_1",2,{ctorA,ctorB},"OP_2",3,{ctorA,ctorC,ctorD},"OP_3",1,{ctorE}};
for ( int i = 0; i < NUMBER_OF_OPS; i++ )
{
for ( int j = 0; j < ExtractOps[i].nCtorCount; j++ )
{
Parent* pExtract = (Parent*) new Extractops[i].pConstructors[j];
if ( pExtract )
{
.... do a bunch of operations on pExtract
delete pExtract;
}
}
} In this example, all of the classes inherit from class Parent and all the operation I call are either defined in the parent or are virtual functions.
Chris Meech
I am Canadian. [heard in a local bar]
Nobody likes jerks. [espeir]
The zen of the soapbox is hard to attain...[Jörgen Sigvardsson]
I wish I could remember what it was like to only have a short term memory.[David Kentley]
|
|
|
|
|
The only way I can think of doing it, is using an factory of some sort
[edit] Re-written into something that actually compiles! [/edit]
enum EClasses
{
EClassA=0,
EClassB,
EClassC,
EClassD,
EClassE,
};
Parent* CreateObject( EClasses type )
{
Parent* pObj = NULL;
switch( type )
{
case EClassA:
pObj= new CClassA();
break;
case EClassB:
pObj= new CClassB();
break;
..etc..
}
return pObj;
}
const int MAX_CLASSES = 10;
typedef struct tagExtractOps
{
std::string strExtractName;
int nCtorCount;
EClasses pClasses[MAX_CLASSES];
} TExtractOps;
const int NUMBER_OF_OPS = 3;
TExtractOps ExtractOps[NUMBER_OF_OPS] = {"OP_1",2,{EClassA,EClassB},"OP_2",3,{EClassA,EClassC,EClassD},"OP_3",1,{EClassE}};
for ( int i = 0; i < NUMBER_OF_OPS; i++ )
{
for ( int j = 0; j < ExtractOps[i].nCtorCount; j++ )
{
Parent* pExtract = CreateObject( ExtractOps[i].pClasses[j] );
if ( pExtract )
{
delete pExtract;
}
}
}
-- modified at 9:58 Wednesday 1st November, 2006
|
|
|
|
|
Thanks. I'll give some thought to a class factory. Ultimately I'm trying to avoid coding some gigantic switch statment that just implements the assignment and 'new' operations. I trying to figure out a way to just code that line once.
Chris Meech
I am Canadian. [heard in a local bar]
Nobody likes jerks. [espeir]
The zen of the soapbox is hard to attain...[Jörgen Sigvardsson]
I wish I could remember what it was like to only have a short term memory.[David Kentley]
|
|
|
|
|
A colleague of mine is a big fan of using complex define systems
something like:
ClassDefinitions.h
DECLARE_CLASS( ClassA )
DECLARE_CLASS( ClassB )
DECLARE_CLASS( ClassC )
enum EClasses
{
#define DECLARE_CLASS( unique_class_name ) E##unique_class_name,
#include "ClassDefinitions.h"
#undef DECLARE_CLASS
}
Parent* CreateObject( EClasses type )
{
Parent* pObj = NULL;
switch( type )
{
#define DECLARE_CLASS( unique_class_name ) \
case E##unique_class_name: \
pObj= new C##unique_class_name(); \
break;
#include "ClassDefinitions.h"
#undef DECLARE_CLASS
}
return pObj;
}
This means you don't need to manually update the enum and factory, you just have to update the single header file. However, it makes code that is much harder to read and understand, so there's a tradeoff there
|
|
|
|
|
Hi, I stuck with gethostbyaddr() function. When I try this function with IP add = 127.0.0.1 it gives me “WSANO_DATA (11004)” error. Now when I am using gethostbyname() function with name = localhost. It is working perfectly can I know what is the problem with this. Thanks in advance.
Priaynk
This is working
LPHOSTENT hostEntry;
hostEntry = gethostbyname("localhost");
This is not working
char* ipadd = "127.0.0.1";
LPHOSTENT hostEntry1;
hostEntry1 = gethostbyaddr(ipadd,4,AF_INET);
|
|
|
|
|
priyank_ldce wrote: hostEntry1 = gethostbyaddr(ipadd,4,AF_INET);
The first argument to gethostbyaddr() must be in network byte order (instead of host byte order). Use inet_addr() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|