|
His original code was:
void CMyButton::SetButtonText(CString text)
{
this->SetWindowText("");
}
I am not sure how this can recurse?
It was probably because he did not set it to a 'real' button window before trying to set the text.
One way to check:
void CMyButton::SetButtonText(CString text)
{
if( ::IsWindow(this->m_hWnd) ){
this->SetWindowText("");
} else {
// Gadzooks! No window is assigned yet! Set status to DefCon IV!
}
}
|
|
|
|
|
Blake Miller wrote:
I am not sure how this can recurse?
Did you not try it out? It can, and does, recurse. Why would it not? The call to this->SetWindowText("") matches the prototype of void CMyButton::SetButtonText(CString text) . This is all due to CString 's LPCSTR operator.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hello David;
I just tried it out. No recursion occurred whatsoever.
SetButtonText does not get called by SetWindowText. The functions have similar signature, but different name. And that is why I originally did not beleive they would recurse, by inspection, but now I demonstrated to myself they do not recurse - by definitive testing.
I noticed that there was a runtime assertion on a window handle WinOcc.cpp - line 229 - ASSERT(::IsWindow(m_hWnd)); , but once I did SubclassDlgItem on an existing button control it works as expected. I maintain you can not SetWindowText on a CButton or CButton-derived class until the class has been assigned to an existing button window.
This is code path I observed:
CMyButton::SetButtonText -> CButton::SetWindowText -> ::SetWindowText
If you can get it to recurse, please explain exactly how.
|
|
|
|
|
Ok, I totally messed up. I thought both were SetWindowText() . I should've read just a tad closer. No wonder my comment to you and Giorgi sounded weird.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
The codes below are used to create button and activate some function, when I compile it, it shows some error message as below.
could some of you tell me how to solve it!
Thanks!
RunButton ( HWND hwnd )
{
CreateWindow(
"BUTTON",
"Run",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
380,
40,
60,
25,
hwnd,
NULL,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
return 1;
}
.
.
.
case WM_COMMAND:
switch HIWORD(wParam)
{
case BN_CLICKED:
switch (lParam)
{
case RunButton: <--- error C2051: case expression not constant
CetCapConnect( hwnd );
break;
} <--- warning C4060: switch statement contains no 'case' or 'default' labels
break;
|
|
|
|
|
Francis Chau wrote:
RunButton ( HWND hwnd )
{
CreateWindow(
"BUTTON",
"Run",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
380,
40,
60,
25,
hwnd,
NULL,
This last NULL should be the ID of your button. This will be the value passed in the loword of the wparam parameter in the BN_CLICKED notification.
Francis Chau wrote:
case WM_COMMAND:
switch HIWORD(wParam)
{
case BN_CLICKED:
switch (lParam)
{
case RunButton:
The lParam parameter contains the HWND of your button, which is the return value of the CreateWindow() function. Also the case expression has to be a constant value, the compiler has to know what the value is when it compiles the code, it can not be a value that is generated when the code is run. If you want to switch on a variable then you have to use the if...else if construct.
This is how I would do it, but I would also add some error checking to make sure that CreateWindow() actually was able to create the button.
#define ID_RUNBUTTON 1001
.
.
.
RunButton ( HWND hwnd )
{
CreateWindow(
"BUTTON",
"Run",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
380,
40,
60,
25,
hwnd,
ID_RUNBUTTON,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
return 1;
}
.
.
.
case WM_COMMAND:
switch HIWORD(wParam)
{
case BN_CLICKED:
switch (LOWORD(wParam))
{
case ID_RUNBUTTON:
CetCapConnect( hwnd );
break;
}
break;
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
|
hi,
im using EnumPrinters to detect local printers on win2k. however this returns all printer devices found on the system, incl. for example also "Microsoft Office Document Image Writer" or "Adobe PDF Writer". How to programatically found out which of the detected handles is for a 'real' hardware printer?
thanx
|
|
|
|
|
I think you can't.
Don't try it, just do it!
|
|
|
|
|
nice
hm... any other way getting this info ? through the printer handle from OpenPrinter ?
|
|
|
|
|
hi if any one can help me...
i need code for encryption "symetric" by vc++ couse i tried befor to anderstanding how to code it but i need example or some thing to read about kind of encry by vc++...
i hope some one can help by sending me algor.. or code..
thanks alot.
|
|
|
|
|
|
Hmmm... Microsoft CryptoAPI can be a problem, because there are windows versions in some countries that do not support it.
There are websites that provide information on different algorithms, some of them also provide source codes. Google for it.
If you need a hint on what symmetric algorithm to use, I propose AES (Advanced Encryption Standard alias "Rijndael") to you.
Don't try it, just do it!
|
|
|
|
|
Alexander M. wrote:
Hmmm... Microsoft CryptoAPI can be a problem, because there are windows versions in some countries that do not support it.
Thanks for the information, can you please provide some link which says this ?
Also are there separate versions of windows for some countries ?
suhredayan There is no spoon.
|
|
|
|
|
No seperate versions of windows, but seperate versions of CryptoAPI.
Some countries have special laws and classify cryptographics as military technology.
I don't have any links for you, but I'm sure you will find very much information using google. Just use "AES" as keyword.
Don't try it, just do it!
|
|
|
|
|
hi.. plz if u can give to me a project made by vc++ for blowfish or aes algorithms for encryption easy to understand.. i tried to use that one in code project it's soo good but not easy to me i want to trying to cood it by my self i couldn't,,, if u can help me sorry for asking alot..
thanks forr all
|
|
|
|
|
Hi,
there are several libraries that can be used. Most of them supports a lot of algorithms.
The most used should be Crypto++ but I'd like cryptlib also (in my opinion it's easier to use and to add in VC projects ).
Imho it's really hard to understand how encryption works starting from code, so I suggest you to start from some RFC or something similar (a good example would be rjindael but you can "google" for a lot of other example )
Bye,
Francesco
|
|
|
|
|
thanks alot for ur help ...
i choosed algorithm called blowfish and i get some info about it but i didn't found good code vc++ or discrition about it..
if u can help me to found simple project to try it and see hoe it is working ...
it will be big help for me and thanks again for information..
for all
|
|
|
|
|
There are several example in codeproject using blowfish
this and
this are two implementation
Bye,
Francesco
|
|
|
|
|
|
hi.. plz if u can give to me a project made by vc++ for blowfish or aes algorithms for encryption easy to understand.. i tried to use that one in code project it's soo good but not easy to me i want to trying to cood it by my self i couldn't,,, if u can help me sorry for asking alot..
thanks forr all
|
|
|
|
|
or for (des) data encryption standarad.. code or algorithm
|
|
|
|
|
Hi, I'm writing an app in which I want to suspend the PC and then wake up sometime later. Having trouble with the wake up (it doesn't happen !!)
My test code is as follows:-
LARGE_INTEGER liDueTime;
HANDLE hWaitTimer;
hWaitTimer = CreateWaitableTimer(NULL,FALSE,"Test timer");
liDueTime.QuadPart=-1200000000; // 2 minutes;
BOOL rc = SetWaitableTimer(hWaitTimer,&liDueTime,0,
pTimerProc,NULL,TRUE);
rc = SetSystemPowerState(NULL,TRUE); // 2nd parm is Resume
DWORD dwError;
if(rc == 0)
dwError = GetLastError();
// WAIT HERE !!!
if (WaitForSingleObject(hWaitTimer, INFINITE) != WAIT_OBJECT_0)
{
printf("WaitForSingleObject failed (%d)\n", GetLastError());
return 3;
}
else
{
printf("Timer was signaled.\n");
return 100;
}
I have run the code with the SetSystemPowerState() commented out, and the timer signals O.K. So any idea about why it won't wake up ? (Tried it on Win2000 and Win98 (needed ultimately for the later) Thanks !
Doug
|
|
|
|
|
After SetWaitableTimer() call, do a GetLastError() and see if it returns ERROR_NOT_SUPPORTED which means "The system does not support a restore".
Note: SetWaitableTimer() succeeds even if the system dosen't supports a restore from a suspended power conservation mode
suhredayan There is no spoon.
|
|
|
|
|
Hi, Just added an unconditional GetLastError() call after the SetWaitableTimer() call as you suggested. It returned 0 (ERROR_SUCCESS) on the Win2K system, so I guess that restore IS supported. Any other ideas that can throw some light on the matter ?
Doug
|
|
|
|