|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Dec 2007
Messaggi: 121
|
[C++]Colorare un singolo Button
sto impazzendo..devo riuscire a colorare un singolo button di una finestra..ho provato con SetSysColors e ho messo KO tutti i colori del sistema
questo è l'ultimo codice che ho provato a scrivere: Codice:
case WM_PAINT: PAINTSTRUCT ps; POINT p; HDC hButLoginDC = BeginPaint(hButtonLogin, &ps); RECT r; SetBkMode(hButLoginDC, OPAQUE); GetClientRect(hButtonLogin, &r); FillRect(hButLoginDC, &r, CreateSolidBrush(RGB(0, 255, 0))); EndPaint(hButtonLogin, &ps); break; |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Mar 2006
Città: Bergamo
Messaggi: 2499
|
ma stai subclassando CButton?
http://cowo.supersized.org/archives/...d-CButton.html
__________________
ho concluso con: kvegeta, doctordb, Leland Gaunt.
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Dec 2007
Messaggi: 121
|
non uso MFC, mi piace complicarmi la vita asd
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Nov 2003
Messaggi: 980
|
Quella roba li la stai facendo nella procedura del pulsante, vero? Lo hai subclassato?
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
|
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Nov 2003
Messaggi: 980
|
Quote:
Comunque, l'importante è quale procedura, se lo fa in quella della finestra che contiene il button, è chiaro che non funziona. |
|
|
|
|
|
|
#7 |
|
Member
Iscritto dal: Dec 2007
Messaggi: 121
|
si è la windowproc della finestra che contiene il button, e uso direttamente le API di windows..sapete come posso fare?
|
|
|
|
|
|
#8 |
|
Member
Iscritto dal: Dec 2007
Messaggi: 121
|
scusate se faccio un piccolo UP ma sono curioso di capire dove sbaglio O.o
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Nov 2003
Messaggi: 980
|
Prova questo:
Codice:
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK ButtonWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WNDPROC originalProc = (WNDPROC)GetProp(hwnd, "OriginalProc");
switch(message)
{
case WM_PAINT:
{
RECT r;
GetClientRect(hwnd, &r);
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &r, CreateSolidBrush(RGB(0, 255, 0)));
char windowText[256];
GetWindowText(hwnd, windowText, 256);
SetBkMode(hdc, TRANSPARENT);
DrawText(hdc, windowText, strlen(windowText), &r, DT_CENTER|DT_VCENTER);
EndPaint(hwnd, &ps);
}
return TRUE;
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
case WM_RBUTTONUP:
{
InvalidateRect(hwnd, NULL, TRUE);
}
break;
case WM_DESTROY:
{
SetWindowLong(hwnd, GWL_WNDPROC, (LONG)originalProc);
RemoveProp(hwnd, "OriginalProc");
}
break;
}
return CallWindowProc(originalProc, hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
HWND button = CreateWindow("BUTTON", "sono colorato!", WS_CHILD|WS_VISIBLE, 10,10,150,25,
hwnd, 0, GetModuleHandle(0), 0);
SetProp(button, "OriginalProc", (HANDLE)GetWindowLong(button, GWL_WNDPROC));
SetWindowLong(button, GWL_WNDPROC, (LONG)ButtonWindowProc);
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:14.











ho concluso con: kvegeta, doctordb, Leland Gaunt.









