Exemplo n.º 1
0
// Our dialogs callback routine
BOOL CALLBACK dialog(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
  	switch(Message)
	{
     // make window layered and set all pixels with an RGB value of 0,0,255 invisible
	  case WM_INITDIALOG:
          {
            if(SetLayeredWindowAttributes != NULL)
            {
              if(i < 1) {
               DestroyCaption(hwnd,bitmapWidth,bitmapHeight);
               i++;
              }

              SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
              SetLayeredWindowAttributes(hwnd, g_ColourKey, 0, LWA_COLORKEY);
            }

            break;
          }

       // move our window
        case WM_LBUTTONDOWN:
           {
            PostMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION,0);
            break;
           }

       // cleanup
        case WM_CLOSE:
           {
		    DeleteObject(hSkinMBmp);
            EndDialog(hwnd, 0);
		    break;
           }

       // draw our bitmap
        case WM_PAINT:
           {
            BITMAP bm;
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            HDC dcSkin = CreateCompatibleDC(hdc);
            GetObject(hSkinMBmp, sizeof(bm), &bm);
            SelectObject(dcSkin, hSkinMBmp);
            BitBlt(hdc, 0,0,bitmapWidth,bitmapHeight, dcSkin, 0, 0, SRCCOPY);
            DeleteDC(dcSkin);
            EndPaint(hwnd, &ps);
            break;
           }

        case WM_COMMAND:
           switch(LOWORD(wParam))
			{
			 // btn commands here
            }
       default:
			return FALSE;
	}
	return TRUE;
}
Exemplo n.º 2
0
// The main window procedure used by the dialog window
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HWND hRunButtonWnd;                      // A handle to the 'Run' button
    static HWND hExitButtonWnd;                     // A handle to the 'Exit' button

    switch(uMsg)                                    // Search through messages sent to this window procedure
    {
    case WM_INITDIALOG:                             // Creating of the dialog window
        if(SetLayeredWindowAttributes != NULL)      // Make sure that this function exits
        {
            if(destroyCaption == false) {           // Make sure that the caption has not already been destroyed
                DestroyCaption(hwndDlg, pDialogSkin->getBitmapWidth(), pDialogSkin->getBitmapHeight());   // Destroy any window caption that may be set
                destroyCaption = true;              // Set a flag to ensure that this has been accomplished
            }

          SetWindowLong(hwndDlg, GWL_EXSTYLE, GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED); // Set the window style
          SetLayeredWindowAttributes(hwndDlg, colorKey, 0, LWA_COLORKEY);                           // Set the transparency color key
        }
        hRunButtonWnd = ::GetDlgItem(hwndDlg,IDRUN);    // Get the window handle for the 'Run' button
        hExitButtonWnd = ::GetDlgItem(hwndDlg,IDEXIT);  // Get the window handle for the 'Exit' button
    return TRUE;

    // draw our bitmap
    case WM_PAINT:                                  // Draw the dialog window
        {
        BITMAP bm;                                  // Create a bitmap structure
        PAINTSTRUCT ps;                             // Create a paint structure
        HDC hdc = BeginPaint(hwndDlg, &ps);         // Create a device context used for the dialog window
        HDC dcSkin = CreateCompatibleDC(hdc);       // Create a compatible memory device context to copy the color information from the bitmap to
        GetObject(pDialogSkin->getBitmapHandle(), sizeof(bm), &bm);      // Fill bitmap structure with information about the background image bitmap
        SelectObject(dcSkin, pDialogSkin->getBitmapHandle());            // Select this bitmap into the memory device context
        BitBlt(hdc, 0,0,pDialogSkin->getBitmapWidth(),pDialogSkin->getBitmapHeight(), dcSkin, 0, 0, SRCCOPY);   // Performs bit-block transfer of bitmap pixels to the memory device context
        DeleteDC(dcSkin);                           // Release the memory device context
        EndPaint(hwndDlg, &ps);                     // End painting of dialog window
        }
    return true;

    case WM_CLOSE:                                  // Exit application
    {
        EndDialog(hwndDlg, 0);                      // Close down the dialog window
    }
    return TRUE;

    case WM_COMMAND:                                // Button has been clicked
    {
        switch (LOWORD (wParam))
        {
            case IDRUN:                             // 'Run' button was clicked
                EndDialog (hwndDlg, 0) ;            // Close the dialog window (or anything else you want to happen)
                return TRUE ;
            case IDEXIT :                           // 'Exit' button was clicked
                EndDialog (hwndDlg, 0) ;            // Close the dialog window because the user is exiting the application
                return TRUE ;
        }
    }
    return TRUE;

    case WM_MOUSEMOVE:                              // Mouse has been moved while over the dialog window area
    {
        if(pRunButton->isMouseOver()){              // Check to see if the mouse was previously over the 'Run' button
            pRunButton->mouseIsOut();               // Set a flag to signify that the mouse is not hovering over the 'Run' button any more

            if(pRunButton->isMouseLeftButtonDown()){// Check to see if the mouse button was previously flagged as down over the 'Run' button
                pRunButton->mouseLeftUp();          // Set a flag to signify that the 'Run' button does not have the left mouse button clicked over it any more

            }
            InvalidateRgn(hRunButtonWnd, NULL, FALSE);  // Redraw the 'Run' button with the default state
        }
        if(pExitButton->isMouseOver()){             // Check to see if the mouse was previously over the 'Exit' button
            pExitButton->mouseIsOut();                 // Set a flag to signify that the mouse is not hovering over the 'Exit' button any more
            if(pExitButton->isMouseLeftButtonDown()){// Check to see if the mouse button was previously flagged as down over the 'Exit' button
                pExitButton->mouseLeftUp();               // Set a flag to signify that the 'Exit' button does not have the left mouse button clicked over it any more

            }
            InvalidateRgn(hExitButtonWnd, NULL, FALSE); // Redraw the 'Exit' button with the default state
        }
    }
    break;

    // Moves the window when the user clicks anywhere not covered by a control. HTCAPTION specifies
    // that all button clicks originate in the title bar area - even when the window has no title bar.
    case WM_LBUTTONDOWN:
    {
        PostMessage(hwndDlg, WM_NCLBUTTONDOWN, HTCAPTION,0);
    }
    return TRUE;

    case WM_LBUTTONUP:                              // The left mouse button was released
    {
        if(pRunButton->isMouseLeftButtonDown()){    // Check to see if the mouse button was previously flagged as down over the 'Run' button
            pRunButton->mouseLeftUp();              // Set a flag to signify that the 'Run' button does not have the left mouse button clicked over it any more
            InvalidateRgn(hRunButtonWnd, NULL, FALSE);  // Redraw the 'Run' button in its default state
        }
        if(pExitButton->isMouseLeftButtonDown()){   // Check to see if the mouse button was previously flagged as down over the 'Exit' button
            pExitButton->mouseLeftUp();                  // Set a flag to signify that the 'Exit' button does not have the left mouse button clicked over it any more
            InvalidateRgn(hExitButtonWnd, NULL, FALSE); // Redraw the 'Exit' button in its default state
        }
    }

    }
    return FALSE;
}