|
I have a button (owner drawn) which has a dynamic image on it. The image can be either a HBITMAP or HICON. It works great for normal styles, but I would like to grey the image when the button is disabled (same way it is done on a toolbar when a button is disabled). Does anyone know how to convert an HBITMAP and/or HICON image to disabled image.
Any help or pointers appreciated, thanks.
---
Better to be silent and thought the fool, than to open your mouth and prove it!
|
|
|
|
|
Try the DrawState() API. When rendering a HBITMAP with this method you should map the background color (probably COLOR_BTNFACE) to white. I do not know wether this applies to icons aswell.
Hope this helps.
-Jan
|
|
|
|
|
Hi,
First off I am new to VC++, so this is probably real basic stuff but I keep getting an error.
What I have so far :
// now all items are in list, so step through list to print them.
list<string>::iterator itr;
for (itr = parsed_items.begin(); itr != parsed_items.end(); ++itr ) {
int count = 0;
string dmp = *itr;
cstr = dmp.c_str(); // convert string to CString
plb->AddString( cstr ); // print to List Box
LPCTSTR word = cstr;
// How do I add the variable word into an array each time the loop goes round
// I want to end being able to access all the words in a sentence i.e.
// word[0]
// word[1]
// word[2]
// etc...
count++;
}
The comments in my code explain what I am trying to achieve.
Any help will be greatly appreciated, as I have been working on this and looking at various examples for two days now and am about to pull my hair out.
Thanks in advance
Tryhard
Tryhard
|
|
|
|
|
This compiles ? Surely you need List<string>::iterator ? Forget I said that, I'm sure you typed List<string>::iterator and lost the template argument as a bad tag as I did.....
Also, why convert string to CString ? Why not start with whichever string class you want and stay there ?
Either way, I don't know for sure if CString has an equivelant, or even if STL does ( shame on me ), but strtok will do what you want with a basic char*.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I m working in Win32 and creating a dialog with an edit box attached to it. The edit box always has input focus. The problem is I want to capture WM_KEYUP and WM_KEYDOWN for the edit control, but no matter what I try I cannot. I am capture EN_CHANGE, but then I cannot find out what key was pressed. I tried WM_KEYUP/KEYDOWN/CHAR for the dialog, but they never get called.
Argh !!!!!
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Not sure this helps but did you try replying DLGC_WANTALLKEYS uppon a WM_GETDLGCODE message in the edit control message handler code?
-Jan
|
|
|
|
|
I'm not sure what that means, but it sounds impressive
Seriously, I did not know about this and I think it will solve it - thank you.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Because edit boxes have their own "window class" (in the Win32 sense of the word), which means they also have their own callback function, the WM_KEYUP and WM_KEYDOWN messages are handled internally. What you want to do is handle them yourself, which will require a subclass (again, in the Win32 sense of the word) of the edit box.
No so long ago, I wrote an article that may be useful to you. Look at the subclass example, as it intercepts the WM_CHAR message and allows some keystrokes through, while denying others.
Feel free to drop me an e-mail if you have any questions about the article or the sample code.
--
Paul
"I drank... WHAT?"
|
|
|
|
|
|
I have 3 classes:
class A - dialog class
class B - thread class
class C - ActiveX class (included in dialog)
(the activeX component is a socket component and I create one variable for it in dialog class)
The scenario is like this:
The dialog will be initialized. The application will winsock other application. After it receive a data from socket component, it will initiate the thread. The thread then will call one method in dialog class which is using socket component. What the method (inside dialog class) should do here is, it will check the connection status. But it failed (it gives me runtime error - access violation error)
The question is:
1) How can I call method in class C(activeX component) straight from class B??
2) If cannot call directly from class B, where can I call the method? I try to call from class A but it failed. so can anybody help me to resolve on this.
I want to use the thread for checking the status connection.
Thanks in advance.
FM
|
|
|
|
|
Hello Farah,
Make sure you synchronizing the data access. what I think is happening is that have not locked the data befoe changing it, in the mean time another thread is using it or modifying it.
Imagine making a withdraw from a bank account while there is a deposit operation in progress.
Here is anexample of using CCriticalSection to avoid such problem. (it is from an article by Dianne M. Marsh on VisualC++ magazine)
class AccountInfo
{
private:
float balance;
string accountName;
CCriticalSection balanceCode;
CSingleLock *balanceLock;
public:
AccountInfo(const string &name) :
balance(0.0), accountName(name)
{
balanceLock = new
CSingleLock(&balanceCode,
false);
}
~AccountInfo() {
delete balanceLock;
}
void deposit(float amount) {
balanceLock->Lock();
balance += amount;
balanceLock->Unlock();
}
void withdraw(float
amount) {
balanceLock->Lock();
balance -= amount;
balanceLock->Unlock();
}
float getBalance() const {
balanceLock->Lock();
float val = balance;
balanceLock->Unlock();
return val;
}
};
On the other hand it could be that you are calling
endthread() before you are returning from the thread function, hile one of the vaiables declared in the thread function is declared on the stack and it does some cleaning in the destructor. To solve this problem, Use new and delete.
Otherwise, if this did not help, I suggest you post some code samples.
Cheers
Alfadhly
It is Illogical to define an inventor by his invention
|
|
|
|
|
Here I post some sample codes:
// myDlg class (class A)
CSocketSvr mySocket; // my socket variable
// ActiveX event handler
void myDlg::OnReceivedData(LPCTSTR ReceivedData)
{
...
// I start my thread - it will execute for the first time I receive any data
if (TRUE)
{
pThread = (CWzdThread*)AfxBeginThread(RUNTIME_CLASS(CWzdThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
}
...
}
// my method
void myDlg::Check()
{
if (mySocket.GetConnectedStatus()) <--- THIS IS WHERE IT GIVES ME THE RUNTIME ERROR
{
...
}
}
/////////////////////////////////////////
// CWzdThread class (class B)
myDlg* pDlg;
int CWzdThread::Run()
{
while(TRUE)
{
...
pDlg->Check();
}
}
///////////////////////////////////////////////
// CSocketSvr class (the activeX control class)
// to get the connection status
bool CSocketSvr::GetConnectedStatus()
{
....
return result;
}
I think this will give you enough information about what I am trying to do here.
mmm I still don't get it where should I add the Lock function.
Can you please explain more on that.
Thank you so much for your help.
FM
|
|
|
|
|
Hi,
this is assuming that the variable *pDlg has been initilized
to be equal to the this pointer of myDlg when it is created ,
in the oninitdialog or so
If the mySocket variable exist the error should happen
somewhere here
bool CSocketSvr::GetConnectedStatus()
{
....
return result;
}
if it does not exist, then it should not have been called at all unless you have multiple threads accessing the same instance.
on the other hand it could be that you are accessing the same variable while it is being used. (the case each time new data is being received)
so you must call the lock before you call any operation on the variable.
Here is a simple way without using MFC
1) Declare critical section
CRITICAL_SECTION g_CriticalSection;
...
..
..
2) When Program Starts, initilize the critical section
::InitializeCriticalSection (&g_CriticalSection);
3) When the program terminate, delete the critical section
::DeleteCriticalSection (&g_CriticalSection);
4) Whenever you are accessing mySocket
::EnterCriticalSection (&g_CriticalSection);
if (mySocket.GetConnectedStatus()) <--- THIS IS WHERE IT GIVES ME THE RUNTIME ERROR
{
..
}
::LeaveCriticalSection(&g_CriticalSection);
It is Illogical to define an inventor by his invention
Cheers
Alfadhly
|
|
|
|
|
mmm.. it seem it doesn't work with the critical section.
Still give me the same error.
Don't know why thread still cannot call the activeX control methods?
FM
|
|
|
|
|
Hi Farah,
Does that mean you have already initilized the *pDlg to point to an instance of MyDlg?
Cheers
It is Illogical to define an inventor by his invention
|
|
|
|
|
Yupp. I already assign *pDlg to point to an instance of myDlg.
FMansor
|
|
|
|
|
I hope you don't mean this line
myDlg* pDlg;
Cheers
It is Illogical to define an inventor by his invention
|
|
|
|
|
Yupp. That's what I did. But before I resume the thread, I assign this (which belongs to dialog class) to pDlg.
This is my code:
in dialog class:
void CMyDlg::OnDataArrival()
{
....
pThread = (CWzdThread*)AfxBeginThread(RUNTIME_CLASS(CWzdThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
pThread->MainDlg(this);
pThread->ResumeThread();
...
}
in thread class:
void CWzdThread::MainDlg(CMyDlg* spDlg)
{
pDlg = spDlg;
}
int CWzdThread::Run()
{
...
pDlg->Check();
...
}
Hope I do not confuse you.
TIA
FM - I can't remember my username
|
|
|
|
|
Hello, I am looking for some code that will produce consecutive sums for instance 5 is 2+3, 1+4, 0+5
If you have a good idea.. please let me know as to i cannot understand my teacher.. thank you
karen
|
|
|
|
|
Couldn't you just set one variable, call it X, to equal the value, an other, call it Y to equal zero, then set up a loop for Y that increases to the starting value of X. Then in each iteration you subtract one from X, and you'll always have two values that add up to the one you want.
I'm loathe to post code because I wouldn't want to encourage you to copy it without understanding it, but if you have a shot at it and post your code I'd be happy to go over it and make suggestions.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
ok ill post the code in the morning..
Thanks
|
|
|
|
|
ok here is my partial code
#include <iostream>
using namespace std;
int main()
{
int i,x,input,j,sum;
cout <<"please enter a number"<<endl;
cin>> input;
//while (input>-1)
{
for (i=1; 1<=input; i++)
{
for (j=i;j<=input;j++)
{
sum=sum+j;
}
}
}
cout <<"Sum"<
|
|
|
|
|
FWIW I'll start by telling you to do a less than or greater than sign into the forum you need to use shift-7 (ampersand) followed by gt or lt. If I just type what I just explained I get < >, but typing in the symbols gets stripped as an HTML tag. Also typing <pre> and </pre> allows you to format the code as you see below.
You're on the right track, but I thought you wanted to output actual sums, as in 1+6=2+5=3+4...=7 ?
To do that you will need to do this:
int value1 = input;
for (int value2 = 0; value2 <= input; ++value2, --value1)
{
cout << value1 << " + " value2 << " = ";
}
cout << input << endl;
So what I am doing is maintaining a count from 0 to the input number, and another from the input number to 0. Adding one to one while removing one from the other means they will always add up to equal 'input', and so I can print the sum in a loop, finishing with the whole value.
I didn't test this code, so LMK if it doesn't work, or if there is something you do not understand (I'm not terribly good at explaining things ).
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
nono it has to be consecutive sums..
input=11
1+2+3+4+5=15
2+3+4+5=14
3+4+5+6=12
4+5+6=14
5+6=11
you have to increase it by 1 each time is which i have done
but what should i place after sums=sums+j ??
to make sure that after it finds the nubers added and it went over 11 to check again?
|
|
|
|
|
Ah... I get it now.
Does it have to be a sequence of a particular maximum size ? Do you have to approach the problem this way ? I'd approach it by saying if I use a sequence of n numbers to add up to x, then x%n = n-1, so that's what I would look for within a loop. To do it the way you are seems to me more complex, although it may be the way your teacher wants you to do it for the sake of the exercise.
LMK if you must do it the way you are, I'm going to have a play with it now.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|