Newsgroup: it.comp.programmare.win32
Titolo: WinApi - Cambiare colore al pulsante

 
Devo impostare il colore dei pulsante  in verde e quando viene premuto, 
cambiare in rosso.
 
Come posso fare partendo la codice riportato sotto?
 
Ciao
 
nero23
 
 
 
 
 
 
//  FILE main.c
#include <windows.h>
#include "resource.h"
 
BOOL CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY: PostQuitMessage(0);
return TRUE;
case WM_CLOSE:
DestroyWindow (hwnd);
return TRUE;
}
 
return FALSE;
}
 
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * 
cmdParam, int cmdShow)
{
HWND handle = 0;
handle = CreateDialog (hInst, MAKEINTRESOURCE (IDD_DIALOG1), 0, 
(DLGPROC)DialogProc);
 
if (!handle)
{
MessageBox(NULL, "Dialog Box", "Errore!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
 
ShowWindow(handle, cmdShow);
UpdateWindow(handle);
 
MSG message;
while(GetMessage(&message, NULL, 0, 0) > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}
 
return message.wParam;
}
 
 
 
 
 
 
//  FILE resource.h
#define IDD_DIALOG1 101
#define IDC_BUTTON1 1007
#define IDC_BUTTON2 1008
#define IDC_BUTTON3 1009
 
 
 
//  FILE fileRC.rc
#include "resource.h"
#include "afxres.h"
 
 
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 100, 100
 
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
{ // BEGIN
     PUSHBUTTON "Pulsante 1",IDC_BUTTON1   ,10,10,40,20
     PUSHBUTTON "Pulsante 2",IDC_BUTTON2   ,10,30,40,20
     PUSHBUTTON "Pulsante 3",IDC_BUTTON3   ,10,50,40,20
} //END


 
#include <windows.h>
 
 
  LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  LRESULT CALLBACK ButtonWndProc (HWND, UINT, WPARAM, LPARAM) ;
  LRESULT CALLBACK (*OldButtonWndProc) (HWND, UINT, WPARAM, LPARAM) ;
  HBITMAP HbitmapUp , HbitmapDown;
  HINSTANCE HInstance ;
  HDC hdcmemUp , hdcmemDown ;
  int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     PSTR szCmdLine, int iCmdShow)
{
  static char szAppName[] = "SysMets3" ;
  MSG         msg ;
  WNDCLASSEX  wndclass ;
  HWND hwnd ;
  HInstance = hInstance ;
 
  wndclass.cbSize        = sizeof (wndclass) ;
  wndclass.style         = CS_HREDRAW | CS_VREDRAW|CS_SAVEBITS ;
  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) COLOR_BACKGROUND+1;//GetStockObject 
(BLACK_BRUSH) ;
  wndclass.lpszMenuName  = NULL ;
  wndclass.lpszClassName = szAppName ;
  wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
 
  RegisterClassEx (&wndclass) ;
  HbitmapUp = LoadBitmap(HInstance,MAKEINTRESOURCE(1)) ;
  HbitmapDown = LoadBitmap(HInstance,MAKEINTRESOURCE(2)) ;
 
  hwnd = CreateWindow (szAppName, "Get System Metrics No. 3",
                           WS_OVERLAPPEDWINDOW ,//| WS_VSCROLL | WS_HSCROLL,
                           0,0,600,300,
                           NULL, NULL, hInstance, NULL) ;
 
  ShowWindow (hwnd, SW_SHOWNORMAL) ;
// InvalidateRect(hwnd,NULL,true);
  UpdateWindow (hwnd) ;
 
 
  while (GetMessage (&msg, NULL, 0, 0))
        {
        TranslateMessage (&msg) ;
        DispatchMessage (&msg) ;
        }
   return msg.wParam ;
 
  }
 
  LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM 
lParam)
{
 
  PAINTSTRUCT ps ;
  static HDC hdc;
  static HWND hwndButton ;
  switch (iMsg)
         {
         case WM_CREATE :
         hdc = GetDC(hwnd);
         hdcmemUp = CreateCompatibleDC(hdc) ;
         hdcmemDown = CreateCompatibleDC(hdc) ;
         SelectObject(hdcmemUp,(HGDIOBJ)HbitmapUp);
         SelectObject(hdcmemDown,(HGDIOBJ)HbitmapDown);
         ReleaseDC(hwnd,hdc);
         return 0 ;
         case WM_KEYDOWN :
         hwndButton = CreateWindow ("button", NULL,
                           WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
                           0,0,100,16,
                           hwnd, (HMENU)1, HInstance, NULL) ;
         OldButtonWndProc = (WNDPROC) 
SetWindowLong(hwndButton,GWL_WNDPROC,(LONG)ButtonWndProc) ;
         return 0;
       case WM_PAINT :
       hdc = BeginPaint(hwnd,&ps);
       BitBlt(hdc,0,40,200,100,hdcmemUp,0,0,SRCCOPY);
       EndPaint(hwnd,&ps);
       return 0 ;
 
         case WM_DESTROY :
         DeleteObject((HGDIOBJ)HbitmapUp);
         DeleteObject((HGDIOBJ)HbitmapDown);
         DeleteDC(hdcmemUp);
         DeleteDC(hdcmemDown);
         PostQuitMessage (0) ;
         return 0 ;
        }
 
  return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
 
}
 
  LRESULT CALLBACK ButtonWndProc (HWND hwnd, UINT iMsg, WPARAM wParam, 
LPARAM lParam)
{
  PAINTSTRUCT ps ;
  static HDC hdc;
  static int Up = 1 ;
  switch (iMsg)        {
 
       case WM_LBUTTONDOWN :
       BUTTONDOWN :
       Up = 0 ;
       InvalidateRect(hwnd,NULL,true) ;
       UpdateWindow(hwnd);
       return 0 ;
 
       case WM_LBUTTONUP :
       Up = 1 ;
       InvalidateRect(hwnd,NULL,true) ;
       UpdateWindow(hwnd);
       return 0 ;
 
       case WM_PAINT :
       hdc = BeginPaint(hwnd,&ps);
       if ( Up )  BitBlt(hdc,0,0,100,16,hdcmemUp,0,0,SRCCOPY);
       else   BitBlt(hdc,0,0,100,16,hdcmemDown,0,0,SRCCOPY);
       EndPaint(hwnd,&ps);
       return 0 ;
       case BM_SETSTATE :
       return 0 ;
       case WM_LBUTTONDBLCLK :
       goto BUTTONDOWN ;
//      return 0 ;
       }
  return CallWindowProc (OldButtonWndProc,hwnd, iMsg, wParam, lParam) ;
}
 
 

Mi da errore, anche dopo aver inserito #include "resource.h"
ciao