|
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.
|
|
|
|
|
Please tell him what is not working. Unless one of you two has psychic powers, you need to help him to help you.
Iain.
|
|
|
|
|
I also think so...
|
|
|
|
|
Greets.
You could try handling the WM_CTLCOLOR (or WM_CTLCOLORBTN and/or WM_CTLCOLORSTATIC) messages in the parent window and return a NULL brush. Am not sure that would work, haven't tried it but it's worth a shot.
AtomAnt
- If God wanted man to code, man would have been born without the need to sleep.
|
|
|
|
|
Hi all,
please tell me how can i get Hard Drive Modal details,like Modal Number or Serial Number.
please help me for this.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
|
See here
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
You can use Win32_DiskDrive[^] WMI class. Check Model property.
Sohail
modified on Thursday, November 13, 2008 4:44 AM
modified 21-Apr-21 21:01pm.
|
|
|
|
|