|
Hi,
Enumprocessmodule fails when i am trying to get the currently running module file path.
|
|
|
|
|
The get the path to the .exe file that was launched to create the current process use GetModuleFileName() with a NULL module handle.
|
|
|
|
|
Per MSDN:
If the function fails, the return value is zero. To get extended error information, call GetLastError() .
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Maybe it's a problem of insufficient access rights. Try it with the local administrative account , or as elevated process in Vista , Win 7 to be sure it is a "permissions issue".
|
|
|
|
|
hi all,
using below example i calculate the hour and minute value,
please help me to calculate second value here.
WORD time =23929;
WORD hour, minute , second;
hour = time >> 11;
minute = time << 5 ;
minute = minute >> 10;
thanks.
|
|
|
|
|
That looks weird, what kind of time format do you use in your time variable?
|
|
|
|
|
time have hex type of values.
|
|
|
|
|
LOL so you are using bit ranges inside the integer? I would rather use Unix time to store the current time, if you use UTC that helps you to handle time zones too.
|
|
|
|
|
I assume it is the format used by the FAT file system due to the 2 seconds resolution.
|
|
|
|
|
|
This does not make a lot of sense but at a guess the bottom five bits of the number are supposed to represent the seconds, although that allows for a maximum of only 31 seconds. You will also get invalid values for minutes as you do not mask out the hour value. Perhaps you could explain where these values, and the shift constants, are derived from.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
WORD time = 23929;
WORD hour = time >> 11;
WORD minute = (time >> 5) & 0x3f
WORD seconds = time & 0x1f;
WORD time2 = seconds | (minute << 5) | (hour << 11);
|
|
|
|
|
You can create a struct or union to define the bit assignments:
typedef union _MyTime_t {
WORD tm;
struct {
unsigned sec : 5; unsigned min : 6;
unsigned hour : 5;
} bits;
} MyTime_t;
MyTime_t tm;
tm.tm = 23939;
printf("%02u:%02u:%02u\n", tm.bits.hour, tm.bits.min, tm.bits.sec * 2);
|
|
|
|
|
|
Now I have build my application like this: it runs in the container of Internet browser(IE, FireFox, Chrome and so on). There is a modeless dialog in my program, the dialog contains one CEdit control.
Here is my problem: when user activate the Edit control to type into something, the edit control get the focus. When the edit control loses the focus, I must check whether the input is valid. If not, I will display a model dialog with
AfxMessageBox . But now I cannot determine whether my edit control loses in my own application. Because the edit control may loses focus by a lot of means, for example, when user close the browser, when user open a text program. In these cases, I will just skip the invalidation check.
Any one can tell me how to find that in which way my edit control loses focus.
Any help will be appreciated!
|
|
|
|
|
|
Thank you very much!
It is just what I want.
|
|
|
|
|
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.
|
|
|
|