|
Hey there
I have a Windows applications written in C++ using Win32 API's.
The problem am facing now is, if the user presses the Alt + F4 key the application will close.
Is there a way of disabling that via the app itself?
Like capturing the windows shortcut key and then do nothing?
Same about Ctl + Alt + Del.
Is it possible to disable that?
How can i capture these key presses in my app?
Thanks in advance.
|
|
|
|
|
Don Guy wrote: Same about Ctl + Alt + Del.
Why would you want to disable that? Is there any good reason to not give a user the ability to close your application?
|
|
|
|
|
You can disable Alt + F4 by handing the WM_SYSCOMMAND message, checking if WPARAM is SC_CLOSE and then returning 0 .
As for Ctrl + Alt + Del , you're out of luck. You cannot block it.
|
|
|
|
|
To disable ALT + F4 simply return TRUE .
The code below intercepts ALT + F4 and does nothing.
More [here] , [here] and [here].
BOOL myDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if( GetKeyState( VK_MENU ) )
{
if( pMsg->wParam == VK_F4) ) { return TRUE; }
}
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
A common way to disable window closing is returning zero from WM_COMMAND. This is the place where ppl usually put the "Really wanna exit?" dialogs and they don't call DestroyWindow() if the user doesn't want to exit or has unsaved work (etc...). Some ppl like hiding the window more than destroying it on WM_CLOSE because this way it keeps the gui state. As for Ctrl+Alt+Del, and other ways to kill your process... If I guess right and you wanna prevent your program from closing/killing than instead of blocking Ctrl+Alt+Del it would be better to hide your process from process enumeration, I did that only on older windows systems and its quite windows version dependent how to do it, search a recent article about it with google.
EDIT: If you wanna block the Ctrl+Alt+Del to prevent windows shutdown, thats a useless idea because ppl use the power button from reflex in that case.
|
|
|
|
|
Ctrl + Alt + Del is a different thing:
In Windows XP you can create your own GINA.DLL (look for information about that).
In other OS versions you have to edit policies.
Searching for both things in google will help you.
Anyway, keep in mind that you can't do that from a normal application so forget about putting it into your application.
Of course it can be done, but by modifying an internal DLL and / or by modifying policies in the computer.
Good luck.
|
|
|
|
|
Hello all. I am new to image processing and am having trouble with CreateDIBSection. I have been reading other threads on this topic and code snippets for several days now, so I was hoping at this point to get specific help with my code rather than a link to a previous explanation or code.
I have a dialog based app. I want to take a screen shot, change some of the pixel colors and BitBlt it back. In my attempt to make a rectangle of red pixels (or any color) that is 800 pixels in width and 900 in height, I end up with 4 rectangles that are 200 pixels in width and 225 pixels in height, that are separated by 36 pixels and that are alternating is color between red a blue. I'm guessing that this has something to do with the padding.
I'd really appreciate an help you can offer!
CDC* pDC=GetDC();
HDC hDC = *pDC;
HDC hDCMem = CreateCompatibleDC(hDC);
BYTE* lpBitmapBits = NULL;
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = m_rcMainRect.Width();
bi.bmiHeader.biHeight = -m_rcMainRect.Height();
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
HBITMAP bitmap = ::CreateDIBSection(hDCMem, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
HGDIOBJ oldbmp = ::SelectObject(hDCMem, bitmap);
BitBlt(hDCMem, 0, 0, m_rcMainRect.Width(), m_rcMainRect.Height(), hDC, 0, 0, SRCCOPY);
for(int x=0; x<800; x=x+4)
{
for(int y=0; y<900; y++)
{
lpBitmapBits[(y*m_rcMainRect.Width())+x] = 0x00;
lpBitmapBits[(y*m_rcMainRect.Width())+x+1] = 0x00;
lpBitmapBits[(y*m_rcMainRect.Width())+x+2] = 0xFF;
lpBitmapBits[(y*m_rcMainRect.Width())+x+3] = 0x00;
}
}
BitBlt(hDC, 0, 0, m_rcMainRect.Width(), m_rcMainRect.Height(), hDCMem, 0, 0, SRCCOPY);
SelectObject(hDCMem,oldbmp);
DeleteDC(hDCMem);
DeleteObject(bitmap);
|
|
|
|
|
The width of the bitmap is in pixels (DWORDs)
and your buffer is in BYTEs ...
PS: You can use all GDI functions in the memory-DC as well.
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
modified 14-Aug-12 3:29am.
|
|
|
|
|
Thanks so much for the quick reply. You are a lifesaver! (Or... at least a sleep saver.)
|
|
|
|
|
A good advice for the future: The size in bytes occupied by one row of pixels in memory is called stride. Its important that in bitmaps stride is always a multiple of 4 bytes. In your cases this condition is true in all cases regardless of the bitmap width because 1 pixel occupies 4 bytes. But for example in a 8 bit bitmap (256 colors) with width==3 the stride would be 4 bytes regardless of the actual size being 3 bytes, there would go 1 byte extra padding.
stride = ((width * bits_per_pixel + 31) >> 3) & ~3;
|
|
|
|
|
|
|
Hi Guys
I have designed a digital controller in matlab. The continuos s domain controller is as follows:
1.16e006 s^2 + 6.287e006 s + 2.436e006
--------------------------------------
s^2 + 10 s
The discretised z domain version (with a sampling rate of 100Hz) is as follows:
1.16e006 z^2 - 2.26e006 z + 1.1e006
-----------------------------------
z^2 - 1.905 z + 0.9048
Now i have managed to program this in C++ and it "sort of" works. However the code is by no means optimal and therefore does not execute as quickly as it should. The code basically looks like this:
float SpeedDemand;
float SpeedError;
float MeasuredGeneratorSpeed;
float y;
float numcoeff[3];
float dencoeff [3];
numcoeff[0] = 1160000;
numcoeff[1] = -2260000;
numcoeff[2] = 1100000;
dencoeff[0] = 1;
dencoeff[1] = -1.905;
dencoeff[2] = 0.9048;
static float xprevious[3];
static float yprevious[3];
SpeedError = MeasuredGeneratorSpeed - SpeedDemand;
xprevious[0] = SpeedError; y = xprevious[0]*numcoeff[0];
y += ((xprevious[1]*numcoeff[1])+(xprevious[2]*numcoeff[2])-(yprevious[1]*dencoeff[1])-(yprevious[2]*dencoeff[2]));
xprevious[2] = xprevious[1]; xprevious[1] = xprevious[0];
yprevious[2] = yprevious[1];
yprevious[1] = y;
Where xprevious[],yprevious[] are arrays that i define earlier in the program. They are used to store the previous input and output values. X is the input and Y is the output. The numbers stored in the numcoeff[] and dencoeff[] arrays correspond to the coefficients in the z domain transfer function shown at the top. Is there a faster way to do this calculation in c++, perhaps by using a circular queue!!??. Unfortunately my programming knowledge is not great(I'm a Matlab guy). If there is a better way to do it that would speed up the calculation perhaps someone could give me an eample of how to do it. By the way all the variables and arrays are floating point. Any help or advice would be much appreciated.
Many Thanks
Ben
modified 14-Aug-12 5:16am.
|
|
|
|
|
that looks pretty straightforward. i doubt a circular buffer is going to give you much improvement - you're just copying some floats around, after all. no matter where they reside or how you abstract your data structure (array, circ buffer, etc), you're still copying floats.
you could probably speed it up a bit using vector processing - execute those four multiplications in one call. you could do the addition/subtraction in one call, too. search here for "SIMD" or "SSE". though that stuff might look a little scary, if you're coming from MatLab...
modified 13-Aug-12 15:35pm.
|
|
|
|
|
Chris Losinger wrote: might look a little scary, if you're coming from MatLab...
just very-little bit scary
|
|
|
|
|
Introduction to SSE Programming [here].
Fast SIMD Prototyping [here].
Matrix/Vector Multiplication Optimization [here].
|
|
|
|
|
Hi,
would anyone know if there is any kind of plug-in to the Visual studio debugger which tracks heap storage
Thanks
|
|
|
|
|
Are you looking for memory profiling tools?
If affirmative, you can have a look at Purify Plus etc.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
I have been using CMemoryState
|
|
|
|
|
I would like to know a way to change the view of a particular pane in a splitter window.
It should be something like an explorer window. Where on click of any tree branch on left side of window right hand side view updates.
Similarily i would like to update my view. On click of any tree node a new pane should be displayed at the same position overriding the previous pane.
sample code would be highly appreciated.
|
|
|
|
|
There are lots of samples of code such as you describe; take a look in the articles section[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
these examples describe how to use a tree control.. what i want is to update the SPLITTER pane with a new view on click of any tree item..
|
|
|
|
|
Rishav Prabhakar wrote: what i want is to update the SPLITTER pane with a new view on click of any tree item.. Then you need to handle the notifications from the TreeView [^] side and take some action, like redrawing the window in the other pane, when the selection changes.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
HI,
Is there any API available to Pan a window, as we can in autocad/pdf file/Pro-e.
If not, how pan a window using C++ code.
Regards,
Maha
modified 17-Aug-12 2:22am.
|
|
|
|
|
What do you mean on panning? Moving? Or scrolling the contents of the displayed stuff?
modified 13-Aug-12 10:36am.
|
|
|
|