|
See, for instance [^], I know it's Delphi, anyway it is conceptually the same issue.
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]
|
|
|
|
|
verry nice, didn't think of that one
but the problem with this is, that it will only work with a known button, one that's written in the code.
when creating new buttons it wil return just the "button" methode as the sender.
so you know that a button is pushed and not an (ai) editbox or that it was a counter. but wich button you still don know.
|
|
|
|
|
Looks like David Crow has given already the solution [^].
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]
|
|
|
|
|
CPallini wrote: I know it's Delphi...
Why would that be an issue?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Beacuse not all the guys around like Greece.
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]
|
|
|
|
|
I suspect there's a joke in there somewhere, but, alas, it escapes me.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
I know is a silly one [^].
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]
|
|
|
|
|
wielklem wrote: But how do I know which of the ten buttons is clicked now?
In myfunction() , what does Sender represent? If it's the button, then look at its Caption property.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
yes it does.
and with thath it returns the caption
thnx!
|
|
|
|
|
I've never use borlands object library - I used their compiler way back when in my 16bit days (ie, up to 1999), so take this next bit under advisement.
In raw windows (which I bet Builder sits on top of):
A button (or any other control) has an ID, which is set when the button is created (CreateWindow parameter), or later (with ::SetWindowLong(hWnd, GWL_ID, nID) )
When a button is pressed, it sends a WM_COMMAND message, and one of the parameters has the ID number embedded in it.
MFC has message handlers of the form:
ON_COMMAND_RANGE(ID_FIRST, ID_LAST, MemberFunction)
where function is of the form:
void CMyDlg::MemberFunction (UINT nID)
so your function can tell different controls apart.
I bet you'll find that TButton inherits from something like TWnd, which will have a SetDlgCtrlID member function, and it has some sort of message routing table.
Iain.
|
|
|
|
|
Hi all..
I'm creating the window with the help of CreateWindowEx. And i'm making it transparent.. And i'm drawing PNG on that window.. Now i need to repaint it whenever any window is dragged to it. As soon as any of the window dragged on it my WM_PAINT should get called. How do i do that?
Thanks.
|
|
|
|
|
May be you can handle WM_WINDOWPOSCHANGED message?
Regards,
Sandip.
|
|
|
|
|
That will just call when my window changes.. I need to get notify when other window move on to my window.. Hope you're getting my problem.
Thanks.
|
|
|
|
|
In what method are you drawing your png?
|
|
|
|
|
I'm using CxImage to draw PNG.. doing something like that..
HDC hdc = BeginPaint (hWnd , &ps) ;
CxImage* image = new CxImage();
image->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG2),"PNG"),CXIMAGE_FORMAT_PNG);
BOOL iReturn = image->Draw(hdc, 1, 1);
EndPaint (hWnd, &ps) ;
Though i'm able to paint on desktop screen also by taking Desktop DC and passing to Draw but again when any window is dragged on it the PNG get erased...
modified on Friday, November 14, 2008 1:16 AM
|
|
|
|
|
In what method (or function) is that code snippet located?
|
|
|
|
|
|
Well, I created a transparent window using WS_EX_TRANSPARENT. I downloaded the CxImage library from CodeProject. Built the libraries. Added the "us.png" file from the demo as a resource to my project, setup a WM_PAINT handler, dropped in your code snippet to my OnPaint, modified it to use my CPaintDC, verified that my drawing code for the view was being obscurred by the png to demonstrate that the transparent effect was correctly being implemented. I then dragged various windows over it, and scrolled the view so the transparent window fell out of the view client area, etc...
I cannot reproduce your issue. It is invalidated correctly and the WM_PAINT is called and the image is always reproduced (i.e. No eraser effect is observed). There are some occasional remnant areas that don't get invalidated when using WS_POPUP. Are you using WS_POPUP or WS_CHILD?
It does however, flicker because of the drawing sequence inherent in using WS_EX_TRANSPARENT. This was expected as I've never found WS_EX_TRANSPARENT very useful in past attempts at using it (except for mouse pass-through).
I'm not sure how to reproduce your issue without more data. However, since I'm confident that you will probably not like the flicker you'll get once you get it all worked out, I would recommend using WS_EX_LAYERED as it is possible to get some pretty smooth results with almost no flicker. It also has a more versatile mouse pass-through effect and you can always use WS_EX_TRANSPARENT to allow mouse messages to pass through the whole window while using WS_EX_LAYERED.
Anyway, if you can give me more detail on your window creation, I might have better luck at reproducing your issue. Regardless, consider WS_EX_LAYERED instead if you can.
|
|
|
|
|
Well i tried with WX_EX_LAYERED and SetLayeredWindowAttributes with opacity 0. But that makes my whole window transparent including that PNG.. Anyways here's my whole code.. Please take a look..
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include "..\cximage600_full\CxImage\ximage.h"
#include ".\resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HINSTANCE hGlobalInst = NULL;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
hGlobalInst = hInstance;
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
ZeroMemory(&wndclass,sizeof(WNDCLASSEX));
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (NULL_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = "WndProc";
if (!RegisterClassEx (&wndclass))
{
MessageBox (NULL, "Registration Fails","Error", MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_LAYERED,
"WndProc",
NULL, WS_POPUP, 1, 1, 170, 45,
NULL,
NULL,
hInstance,
NULL) ;
if(!hwnd)
{
MessageBox (NULL, "Window Creation Fails","Error", MB_ICONERROR) ;
return 0 ;
}
DWORD eRR1 = GetLastError();
ShowWindow (hwnd, iCmdShow) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.lParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps ;
RECT rect;
GetWindowRect(hWnd, &rect);
switch (message)
{
case WM_PAINT:
{
HDC hdc = GetDC(NULL);
hdc = BeginPaint (NULL, &ps) ;
CxImage* image = new CxImage();
image->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG1),"PNG"),CXIMAGE_FORMAT_PNG);
BOOL iReturn = image->Draw(hdc, 1, 1);
EndPaint (NULL , &ps) ;
break;
}
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
</windows.h>
|
|
|
|
|
May be i'm doing something wrong in CreateWindowEx.. Can you please post your code..
Thanks.
|
|
|
|
|
Hello,
I am working on an mfc application. In it I am using a static control and a checkbox.
I am using a Picture control on top of it i have placed the checkbox and static control.
The problem is that the background of checkbox and static control is not tranparent as a result of which the picture colour and background colours of the controls are not matching..
please help me.
Thanks & regards.
Dhiraj Kumar Saini
|
|
|
|
|
You might want this.
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
{
HDC hdc = (HDC) wParam;
HWND hwndStatic = (HWND) lParam;
HBRUSH hbrBkcolor = (HBRUSH)GetStockObject(NULL_BRUSH);
if (hwndStatic == GetDlgItem(hWnd, IDC_STATIC_CONTROL))
{
SetBkMode(hdc, TRANSPARENT);
return (LRESULT) hbrBkcolor;
}
break;
}
Same stuff do with your Check Box also..
Hope this help.
|
|
|
|
|
I am using MFC and not win32 .
Please help me with MFC code as i dont know win32.
Thanks
|
|
|
|
|
|
Its not working. Please tell me whats the problem.
|
|
|
|
|