|
But are you checking for that style using the equality operator or the bitwise AND operator? It makes a big difference.
Otherwise, you'll also need to compare the class name as has already been suggested.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
AFAIK I'm using the & operator.. although I don't have code in front of me to check it.
Joel Holdsworth
|
|
|
|
|
Check these two things:
1. Check for the style flag (BS_GROUPBOX)
2. Check the class name ("BUTTON")
It should be pretty fail-safe. If nothing else helps, then use Spy++ to get the style DWORD value of the group control and do a direct comparison. If you're using Dialog Editor to create your dialogs, it always creates "similar" group box controls.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I do not know if you figured this out already, but this is the code I use
(pWnd->IsKindOf(RUNTIME_CLASS(CButton))) &&
(((pWnd->GetStyle()) & BS_GROUPBOX) == BS_GROUPBOX)
BS_GROUPBOX is defined as 0x7 ( 0111 in binary ) so it is a combination of bits. Using just GetStyle() & BS_GROUPBOX will return a positive value if any one of the three bits are set (ie for BS_DEFPUSHBUTTON, BS_CHECKBOX, BS_AUTOCHECKBOX and BS_RADIOBUTTON). By checking for equality you ensure that all three bits are set.
"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!
|
|
|
|
|
Does anyone know a good way to prevent Alt+F4 from exiting my MFC app?
Joel Holdsworth
|
|
|
|
|
Is there any specific reason of why you'd need to prevent these hotkeys ?
Alt+F4 (and CTRL+F4) are considered as global, all-working hotkeys to close Windows applications. They are available as "last resort" commands to close down a non-functioning or an incorrectly running application, and as such, they shouldn't be disabled for light reasons.
A more effective way is to implement an "application closing" handler (WM_QUIT) that will tell the user to save open documents and/or warn the user if it is unwise to exit the application at this moment.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Yeah I know [sigh], I'm aware of the windows standard, but there's a fairly good reason to break the rules in this context... I'm writing software to control 30-40 hydraulic jacks, each designed to carry around 800 tonnes. The idea here is that the interface is really dumned down, and only a few very select hot-keys are implemented. And the idea of the app exiting halfway through a lift is very undesirable (despite the fact that you'd have to be really stupid to press Alt+F4 while working on this thing). The customer has requested the keys to be surpressed, so I can't really get around this!
Joel Holdsworth
|
|
|
|
|
Alt+F4 sends, IIRC, a WM_SYSCOMMAND message with the SC_CLOSE flag. If you allow that to propogate down to DefWindowProc, it gets turned into a WM_CLOSE, which in turn if not handled by you ends up in DefWindowProc which calls DestroyWindow.
You can intercept the WM_CLOSE message and simply not do anything. Yes, it's evil Windows won't try to kill off your app, or bring up the 'End Task' dialog, because you're still handling messages. Assuming this is XP. I hope it isn't, because XP doesn't have any kind of real-time guarantees, so you'll have unpredictable response times to interrupts. If you're using a real-time kernel with XP, feel free to ignore me.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Well, I do still want to allow exiting, just not by the Alt+F4 method. As for using WM_SYSCOMMAND... will that still allow closing from the close button or sys menu?
Joel Holdsworth
|
|
|
|
|
Er, I don't think so.
Guess it's the old keyboard hook trick, then, or override PreTranslateMessage and throw away WM_SYSKEYDOWN and WM_SYSKEYUP where wParam is VK_F4 .
I think a standard, rather than low-level, hook will sort you out since Alt+F4 is handled by the application, not by the system.
BTW, I'm stabbing in the dark a bit here: my main responsibility is as a Pocket PC developer, which doesn't have these keys...
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Override the window procedure function. If message is WM_CLOSE, ignore it and return zero. This disables Alt+F4 usage completely. However, for a more effective solution, create a boolean variable inside the window's class. When the user attempts to quit the application by using a "legimate way", such as a menu selection or pressing the X button, then set the boolean to true, and allow the WM_CLOSE message to pass through, thus ending the application.
Your application can still be closed by pressing ESC or ENTER/RETURN, if it is a dialog-based application. Both methods are easy to disable: monitor for WM_KEYDOWN messages, and if the message is generated by ESC/RETURN/ENTER, ignore and return zero. Again, using a boolean variable allows to know whether it's a "legimate" press or an accidental one (entering a number into a field and pressing ENTER, for example)
If it is a standard Windows-application (non-dialog), then the ESC/RETURN/ENTER make no difference, I think. But you should test them all out nevertheless, as I don't want a 800 ton weight to drop on me
For all other key combinations used to end an application, here's perhaps-a-complete list: CTRL+F4, ALT+F4, ESC, RETURN and ENTER.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Anyone have any sample code on how to use CredUIConfirmCredentials with CredUIPromptForCredentials to verify local users on there computer.
Thanks
|
|
|
|
|
Anthony9887 wrote:
Anyone have any sample code on how to...verify local users on there computer.
Can you not use this, or are you stuck with CredUIConfirmCredentials() and CredUIPromptForCredentials() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Yes, I'm stuck on using CredUIConfirmCredentials() with CredUIPromptForCredentials. Do you have a code sample on how to use both?
Thanks
|
|
|
|
|
Hello,
I am trying to write code to open an explorer window and highlight a given file in that folder.
I am using ShellExecute(hwnd, "explore", fileName, NULL, path, SW_SHOW) to do this but it does not always seem to work.
Is there a better way to do this?
Thank you,
Andy Moore
|
|
|
|
|
Andy Moore wrote:
but it does not always seem to work.
So it works sometimes and not others, is that correct? When it does not work, what are the symptoms? What is ShellExecute() 's return value?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I have a app that runs on several PC.
My problem is that on some PC the text bmp's and rectangles are smaller.
The Monitors and PC are the same except for the graphic card.
I'm using MM_LOENGLISH and DeviceCaps are 96 on x and y on both PC's.
If I create a CRect top = -83, bottom = -38, left = 5, right = 95 and do a LPtoDP.
On one PC I get top = 54, bottom = 25, left = 3, right = 62 on the other
I get top = 80, bottom = 37, left = 5, right = 92?????
How do I make them all the same?
Please help!!!
Thanks in advance!
|
|
|
|
|
newbeetoc wrote:
DeviceCaps are 96 on x and y on both PC's
which DevCaps are 96? HORZSIZE, HORZRES, LOGPIXELSX ?
Software | Cleek
|
|
|
|
|
|
Hello,
I know that this may sound like a trival question, but I am trying to automatically generate the filter string for the lpstrFilter member of the OPENFILEDIALOG structure.
I look up the file extension in the registry and attempt to build the filter string by concatenating the string from the registry with the extension. I have not had much luck doing this. Perhaps is there an easier approach to this?
Thank you,
Andy Moore
|
|
|
|
|
Andy Moore wrote:
I look up the file extension in the registry and attempt to build the filter string by concatenating the string from the registry with the extension. I have not had much luck doing this.
Maybe it's just me but that does not tell me anything I can use to help.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I guess basically what I am trying to do is if I have a file with a .zip extension, I want to call GetOpenFileName(&ofn) with the lpstrFilter set to filter only zip files, etc. I can look up HKCR/*.zip in the registry and get a string like "WinZip file". I am trying to generate the filter "WinZip Files (*.zip)\0*.zip\0".
I was wondering if there was already API functions that do this so I could avoid reinventing the wheel.
Thank you,
Andy Moore
|
|
|
|
|
nice idea.
Maybe AssocQueryStringByKey can help you, or IQueryAssociations.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thanks for the pointer. I will take a look at these.
Andy
|
|
|
|
|
Andy Moore wrote:
I am trying to generate the filter "WinZip Files (*.zip)\0*.zip\0".
Can you not just concatenate those two strings together using strcpy() /strcat() , or with a CString object if you are using MFC?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|