|
NULL is not INVALID_HANDLE_VALUE , but (I guess) it is still is an invalid handle value.
That's said, I agree with you: he should return INVALID_HANDLE_VALUE.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
|
|
Mark Salsbery wrote: I knew you were going to bring that up!
MS's trap!!!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
If this is possible, I don't think it should be.
To borrow a phrase, "what if you could do this?"
1/ Do you think people who write viruses / trojans / rootkit / bad stuff(tm) would say to themselves "oh, it would be irresponsible of us to use MakeOurAppUnstoppable (), so we'll leave that API only for good people".
2/ You have a bug in your program, and it's in an infinite loop, guzzling memory. How do you close it to put your NewEvenShinierApp.exe?
3/ There is no (3). I'd convinced myself at (1)...
Iain.
|
|
|
|
|
Wonderful.
Good stuff for 'memorable quotes' on my blog.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Why ? Wouldn't this be considered rude ?
|
|
|
|
|
I am not able to think of a legitimate purpose why you want to do this. Why should your process run forever? The user must have the freedom to quit any process that they want to and delete any files that they want to.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: I am not able to think of a legitimate purpose why you want to do this. Why should your process run forever? The user must have the freedom to quit any process that they want to and delete any files that they want to.
How about a software that can keep an eye on all the users logged in to your office network at any given time, and of course the users should not be able to terminate this. Trying to achive something like without using access previlages and no service, it looks he has few windows 9x clients also
|
|
|
|
|
One good use:
Anti-malware, keep the program running as a diagnostic tool.
Ps.
Ring 0, or ring 3 can't think of it.
IF you look at it from a malware writer's perspective, it would usually involve dll injection, dual processes, or creation of a driver.
Whether the code is revealed or not, malware will ALWAYS be written as will diagnostic software.
|
|
|
|
|
But why do you want to do it I want to delete or uninstall your program ?
|
|
|
|
|
|
Anil K P wrote: (users with Admin right and below)
If you can take the Admin out of that list, then this should be possible by carefully assigning the permissions, for the users you may wish to deny.
Anil K P wrote: I can't make this executable a service, but need it as an executable itself.
A service is also an executable. Anyways if you dont like the idea of service, still you can try remote execute your application as an administrator through network.
|
|
|
|
|
I made my dialog box transparent.. so that when i draw something on dialog it looks like i draw on desktop screen. Now when i put another window over the drawn stuff it took previous window background. How do i overcome this.. Below is my code.. Please take a look..
|
|
|
|
|
#include <windows.h>
struct
{
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY palPalEntry[12];
} palPalette =
{
0x300,
12,
{
{0xFF, 0x00, 0x00, PC_RESERVED},
{0xC0, 0x40, 0x00, PC_RESERVED},
{0x80, 0x80, 0x00, PC_RESERVED},
{0x40, 0xC0, 0x00, PC_RESERVED},
{0x00, 0xFF, 0x00, PC_RESERVED},
{0x00, 0xC0, 0x40, PC_RESERVED},
{0x00, 0x80, 0x80, PC_RESERVED},
{0x00, 0x40, 0xC0, PC_RESERVED},
{0x00, 0x00, 0xFF, PC_RESERVED},
{0x40, 0x00, 0xC0, PC_RESERVED},
{0x80, 0x00, 0x80, PC_RESERVED},
{0xC0, 0x00, 0x40, PC_RESERVED}
}
};
POINT pt12[12] =
{
{0, 1000},
{500, 866},
{866, 500},
{1000, 0},
{866, -500},
{500, -866},
{0, -1000},
{-500, -866},
{-866, -500},
{-1000, 0},
{-866, 500},
{-500, 866}
};
void Animate(HWND hwnd, HPALETTE hPalette)
{
HDC hDC;
PALETTEENTRY pe[12];
HPALETTE hOldPal;
static int nIndex;
int i;
for (i = 0; i < 12; i++)
pe[i] = palPalette.palPalEntry[(i + nIndex) % 12];
hDC = GetDC(hwnd);
hOldPal = SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
AnimatePalette(hPalette, 0, 12, pe);
nIndex = (++nIndex) % 12;
SelectPalette(hDC, hOldPal, FALSE);
ReleaseDC(hwnd, hDC);
}
void DrawCircle(HWND hwnd, HPALETTE hPalette)
{
HDC hDC;
PAINTSTRUCT paintStruct;
RECT rect;
SIZE sizeO;
POINT ptO;
HPALETTE hOldPal;
int i;
hDC = BeginPaint(hwnd, &paintStruct);
if (hDC != NULL)
{
hOldPal = SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
GetClientRect(hwnd, &rect);
DPtoLP(hDC, (LPPOINT)&rect, 2);
ptO.x = (rect.left + rect.right) / 2;
ptO.y = (rect.top + rect.bottom) / 2;
sizeO.cx = MulDiv((rect.right - rect.left), 2, 3);
sizeO.cy = MulDiv((rect.bottom - rect.top), 2, 3);
for (i = 0; i < 12; i++)
{
HBRUSH hbr;
HBRUSH hbrOld;
hbr = CreateSolidBrush(PALETTEINDEX(i));
hbrOld = (HBRUSH)SelectObject(hDC, hbr);
Ellipse(hDC,
ptO.x + MulDiv(sizeO.cx, pt12[i].x - 259, 2000),
ptO.y + MulDiv(sizeO.cy, pt12[i].y - 259, 2000),
ptO.x + MulDiv(sizeO.cx, pt12[i].x + 259, 2000),
ptO.y + MulDiv(sizeO.cy, pt12[i].y + 259, 2000)
);
SelectObject(hDC, hbrOld);
DeleteObject(hbr);
}
SelectPalette(hDC, hOldPal, FALSE);
EndPaint(hwnd, &paintStruct);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
static HPALETTE hPalette;
switch(uMsg)
{
case WM_CREATE:
hPalette = CreatePalette((LPLOGPALETTE)&palPalette);
break;
case WM_PAINT:
DrawCircle(hwnd, hPalette);
break;
case WM_TIMER:
Animate(hwnd, hPalette);
break;
case WM_DESTROY:
DeleteObject(hPalette);
hPalette = NULL;
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR d3, int nCmdShow)
{
MSG msg;
HWND hwnd;
WNDCLASS wndClass;
if (hPrevInstance == NULL)
{
memset(&wndClass, 0, sizeof(wndClass));
wndClass.style = CS_HREDRAW | CS_VREDRAW ;
wndClass.lpfnWndProc = WndProc ;
wndClass.cbClsExtra = 0 ;
wndClass.cbWndExtra = 0 ;
wndClass.hInstance = hInstance ;
wndClass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndClass.hbrBackground = (HBRUSH) GetStockObject (HOLLOW_BRUSH ) ;
wndClass.lpszMenuName = NULL ;
wndClass.lpszClassName = "HELLO";
if (!RegisterClass(&wndClass)) return FALSE;
}
hwnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
"HELLO",
NULL,
WS_POPUP,
10,
10,
200,
200,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
SetTimer(hwnd, 1, 200, NULL);
while (GetMessage(&msg, NULL, 0, 0))
DispatchMessage(&msg);
KillTimer(hwnd, 1);
return msg.wParam;
}
</windows.h>
|
|
|
|
|
Sure, no sweat
First of all, the best approach I can see for this is to use a LayeredWindow approach. This necessitates win2k or higher and just 2 changes to your code.
It also means that 1 of the 2^24 colours available cannot be used, as this is used as the mask colour.
First, goto the line that sets the background for the window class
and change it to (where RGB(255,0,255) represents an arbitrary colour choice)
wndClass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(255,0,255));
Next, goto the line that updates the window after it's shown
and change it to:
SetLayeredWindowAttributes(hwnd, RGB(255,0,255), 255, LWA_COLORKEY|LWA_ALPHA);
Voila! You should now have a bunch of circles floating on whatever is under them.
Add this code, and you can drag it using the left mouse button.
case WM_LBUTTONDOWN:
SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION,NULL);
break;
In the above code, I have used 255,0,255 as the mask colour.
|
|
|
|
|
Hi..
Thanks for the help.. But i guess i need HOLLOW_BRUSH. To make it look like i draw on desktop screen..
After using your code it doesn't get hang on previous window. But i need to make the background transparent..
I hope you getting my point..
Thanks.
|
|
|
|
|
gothic_coder wrote: But i need to make the background transparent..
Sorry, I don't quite understand you here. With the changes I proposed the only thing you see is 12 coloured circles. The rest of the window is transparent - you can see objects below the circles. If you change the opacity, you can see objects _through_ the circles.
Perhaps I missed something else - I just noticed I missed a #define. If this doesn't help, & I'm just not 'getting it', I'll have another go if you can re-phrase you question.
#define _WIN32_WINNT 0x0501
#include <windows.h>
struct
{
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY palPalEntry[12];
} palPalette =
{
0x300,
12,
{
{0xFF, 0x00, 0x00, PC_RESERVED},
{0xC0, 0x40, 0x00, PC_RESERVED},
{0x80, 0x80, 0x00, PC_RESERVED},
{0x40, 0xC0, 0x00, PC_RESERVED},
{0x00, 0xFF, 0x00, PC_RESERVED},
{0x00, 0xC0, 0x40, PC_RESERVED},
{0x00, 0x80, 0x80, PC_RESERVED},
{0x00, 0x40, 0xC0, PC_RESERVED},
{0x00, 0x00, 0xFF, PC_RESERVED},
{0x40, 0x00, 0xC0, PC_RESERVED},
{0x80, 0x00, 0x80, PC_RESERVED},
{0xC0, 0x00, 0x40, PC_RESERVED}
}
};
POINT pt12[12] =
{
{0, 1000},
{500, 866},
{866, 500},
{1000, 0},
{866, -500},
{500, -866},
{0, -1000},
{-500, -866},
{-866, -500},
{-1000, 0},
{-866, 500},
{-500, 866}
};
void Animate(HWND hwnd, HPALETTE hPalette)
{
HDC hDC;
PALETTEENTRY pe[12];
HPALETTE hOldPal;
static int nIndex;
int i;
for (i = 0; i < 12; i++)
pe[i] = palPalette.palPalEntry[(i + nIndex) % 12];
hDC = GetDC(hwnd);
hOldPal = SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
AnimatePalette(hPalette, 0, 12, pe);
nIndex = (++nIndex) % 12;
SelectPalette(hDC, hOldPal, FALSE);
ReleaseDC(hwnd, hDC);
}
void DrawCircle(HWND hwnd, HPALETTE hPalette)
{
HDC hDC;
PAINTSTRUCT paintStruct;
RECT rect;
SIZE sizeO;
POINT ptO;
HPALETTE hOldPal;
int i;
hDC = BeginPaint(hwnd, &paintStruct);
if (hDC != NULL)
{
hOldPal = SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
GetClientRect(hwnd, &rect);
DPtoLP(hDC, (LPPOINT)&rect, 2);
ptO.x = (rect.left + rect.right) / 2;
ptO.y = (rect.top + rect.bottom) / 2;
sizeO.cx = MulDiv((rect.right - rect.left), 2, 3);
sizeO.cy = MulDiv((rect.bottom - rect.top), 2, 3);
for (i = 0; i < 12; i++)
{
HBRUSH hbr;
HBRUSH hbrOld;
hbr = CreateSolidBrush(PALETTEINDEX(i));
hbrOld = (HBRUSH)SelectObject(hDC, hbr);
Ellipse(hDC,
ptO.x + MulDiv(sizeO.cx, pt12[i].x - 259, 2000),
ptO.y + MulDiv(sizeO.cy, pt12[i].y - 259, 2000),
ptO.x + MulDiv(sizeO.cx, pt12[i].x + 259, 2000),
ptO.y + MulDiv(sizeO.cy, pt12[i].y + 259, 2000)
);
SelectObject(hDC, hbrOld);
DeleteObject(hbr);
}
SelectPalette(hDC, hOldPal, FALSE);
EndPaint(hwnd, &paintStruct);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
static HPALETTE hPalette;
switch(uMsg)
{
case WM_CREATE:
hPalette = CreatePalette((LPLOGPALETTE)&palPalette);
break;
case WM_PAINT:
DrawCircle(hwnd, hPalette);
break;
case WM_TIMER:
Animate(hwnd, hPalette);
break;
case WM_LBUTTONDOWN:
SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION,NULL);
break;
case WM_DESTROY:
DeleteObject(hPalette);
hPalette = NULL;
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR d3, int nCmdShow)
{
MSG msg;
HWND hwnd;
WNDCLASS wndClass;
if (hPrevInstance == NULL)
{
memset(&wndClass, 0, sizeof(wndClass));
wndClass.style = CS_HREDRAW | CS_VREDRAW ;
wndClass.lpfnWndProc = WndProc ;
wndClass.cbClsExtra = 0 ;
wndClass.cbWndExtra = 0 ;
wndClass.hInstance = hInstance ;
wndClass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndClass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(255,0,255));
wndClass.lpszMenuName = NULL ;
wndClass.lpszClassName = "HELLO";
if (!RegisterClass(&wndClass)) return FALSE;
}
hwnd = CreateWindowEx(WS_EX_TOOLWINDOW |WS_EX_LAYERED|WS_EX_APPWINDOW,
"HELLO",
"Colour Wheel",
WS_SYSMENU|WS_POPUP,
10,
10,
200,
200,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow(hwnd, nCmdShow);
SetLayeredWindowAttributes(hwnd, RGB(255,0,255), 155, LWA_COLORKEY|LWA_ALPHA);
SetTimer(hwnd, 1, 200, NULL);
while (GetMessage(&msg, NULL, 0, 0))
DispatchMessage(&msg);
KillTimer(hwnd, 1);
return msg.wParam;
}
|
|
|
|
|
Hey thanks a ton brother... That's works beautifully...
Anyways one question. If i try to add BMP in my resource and then make it transparent it didn't look good.. I mean masking make it transparent but not completely. Heard that transparency in PNG is good.
Any idea how can i use PNG in my project..
Thanks again.
|
|
|
|
|
It really is a pleasure my friend.
I did some work a while ago using transparent bitmaps. It was inspired by Hans Dietrich's XCPClock prject. Two points I should point out about my implementation:
1) It doesn't use MFC
2) The reflection on the dial is shown on top of the hands - a transparent bitmap.
Unfortunately, there are a few dimensions and offsets that are hard-coded though it should hopefully still guide you in your endevours.
You can find the project here. Transparent Bitmaps demo[^]
As for PNGs, there's a number of libraries out there that will deal with them. Never used any of them myself, though it shouldn't be too hard. You can look for libpng.
Also, you might like to check out the source code for "Slide Show Screen Saver for Windows" as found here[^]
The complete source is available there. Haven't had much of a look yet, though I do recall getting this code some years ago for the purpose of dealing with pngs and jpgs.
|
|
|
|
|
Thanks for the link.. I've this strong feeling that these link gonna help me out.. I'll take a look and get back to you asap...
|
|
|
|
|
I am trying to develop an application with dialogs to be skinned in XP style for Windows Mobile platform. Please let me know if any of you can help me out.
Cheers.
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
I think you are obliged to do the skinng stuff yourself on Windows Mobile.
Of course you can still inspire yourself from existing efforts for the Desktop plateform.
(There are lots of articles here, otherwise there is open source lib like beyondata.com or even the MFC FeaturePack source code which features many beatiful skins)
..
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|