|
|
Hi, i am new to Visual C++ and facing problem with combo boxes.
Here is what i need:
Combobox1
Choice: Metal, Plastic
Combobox2
Choice: if Metal in Combobox1: 2,3,4,5,6
Choice: if Plastic in Combobox1: 8,10,15
I am unable to write code for the event, can any one help me out with the hints or links or code!...any help is highly appreciated...!
#pragma once
namespace PR {
using namespace System; using namespace System::ComponentModel; using namespace System::Collections;
using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{ InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ComboBox^ comboBox1;
protected:
private: System::Windows::Forms::ComboBox^ comboBox2;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
this->SuspendLayout();
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^ >(2) {L"METAL", L"PLASTIC"});
this->comboBox1->Location = System::Drawing::Point(81, 80);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(121, 21);
this->comboBox1->TabIndex = 0;
this->comboBox1->Text = L"METAL";
this->comboBox2->FormattingEnabled = true;
this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^ >(5) {L"2", L"3", L"4", L"5", L"6"});
this->comboBox2->Location = System::Drawing::Point(81, 126);
this->comboBox2->Name = L"comboBox2";
this->comboBox2->Size = System::Drawing::Size(121, 21);
this->comboBox2->TabIndex = 1;
this->comboBox2->Text = L"2";
this->comboBox2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox2_SelectedIndexChanged);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->comboBox2);
this->Controls->Add(this->comboBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void comboBox2_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}
modified on Monday, October 19, 2009 10:27 AM
|
|
|
|
|
you'd probably need to post this in the "Managed c++/cli" forum.
anyway, there's stuff missing from you post.
This signature was proudly tested on animals.
|
|
|
|
|
Hi Maximilien
Please find the complete code now, or should i post it on "Managed C++/CLI" forum?
Any help is appreciated. Thanks
|
|
|
|
|
Invinci wrote: should i post it on "Managed C++/CLI" forum?
yes.
This signature was proudly tested on animals.
|
|
|
|
|
My MFC applicatin crashes with this call stack info.
Can anyone please help me out in understanding this?
ntdll!KiUserExceptionDispatcher+e
<Unloaded_RapidEyeAPI.dll> +1e701
ntdll!ExecuteHandler2+26
ntdll!ExecuteHandler+24
ntdll!KiUserExceptionDispatcher+e
<Unloaded_RapidEyeAPI.dll> +1e701
ntdll!ExecuteHandler2+26
ntdll!ExecuteHandler+24
ntdll!KiUserExceptionDispatcher+e
<Unloaded_RapidEyeAPI.dll> +1e701
ntdll!ExecuteHandler2+26
ntdll!ExecuteHandler+24
ntdll!KiUserExceptionDispatcher+e
<Unloaded_RapidEyeAPI.dll> +1e701
ntdll!ExecuteHandler2+26
ntdll!ExecuteHandler+24
ntdll!KiUserExceptionDispatcher+e
<Unloaded_RapidEyeAPI.dll>+271d
ntdll!RtlpAllocateFromHeapLookaside+42
<Unloaded_RapidEyeAPI.dll>+39f3
ntdll!RtlpAllocateFromHeapLookaside+42
<Unloaded_RapidEyeAPI.dll>+1c999
ntdll!RtlpAllocateFromHeapLookaside+42
kernel32!BaseThreadStart+37
modified on Monday, October 19, 2009 9:13 AM
|
|
|
|
|
Could you solve your problem?
BaseThreadStart is indicating that you are creating a new thread?
|
|
|
|
|
Hi all,
I have written a program which can monitor a specific program when it was closed.I used hook to do it and everything seem be ok but the problem is that I cannot hook WM_CLOSE message.
I have tried to use WH_GETMESSAGE, WH_CBT, WH_CALLWNDPROC. But all of them seem not work properly!
here is my code:
hHook = SetWindowsHookEx(WH_CALLWNDPROC,fnHookProc,hInstDLL,tid);
DLLEXPORT LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam, LPARAM lParam)
{
LPMSG msg = (LPMSG)lParam;
if(msg->message == WM_CLOSE )
{
}
return CallNextHookEx(_hHook,nCode,wParam, lParam);
}
anybody help me.
thanks
[N][Q][H]
|
|
|
|
|
There must be something special about the WM_CLOSE message. Are you using a DLL? Are you calling SetWindowLong() in that DLL? Are you injecting the DLL into the process of the "specific window?"
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Because this is a global hook which will monitor all message before they really reach to target window. So I think It doesn't need inject the dll to the target window. But I will try.
I took a round from google and know that many people have the same problem with me when they try to catch the WM_CLOSE. But I still cannot find the solution.
[N][Q][H]
|
|
|
|
|
[N][Q][H] wrote: DLLEXPORT LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam, LPARAM lParam)
You hook handler seems to be incorrect. For instance if you are using the WH_CALLWNDPROC, the handler should be like
LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam, LPARAM lParam)
{
PCWPSTRUCT msg = (PCWPSTRUCT)lParam;
if(msg->message == WM_CLOSE )
{
}
return CallNextHookEx(_hHook,nCode,wParam, lParam);
}
|
|
|
|
|
ok, KeyboardProc must be renamed to fnHookProc. But this is not the cause. This just a mistake when I copy from my code.
LRESULT CALLBACK LRESULT CALLBACK fnHookProc(int nCode,WPARAM wParam, LPARAM lParam)
{
PCWPSTRUCT msg = (PCWPSTRUCT)lParam;
if(msg->message == WM_CLOSE )
{
}
return CallNextHookEx(_hHook,nCode,wParam, lParam);
}
[N][Q][H]
|
|
|
|
|
It's an old Win32 FAQ (see onWin32 grp[^]) (same method than on Win 9x)
|
|
|
|
|
Dear all,
I am using MFC dialog application to get an text input from the user and make processing on it and then reply with response but I need to declare some variables to be working throughout the whole system cycle(I think its called global variables) to be accessible whereever from my system coding files. Because I need to deal with the variable changes during the system cycle.
I tired many things Like: static ,extern. But till now I'm beginner in this language so I didn't know how to deal with them in .cpp files.
Please any help will be appreciated.
Best regards.
|
|
|
|
|
If you need a global variable in your application, then you have an example at hand: the variable theApp (have look at it in your application). You may use the same route for your own global variable: declare it as extern in the main header of your application (the one included by all the - or the relevant - sources and define it in the main source. For instance, suppose your application name is test , then in test.h :
extern int g_iMainCounter;
and in test.cpp
int g_iMainCounter;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you for your reply and its work fine only when I want to use the variable in test.cpp. and in testDlg.cpp because you know I'm using dialog application.
But I tried to use the same variable in different files inside the same application for example in XX.cpp its already undeclared identifier there and I tried to include the header file #include "XX.h" and I can't access this variable.
Please help me.
And thanks alot again.
|
|
|
|
|
You need to include "test.h".
|
|
|
|
|
moh.hijjawi wrote: But I tried to use the same variable in different files inside the same application for example in XX.cpp
You have to options:
- include
test.h in XX.cpp . - declare the variable as
extern inside XX.h (or XX.cpp ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you for all of you.
I included test.h but it doesn't work as well But it works when I declare it as external inside XX.cpp so its now work fine.
Really you save my time with your experince and many thanks.
Regards.
|
|
|
|
|
You are welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi
I come back to make updating on this function to make the initialization for these variables through function and this function should bring the values from DB.
I am struggling with where I should declare the function and where I could call this function to be luncing once the MFC dialog interface launched. I tried many ways but always the compiler inform me that "unresolved external symbol" for the used external variables.
I tried to put the function declaration as a member function in the testApp class //but failed
I tried to put the function declaration as a member function in the ZZ.cpp and make the proper including //but failed and inform me that you can't initialize them into closed scope.
it seems to me that the initialization should be in the test.cpp and without function using. I don't believe that but how I can make it.
Any help will be appreciated
|
|
|
|
|
Hello,
I just played around with mutexes and wrote the following piece of code:
HANDLE hMutex = CreateMutex(NULL,
TRUE,
"test");
DWORD err = WaitForSingleObject(hMutex, INFINITE);
if( err == WAIT_FAILED )
printf( "This shouldn´t happen." );
else
{
err = WaitForSingleObject(hMutex, INFINITE);
if( err == WAIT_FAILED )
printf( "This shouldn´t happen." );
else
printf( "This shouldn´t happen either." );
}
No I don´t understand why the second WaitForSingleObject()-call doesn´t block. Since I said to wait indefinitely, shouldn´t it do so because the mutex object is already in use?
I guess, I have some general trouble understanding the mechanism here. How do I get the mutex to lock a code area up?
Souldrift
|
|
|
|
|
Whay don't you use GetLastError() when the return value is WAIT_FAILED as the documentation suggests?
|
|
|
|
|
There is no error. The return value both times is 0. Which is fine with the first call, and I thought was odd with the second.
But I just read somewhere else, that mutexes under windows don´t block inside the same thread. So that might be it.
Souldrift
|
|
|
|
|
Souldrift wrote: No I don´t understand why the second WaitForSingleObject()-call doesn´t block. Since I said to wait indefinitely, shouldn´t it do so because the mutex object is already in use?
Souldrift wrote: I guess, I have some general trouble understanding the mechanism here.
You're missing this ([^])
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the mutex satisfied a wait.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|