LRESULT CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   static SQLHENV henv;
   static SQLHDBC hdbc;
   static SQLHSTMT hstmt;
   static int ifconnect=0;
   static SQLCHAR server[32];
   static char Content[10240] ;
   static RECT rect;
   static PAINTSTRUCT ps;
   static HBRUSH hbrush;	
   static HDC hDC ;
	static RedrawFlag = 0;
	LPDRAWITEMSTRUCT pdis;
	//~ char Content2[10240] ;
	SQLCHAR sqlstr[1024];	
	SQLRETURN retcode;
 
	//~ SQLHENV env;
	char dsn[256];
	char desc[256];
	SQLSMALLINT dsn_ret;
	SQLSMALLINT desc_ret;
	SQLUSMALLINT direction;
	SQLRETURN ret;
	HWND hEditTN = GetDlgItem(hwndDlg, IDC_EDIT1);
	HWND hEdit = GetDlgItem(hwndDlg, IDC_EDIT2);
	HWND hCBox = GetDlgItem(hwndDlg,IDC_COMBO1);
	HWND hBTN1 = GetDlgItem(hwndDlg,IDC_BUTTON1);
	int curSel;
	char szTable[256]; // receives name of item to delete. 
	LPDRAWITEMSTRUCT dItem;
	char text[20];
	int len;
	SIZE sz;

	GetWindowRect(hBTN1,&rect);
	
	switch (uMsg)
	{

	case WM_INITDIALOG:// WM_INITDIALOG message is sent before dialog is displayed
		{
		   // Allocate environment handle
		   retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
		   // Set the ODBC version environment attribute
		   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
			  retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
		   }
		   else {
					MessageBoxPrintf("Prompt","fail to SQLAllocHandle SQL_HANDLE_ENV\n");
					return FALSE;
			}
			
		  direction = SQL_FETCH_FIRST;
		  while(SQL_SUCCEEDED(ret = SQLDataSources(henv, direction,
							   dsn, sizeof(dsn), &dsn_ret,
							   desc, sizeof(desc), &desc_ret))) 
		  {
			direction = SQL_FETCH_NEXT;
			//MessageBoxPrintf("DSN","%s\n",dsn);
			ComboBox_InsertString(hCBox,0,dsn);								   
			if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
		  }
			
			return TRUE;
		}
		break;
	case WM_COMMAND://
		{
			switch (LOWORD(wParam)) 
            { 
                // Process the accelerator and menu commands. 
 
                case ID_ACCELERATOR1: 
				//~ MessageBoxPrintf("hi","hello");
				//~ GetModuleHandle()
				SendMessage(hEdit, EM_SETSEL,(WPARAM)0,(LPARAM) sizeof(Content)/sizeof(char));
			return TRUE;
			}
			
			switch(wParam)
			{
				case IDC_BUTTON1:
				{
					//disconnect
					if (ifconnect) {
						retcode = SQLDisconnect(hdbc);	
					   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
							SetWindowText(GetDlgItem(hwndDlg, IDC_BUTTON1), (LPCTSTR )"Connect");				   
							//~ MessageBoxPrintf("Prompt","Disconnected from %s!\n",server);
							ifconnect = 0;
						InvalidateRect(GetDlgItem(hwndDlg, IDC_BUTTON1),NULL, TRUE);  
						UpdateWindow(GetDlgItem(hwndDlg, IDC_BUTTON1));						   
							return 0;
					   }
					   //~ else
					   //~ {
							//~ MessageBoxPrintf("Prompt","Not Connect yet!\n");						
						//~ }
					}

					  // Allocate connection handle
						 retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
					  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
							 // Set login timeout to 5 seconds					  
							SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0);	
					  }
					  else{
							SQLFreeHandle(SQL_HANDLE_DBC, hdbc);  
							SQLFreeHandle(SQL_HANDLE_ENV, henv);								
							return FALSE;					  
					  }

					// Connect to data source
						if(!ComboBox_GetTextLength(hCBox)){
							MessageBoxPrintf("ERROR","Please Select an Item!");
							return FALSE;
						}
						curSel=ComboBox_GetCurSel(hCBox);
						ComboBox_GetLBText(hCBox,curSel,server);
						retcode = SQLConnect(
						hdbc
						, (SQLCHAR*) server
						, SQL_NTS
						, (SQLCHAR*) NULL
						, 0
						, NULL
						, 0);
					  
					if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
						ifconnect=1;
						SetWindowText(GetDlgItem(hwndDlg, IDC_BUTTON1), (LPCTSTR )"Connected");
						RedrawFlag=1;
						//~ SendMessage(hBTN1, WM_CTLCOLORBTN, (WPARAM)GetWindowDC(hBTN1), (LPARAM)hBTN1);
						//~ SendDlgItemMessage(hwndDlg,IDC_BUTTON1
						//~ ,WM_CTLCOLORBTN,(WPARAM)GetWindowDC(hBTN1), (LPARAM)hBTN1);
						InvalidateRect(GetDlgItem(hwndDlg, IDC_BUTTON1),NULL, TRUE);  
						UpdateWindow(GetDlgItem(hwndDlg, IDC_BUTTON1));
						//~ InvalidateRect(hwndDlg,NULL,TRUE);
						//~ MessageBoxPrintf("Prompt","Connected to %s!\n" ,server);							
					}
					else {
						MessageBoxPrintf("Prompt","Fail to Connect to %s!\n",server);	
						ShowDBStmtError(hwndDlg,hdbc);								
					}
				}
				break;
				
				case IDC_BUTTON3:
				{
					//~ MessageBoxPrintf("INFO","length:%d\n",Edit_GetTextLength(hEdit));
					if(!Edit_GetTextLength(hEditTN)){
						MessageBoxPrintf("Error","[SKM.]TABNAME");
						return FALSE;
					}
					
					ZeroMemory(Content,sizeof(Content)/sizeof(char));
					SetDlgItemText(hwndDlg,IDC_EDIT2,Content);										
					if (!ifconnect) {
						MessageBoxPrintf("Prompt","Not Connect yet!\n");						
						return 0;
					}
					//初始化语句句柄
					retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
					//SQL_NTS telling the function the previous parameter is Null-Terminated String, 
					//please alculate the string length for me
                    if (!GetDlgItemText(hwndDlg, IDC_EDIT1, szTable, sizeof(szTable)/sizeof(SQLCHAR))) 
					{
						*szTable=0;
						MessageBoxPrintf("","%s\n",sqlstr);
					}
					
					// 判断表是否存在
					wsprintf(sqlstr,"select count(0) from syscat.columns where tabname = upper('%s')",szTable);
					retcode = SQLPrepare(hstmt,(SQLCHAR*)sqlstr,SQL_NTS);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					retcode =SQLExecute(hstmt);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					while ( SQLFetch(hstmt) != SQL_NO_DATA_FOUND ){
						SQLINTEGER id=0;
						SQLGetData(hstmt,1,SQL_C_ULONG,&id,sizeof(SQLINTEGER),(SQLINTEGER*)NULL);
						if(0==id){
						MessageBoxPrintf("ERROR","TABLE <%s> does not exists!",szTable);
							return FALSE;
						}
					}
					SQLFreeStmt(hstmt,SQL_CLOSE);

					// do the job
					wsprintf(sqlstr,"select COLNAME from syscat.columns where tabname = upper('%s') ORDER BY COLNO ASC",szTable);
					retcode = SQLPrepare(hstmt,(SQLCHAR*)sqlstr,SQL_NTS);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					retcode =SQLExecute(hstmt);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					while ( SQLFetch(hstmt) != SQL_NO_DATA_FOUND ){
						//~ SQLINTEGER id=0;
						char name[32];
						ZeroMemory(name,sizeof(name)/sizeof(char));
						//~ SQLGetData(hstmt,1,SQL_C_ULONG,&id,sizeof(SQLINTEGER),(SQLINTEGER*)NULL);
						SQLGetData(hstmt,1,SQL_C_CHAR,name,sizeof(name)/sizeof(SQLCHAR),(SQLINTEGER*)NULL);
						//~ MessageBoxPrintf("Result","%s",name);
						strncat(Content,name,32);
						strncat(Content,"\r\n,",32);
					}
					*(Content+strlen(Content)-1)=0;
					//~ strncpy(Content2,Content,strlen(Content)-2);
					SetDlgItemText(hwndDlg,IDC_EDIT2,Content);
					//~ SendMessage(hEdit, EM_LINESCROLL, 0, 80);//WS_VSCROLL
					SQLFreeStmt(hstmt,SQL_CLOSE);
				}				
				default:
					break;
			}
			return TRUE;
		}
		break;
		
	case WM_CTLCOLORBTN:
			//~ hDC = BeginPaint((HWND)wParam, &ps);
			//~ FillRect(hDC, &rect, hbrush);
			//~ EndPaint((HWND)wParam, &ps);		
			//~ if(RedrawFlag){
				//~ hbrush = CreateSolidBrush(RGB(0,255,0));			
				//~ SetTextColor((HDC)wParam,RGB(0,0,0));						
				//~ SetBkColor((HDC)wParam,RGB(0,255,0));
			//~ return (long)hbrush ;
			//~ }
			//~ else 
			//~ {
				//~ SetTextColor((HDC)wParam,RGB(255,0,0));	
				//~ SetBkColor((HDC)wParam,RGB(0,0,0));		
				//~ SetBkMode((HDC)wParam, TRANSPARENT);
				//~ return (long)hbrush ;
			//~ }
	break;
	
	case WM_CLOSE://Massage for terminate/exit (may close button clicked on title bar)
		{
			//Close dialog
			SQLFreeStmt(hstmt,SQL_CLOSE);	
			SQLDisconnect(hdbc);	
			SQLFreeHandle(SQL_HANDLE_DBC, hdbc);  
			SQLFreeHandle(SQL_HANDLE_ENV, henv);					
			//~ EndDialog(hwndDlg,0);
			DestroyWindow(hwndDlg);			
			break;
		}
	case WM_DESTROY:
		{
			PostQuitMessage(0); 
			return TRUE;
		}
	case WM_CTLCOLORDLG: //set its text and background colors using the specified display device context handle.
		{
			break;			
		}
	case WM_PAINT:
		{
			if (RedrawFlag == 1){
				hbrush = CreateSolidBrush(RGB(0,255,0));
				hDC = BeginPaint(hBTN1, &ps);
				FillRect(hDC, &rect, hbrush);
				EndPaint(hBTN1, &ps);
				return (LONG)hbrush;
			}
			break;	
		}
	case WM_DRAWITEM:
	{
				dItem = (DRAWITEMSTRUCT*)lParam;
				if (ifconnect){
				SetBkColor(dItem->hDC, RGB(0,255,0));				
					}
					else
					{
				SetBkColor(dItem->hDC, RGB(255,0,0));						
					}
                //~ SetTextColor(dItem->hDC, RGB(0,0,0xFF));
				memset(text, '\0', 20);

				GetWindowText(dItem->hwndItem, text, 20);
				len=lstrlen(text);

				GetTextExtentPoint32(dItem->hDC, text, len, &sz);

				ExtTextOut( dItem->hDC
							, ((dItem->rcItem.right - dItem->rcItem.left) / 2) + dItem->rcItem.left - (sz.cx / 2)
							, ((dItem->rcItem.bottom - dItem->rcItem.top) / 2) + dItem->rcItem.top - (sz.cy / 2)
							, ETO_OPAQUE | ETO_CLIPPED, &dItem->rcItem, text, len, NULL);

				DrawEdge( dItem->hDC, &dItem->rcItem
						, (dItem->itemState & ODS_SELECTED ? BDR_SUNKENOUTER : BDR_RAISEDOUTER), BF_RECT);
                return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
break;			
		
	}
	case WM_CTLCOLORSTATIC: //可以控制静态控件的颜色
		{
			break;			
		}
	default:
		break;			
	}
	return FALSE;
}
Esempio n. 2
0
//  This function is called by the Windows function DispatchMessage()
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HWND  hwndAddButton, hwndClearButton, hwndOutputText, hwndInputText, hwndCatButton, hwndDogButton, hwndBuyButton ;    //all the handles to different controls
    PAINTSTRUCT ps;
    RECT rect;
    HDC hdc;                                                                                                                     //device context handle
    LRESULT textSize;
    char * message = new char[100];                                                                                              //Text buffer
    char * placeholder = new char[26];
    placeholder = "Type here...";
    HFONT textFont,hFontOld;                                                                                                     //Font handles
	int screenW;                                                                                                                 //characters ave width of string
    int screenH;                                                                                                                 //characters ave height of string                                                                                                                
    HBRUSH color;

    switch(msg)                       // handle the messages 
    {
	case WM_CREATE:

		//Getting information about the average height and width of a letter
		screenW = GetSystemMetrics(SM_CXSCREEN);
        screenH = GetSystemMetrics(SM_CYSCREEN);

		//Getting the dimensions of the window area
		GetClientRect(hwnd, &rect);
            SetWindowPos(
                    hwnd, 0,
                    (screenW - rect.right)/2,
                    (screenH - rect.bottom)/2,
                    0, 0,
					SWP_NOZORDER|SWP_NOSIZE);

			hwndAddButton = CreateWindowEx(
                (DWORD)WS_EX_CLIENTEDGE,
                TEXT("button"),                                                 // The class name required is button
                TEXT("Add"),                                                    // the caption of the button
                WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON,                           // the styles
                480, 100,                                                       // the left and top co-ordinates
                70, 40,                                                         // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_ADD_BUTTON,                                          // the ID of your button
                hInst,                                                          // the instance of your application
                NULL);

			 hwndClearButton = CreateWindowEx(
                (DWORD)WS_EX_CLIENTEDGE,
                TEXT("button"),                                                 // The class name required is button
                TEXT("Clear"),                                                  // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                          // the styles
                480, 150,                                                       // the left and top co-ordinates
                70, 40,                                                         // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_CLEAR_BUTTON,                                        // the ID of your button
                hInst,                                                          // the instance of your application
                NULL);                                                          // extra bits you dont really need

            hwndOutputText = CreateWindowEx(
                (DWORD)NULL,
                TEXT("edit"),                                                   // The class name required is edit
                TEXT(""),                                                       // Default text.
                WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL |
                ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY,                    // Textbox styles
                80, 60,                                                         // the left and top co-ordinates
                390, 150,                                                       // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_OUTPUT_TEXT,                                         // the ID of your editbox
                hInst,                                                          // the instance of your application
                NULL);                                                          // extra bits you dont really need

            hwndInputText = CreateWindowEx(
                (DWORD)NULL,
                TEXT("edit"),                                                   // The class name required is edit
                TEXT(placeholder),                                              // Default text.
                WS_VISIBLE | WS_CHILD | WS_EX_CLIENTEDGE | ES_MULTILINE,        // Textbox styles
                80, 230,                                                        // the left and top co-ordinates
                30, 25,                                                         // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_INPUT_TEXT,                                          // the ID of your editbox
                hInst,                                                          // the instance of your application
                NULL);                                                          // extra bits you dont really need

			 hwndCatButton = CreateWindowEx(
                (DWORD)WS_EX_DLGMODALFRAME,                                                
                TEXT("button"),                                                 // The class name required is button
                TEXT("Cat"),                                                    // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,           // the styles
                20, 70,                                                         // the left and top co-ordinates
                48, 48,                                                         // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_CAT_BUTTON,                                          // the ID of your button
                hInst,                                                          // the instance of your application
                NULL);

            hwndDogButton = CreateWindowEx(
                (DWORD)WS_EX_DLGMODALFRAME,
                TEXT("button"),                                                 // The class name required is button
                TEXT("Dog"),                                                    // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,           // the styles
                20, 130,                                                        // the left and top co-ordinates
                48, 48,                                                         // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_DOG_BUTTON,                                          // the ID of your button
                hInst,                                                          // the instance of your application
                NULL);

			hwndBuyButton = CreateWindowEx(
                (DWORD)WS_EX_DLGMODALFRAME,
                TEXT("button"),                                                 // The class name required is button
                TEXT("Buy"),                                                    // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,           // the styles
                20, 190,                                                        // the left and top co-ordinates
                48, 48,                                                         // width and height
                hwnd,                                                           // parent window handle
                (HMENU)IDC_BUY_BUTTON,                                          // the ID of your button
                hInst,                                                          // the instance of your application
                NULL);
			break;

		 case WM_SIZE:

        //Setting up the display window size
        GetClientRect(hwnd,&rect);
        rect.left  =80;
        rect.top   =60;
        rect.bottom-=80;
        rect.right -=100;

        //Moving the buttons and other windows according to the resize
         MoveWindow(hwndAddButton,rect.right+10,rect.top+30,70,40,FALSE);

         MoveWindow(hwndClearButton,rect.right+10,rect.top+80,70,40,FALSE);

         MoveWindow(hwndOutputText,rect.left+1,1+rect.top,rect.right-rect.left-1,rect.bottom-rect.top-1,FALSE);

	     MoveWindow(hwndInputText,rect.left+1,20+rect.bottom,rect.right-rect.left-2,25,FALSE);

         MoveWindow(hwndCatButton,rect.left-60,rect.top+10,48,48,FALSE);

         MoveWindow(hwndDogButton,rect.left-60,rect.top+70,48,48,FALSE);

	     MoveWindow(hwndBuyButton,rect.left-60,rect.top+130,48,48,FALSE);

            return 0;

		 case WM_GETMINMAXINFO:

        //Setting the minimal size for the window
        MINMAXINFO *ptMinMax;
        ptMinMax=(MINMAXINFO*)lParam;

        ptMinMax->ptMinTrackSize.x=590;
        ptMinMax->ptMinTrackSize.y=330;
        break;

		case WM_COMMAND:

			//Handling button presses
            switch(LOWORD(wParam))
			{
              case IDC_ADD_BUTTON:

				  //sending the message from the edit box to the list box
                    textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message);
                    message[textSize] = _T('\0');

                    if(strlen(message) && strcmp(message, placeholder))
                    {
                        char *item = new char[200];
                        if(items)
							strcpy(item, "\r\n > ");
                        else
							strcpy(item, " > ");         // Managing the new string
                        strcat(item, message);
                        SendMessage(hwndOutputText, EM_REPLACESEL,
                            TRUE, (LPARAM)item);                                     // Appending a new item in the list
                        SendMessage(hwndInputText, WM_SETTEXT, TRUE,(LPARAM)"");     // Clearing the text input
                        delete [] item;                                              // Managing the memory
                        items += 1;                                                  // Incrementing the number of items
                        SendMessage(
                            hwndInputText,
                            WM_SETTEXT,
                            TRUE,
                            (LPARAM)placeholder);                                    // Recovering the placeholder
                        focused = 0;
                    }
                    RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
                    break;

		      case IDC_CLEAR_BUTTON:
                    SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)"");
                    break;

			case IDC_INPUT_TEXT:
                    if(HIWORD(wParam) == EN_SETFOCUS)
                    {
                        textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message);
                        message[textSize] = _T('\0');

                        if(!strcmp(message, placeholder))
                        {
                            SendMessage(hwndInputText, WM_SETTEXT, TRUE,(LPARAM)"");         // Clearing the text input
                            focused = 1;
                            RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
                        }
                    }
                    else if(HIWORD(wParam) == EN_KILLFOCUS)
                    {
                        textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message);
                        message[textSize] = _T('\0');

                        if(!strcmp(message, ""))
                        {
                            SendMessage(
                                hwndInputText,
                                WM_SETTEXT,
                                TRUE,
                                (LPARAM)placeholder);                                         // Recovering the placeholder
                            focused = 0;
                            RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
                        }
                    }
                    break;

            case IDC_CAT_BUTTON:
                    SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)" Domestic cats, no matter their breed, are all members of one species."
                                                                       " Felis catus has had a very long relationship with humans."
                                                                       " Ancient Egyptians may have first domesticated cats as early as 4,000 years ago."
                                                                       " Plentiful rodents probably drew wild felines to human communities."
                                                                       " The cats' skill in killing them may have first earned the affectionate attention of humans."
                                                                       " Early Egyptians worshipped a cat goddess and even mummified their beloved pets for their journey to the next world—accompanied by mummified mice!"
                                                                       " Cultures around the world later adopted cats as their own companions."
                                                                       " Like their wild relatives, domestic cats are natural hunters able to stalk prey and pounce with sharp claws and teeth."
                                                                       " They are particularly effective at night, when their light-reflecting eyes allow them to see better than much of their prey."
                                                                       " Cats also enjoy acute hearing."
                                                                       " All cats are nimble and agile, and their long tails aid their outstanding balance."
                                                                       " Cats communicate by marking trees, fence posts, or furniture with their claws or their waste. "
                                                                       " These scent posts are meant to inform others of a cat's home range."
                                                                       " House cats employ a vocal repertoire that extends from a purr to a screech."
                                                                       " Domestic cats remain largely carnivorous, and have evolved a simple gut appropriate for raw meat."
                                                                       " They also retain the rough tongue that can help them clean every last morsel from an animal bone (and groom themselves)."
                                                                       " Their diets vary with the whims of humans, however, and can be supplemented by the cat's own hunting successes.");

            break;

            case IDC_DOG_BUTTON:

                    SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)" Dogs are one of our most popular domestic pet."
                                                                       " Most people acquire a dog out of choice, so if you make this decision you should think carefully before going ahead."
                                                                       " A dog needs lots of love and care, including regular worming, vaccinations and dental care;"
                                                                       " you will also need to keep an eye out for ticks, fleas and ear mites."
                                                                       " If your new puppy or dog hasn't been neutered you will also need to make arrangements for your pet to be neutered with your vet."
                                                                       " In the unlikely event that your dog goes missing it is going to be very difficult for anyone to know who it belongs to,"
                                                                       " unless your dog carries some form of permanent identification."
                                                                       " It is wise to get your dog microchipped, this will avoid heartache in the long run, should your dog go missing or is stolen."
                                                                       " Dogs love human company and, unlike cats, love constant human contact. "
                                                                       " Don't forget that dogs need somewhere warm to sleep, a constant supply of water, feeding daily, toys to play with and regular exercise."
                                                                       " It can cost up to £80 a month to care for a dog, including food, veterinary care and pet insurance; "
                                                                       " there will be other costs, including buying toys and kennel charges when you go on holiday."
                                                                       " Dogs can live up to 10 years old and longer, over this time your dog will expect lots of care, companionship, time for play and grooming."
                                                                       " Being able to provide all of this will ensure you and your dog make the most of your time together.");




            break;


				case IDC_BUY_BUTTON:
                    if (MessageBox(NULL, TEXT("Which one would you choose to buy? Cat YES?"), TEXT("Buy a Kitten"), MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) == IDYES) {
                        return MessageBox(NULL, TEXT("Great Decision !!!"), TEXT("Congratulations!"), MB_OK | MB_ICONASTERISK);
                    };
                   break;
            }
            break;



	case WM_CTLCOLOREDIT:
            if(GetDlgCtrlID((HWND)lParam) == IDC_INPUT_TEXT)
            {
                hdc = (HDC)wParam;                                              //Get handles
                if(focused)
                {
                    color = CreateSolidBrush(RGB(255, 255, 255));
                    SetTextColor(hdc, RGB(0,0,0));                              // Text color
                    SetBkMode(hdc, TRANSPARENT);                                // EditBox Backround Mode
                    SetBkColor(hdc,(LONG)color);                                // Backround color for EditBox
                }
                else
                {
                    color = CreateSolidBrush(RGB(255, 255, 255));
                    SetTextColor(hdc, RGB(110,123,139));                        // Text color
                    SetBkMode(hdc, TRANSPARENT);                                // EditBox Backround Mode
                    SetBkColor(hdc,(LONG)color);                                // Backround color for EditBox
                }
                return (LONG)color;                                             // Paint it
            }
            break;

	    case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &rect);                                                                        // Getting coordinates of window client area
            SetBkMode(hdc, TRANSPARENT);                                                                       // Set the background to be transparent
            SetTextColor(hdc, RGB(255,231,186));                                                               // Setting the text color to a pale orange
			DrawText(hdc, "\nIANA Bancila", -1, &rect, DT_CENTER | DT_TOP);                                    // Drawing the text on top aligning it to center
            textFont  = CreateFont(0, 0, 0, 0, FW_SEMIBOLD, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");     // Creating the text font to semibold, italic, choosing Times New Roman font
            hFontOld  = (HFONT)SelectObject(hdc,textFont);                                                     // Setting the text font 
            SetTextColor(hdc,RGB(238,173,14));                                                                 // Setting the text color to a dark orange
            SetBkMode(hdc, TRANSPARENT);                                                                       // Set the background to be transparent
            DrawText(hdc, "\n\nLAB1_WindowsProgramming", -1, &rect, DT_CENTER | DT_TOP);                       // Drawing the text on top aligning it to center
            SetTextColor(hdc, RGB(0, 100, 0));                                                                 // Resetting the color to black
			EndPaint(hwnd, &ps);
            break;

        case WM_DRAWITEM:
            if ((UINT)wParam == IDC_DOG_BUTTON) {
                LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam;
                SIZE size;
                char szDogBtnText[5];
                strcpy(szDogBtnText, "Dog");
                GetTextExtentPoint32(lpdis->hDC, szDogBtnText, strlen(szDogBtnText), &size);
                SetTextColor(lpdis->hDC, RGB(245,245,220));
                SetBkColor(lpdis->hDC, RGB(133,99,99));

                ExtTextOut(
                    lpdis->hDC,
                    ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2,
                    ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2,
                    ETO_OPAQUE | ETO_CLIPPED,
                    &lpdis->rcItem,
                    szDogBtnText,
                    strlen(szDogBtnText),
                    NULL);

                DrawEdge(
                    lpdis->hDC,
                    &lpdis->rcItem,
                    (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ),
                    BF_RECT);
                return TRUE;
			}

			else if ((UINT)wParam == IDC_CAT_BUTTON) {
                LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam;
                SIZE size;
                char szCatBtnText[5];
                strcpy(szCatBtnText, "Cat");
                GetTextExtentPoint32(lpdis->hDC, szCatBtnText, strlen(szCatBtnText), &size);
                SetTextColor(lpdis->hDC, RGB(245,245,220));
                SetBkColor(lpdis->hDC, RGB(238,118,33));

                ExtTextOut(
                    lpdis->hDC,
                    ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2,
                    ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2,
                    ETO_OPAQUE | ETO_CLIPPED,
                    &lpdis->rcItem,
                    szCatBtnText,
                    strlen(szCatBtnText),
                    NULL);

                DrawEdge(
                    lpdis->hDC,
                    &lpdis->rcItem,
                    (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ),
                    BF_RECT);

                return TRUE;

			}

			else if ((UINT)wParam == IDC_BUY_BUTTON) {
                LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam;
                SIZE size;
                char szBuyBtnText[5];
                strcpy(szBuyBtnText, "BUY");
                GetTextExtentPoint32(lpdis->hDC, szBuyBtnText, strlen(szBuyBtnText), &size);
                SetTextColor(lpdis->hDC, RGB(245,245,220));
                SetBkColor(lpdis->hDC, RGB(153,204,50));

                ExtTextOut(
                    lpdis->hDC,
                    ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2,
                    ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2,
                    ETO_OPAQUE | ETO_CLIPPED,
                    &lpdis->rcItem,
                    szBuyBtnText,
                    strlen(szBuyBtnText),
                    NULL);

                DrawEdge(
                    lpdis->hDC,
                    &lpdis->rcItem,
                    (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ),
                    BF_RECT);

                return TRUE;

			}

             break;

	case WM_SYSCOMMAND:
            switch(wParam) {

                case SC_MINIMIZE:
                    return MessageBox(NULL, TEXT("STOP! Do not do it!"), TEXT("Minimize Button Clicked!"), MB_OK | MB_ICONSTOP);

                case SC_MAXIMIZE:
                    return MessageBox(NULL, TEXT("Hey! You just clicked Maximize button"), TEXT("Maximize Button Clicked!"), MB_OK | MB_ICONEXCLAMATION);

                case SC_CLOSE:
            if(MessageBox(hwnd, "Are you sure that you want to close this window?", "Lab_1", MB_OKCANCEL) == IDOK)
                DestroyWindow(hwnd);
			break;
                    
                default:
                    return DefWindowProc(hwnd, msg, wParam, lParam);
            }
            break;

	case WM_DESTROY: 

		// User closed the window
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
   }
Esempio n. 3
0
static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
{
	if(hdcPaint) {
		HDC 	hdcMem;
		RECT 	rcClient, rcBp;
		HFONT 	hOldFont = 0;
		int 	xOffset = 0;
		HANDLE	hbp = 0;
		GetClientRect(ctl->hwnd, &rcClient);
#ifndef _USE_D2D
		rcBp = rcClient;
		INIT_PAINT(hdcPaint, rcBp, hdcMem);
#else
		hdcMem = cfg::dat.hdcBg;
		MapWindowPoints(ctl->hwnd, pcli->hwndContactList, reinterpret_cast<POINT *>(&rcClient), 2);
#endif

		hOldFont = reinterpret_cast<HFONT>(SelectObject(hdcMem, ctl->hFont));
		// If its a push button, check to see if it should stay pressed
		if(ctl->pushBtn && ctl->pbState)
			ctl->stateId = PBS_PRESSED;

		// Draw the flat button
		if(ctl->flatBtn) {
			if(ctl->hThemeToolbar && ctl->bThemed) {
				RECT rc = rcClient;
				int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
				Gfx::drawBGFromSurface(ctl->hwnd, rc, hdcMem);
				if(Api::pfnIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
					Api::pfnDrawThemeParentBackground(ctl->hwnd, hdcMem, &rc);
				}
				Api::pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rc, &rc);
			} else {
				HBRUSH hbr;
				RECT rc = rcClient;

				if(ctl->buttonItem) {
					RECT rcParent;
					POINT pt;
					TImageItem *imgItem = ctl->stateId == PBS_HOT ? ctl->buttonItem->imgHover : (ctl->stateId == PBS_PRESSED ? ctl->buttonItem->imgPressed : ctl->buttonItem->imgNormal);
					LONG *glyphMetrics = ctl->stateId == PBS_HOT ? ctl->buttonItem->hoverGlyphMetrics : (ctl->stateId == PBS_PRESSED ? ctl->buttonItem->pressedGlyphMetrics : ctl->buttonItem->normalGlyphMetrics);
#ifndef _USE_D2D
					GetWindowRect(ctl->hwnd, &rcParent);
					pt.x = rcParent.left;
					pt.y = rcParent.top;
					ScreenToClient(pcli->hwndContactList, &pt);
					Gfx::drawBGFromSurface(ctl->hwnd, rc, hdcMem);
#endif
					if(imgItem)
						Gfx::renderSkinItem(hdcMem, &rc, imgItem);
					if(Skin::glyphItem) {
						Api::pfnAlphaBlend(hdcMem, (rc.right - glyphMetrics[2]) / 2, (rc.bottom - glyphMetrics[3]) / 2,
										   glyphMetrics[2], glyphMetrics[3], Skin::glyphItem->hdc,
										   glyphMetrics[0], glyphMetrics[1], glyphMetrics[2],
										   glyphMetrics[3], Skin::glyphItem->bf);
					}
				} else if(ctl->bSkinned) {    // skinned
					RECT rcParent;
					TStatusItem *item;
					int item_id;

					GetWindowRect(ctl->hwnd, &rcParent);

					Gfx::drawBGFromSurface(ctl->hwnd, rc, hdcMem);
					item_id = ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKBUTTONSPRESSED : ID_EXTBKBUTTONSNPRESSED);
					item = &Skin::statusItems[item_id];
					Gfx::setTextColor(item->TEXTCOLOR);
					if(item->IGNORED)
						FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE));
					else {
						rc.top += item->MARGIN_TOP;
						rc.bottom -= item->MARGIN_BOTTOM;
						rc.left += item->MARGIN_LEFT;
						rc.right -= item->MARGIN_RIGHT;
						Gfx::renderSkinItem(hdcMem, &rc, item->imageItem);
					}
				} else {
					if(ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
						hbr = GetSysColorBrush(COLOR_3DFACE);
					else {
						HDC dc;
						HWND hwndParent;

						hwndParent = GetParent(ctl->hwnd);
						dc = GetDC(hwndParent);
						hbr = (HBRUSH) SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM) dc, (LPARAM) hwndParent);
						ReleaseDC(hwndParent, dc);
					}
					if(hbr) {
						FillRect(hdcMem, &rc, hbr);
						DeleteObject(hbr);
					}
				}
				if(!ctl->bSkinned && ctl->buttonItem == 0) {
					if(ctl->stateId == PBS_HOT || ctl->focus) {
						if(ctl->pbState)
							DrawEdge(hdcMem, &rc, EDGE_ETCHED, BF_RECT | BF_SOFT);
						else
							DrawEdge(hdcMem, &rc, BDR_RAISEDOUTER, BF_RECT | BF_SOFT);
					} else if(ctl->stateId == PBS_PRESSED)
						DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
				}
			}
		} else {
			// Draw background/border
			if(ctl->hThemeButton && ctl->bThemed) {
				int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
				POINT pt;
				RECT rcParent;

				GetWindowRect(ctl->hwnd, &rcParent);
				pt.x = rcParent.left;
				pt.y = rcParent.top;
				ScreenToClient(pcli->hwndContactList, &pt);
				BitBlt(hdcMem, 0, 0, rcClient.right, rcClient.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);

				if(Api::pfnIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
					Api::pfnDrawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
				}
				Api::pfnDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
			} else {
				UINT uState = DFCS_BUTTONPUSH | ((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0) | ((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
				if(ctl->defbutton && ctl->stateId == PBS_NORMAL)
					uState |= DLGC_DEFPUSHBUTTON;
				DrawFrameControl(hdcMem, &rcClient, DFC_BUTTON, uState);
			}

			// Draw focus rectangle if button has focus
			if(ctl->focus) {
				RECT focusRect = rcClient;
				InflateRect(&focusRect, -3, -3);
				DrawFocusRect(hdcMem, &focusRect);
			}
		}

		// If we have an icon or a bitmap, ignore text and only draw the image on the button
		if(ctl->hIcon || ctl->hIconPrivate || ctl->iIcon) {
			int ix = (rcClient.right - rcClient.left) / 2 - (CXSMICON / 2);
			int iy = (rcClient.bottom - rcClient.top) / 2 - (CXSMICON / 2);
			HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
			if(lstrlen(ctl->szText) == 0) {
				if(ctl->iIcon)
					ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, CXSMICON, CYSMICON, CLR_NONE, CLR_NONE, ILD_NORMAL);
				else
					DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, CXSMICON, CYSMICON, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
				ctl->sLabel.cx = ctl->sLabel.cy = 0;
			} else {
				GetTextExtentPoint32(hdcMem, ctl->szText, lstrlen(ctl->szText), &ctl->sLabel);

				if(CXSMICON + ctl->sLabel.cx + 8 > rcClient.right - rcClient.left)
					ctl->sLabel.cx = (rcClient.right - rcClient.left) - CXSMICON - 8;
				else
					ctl->sLabel.cx += 4;

				ix = (rcClient.right - rcClient.left) / 2 - ((CXSMICON + ctl->sLabel.cx) / 2);
				if(ctl->iIcon)
					ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, CXSMICON, CYSMICON, CLR_NONE, CLR_NONE, ILD_NORMAL);
				else
					DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, CXSMICON, CYSMICON, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
				xOffset = ix + CXSMICON + 4;
			}
		} else if(ctl->hBitmap) {
			BITMAP bminfo;
			int ix, iy;

			GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
			ix = (rcClient.right - rcClient.left) / 2 - (bminfo.bmWidth / 2);
			iy = (rcClient.bottom - rcClient.top) / 2 - (bminfo.bmHeight / 2);
			if(ctl->stateId == PBS_PRESSED) {
				ix++;
				iy++;
			}
			DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->hBitmap, 0, ix, iy, bminfo.bmWidth, bminfo.bmHeight, IsWindowEnabled(ctl->hwnd) ? DST_BITMAP : DST_BITMAP | DSS_DISABLED);
		}
		if(GetWindowTextLength(ctl->hwnd)) {
			// Draw the text and optinally the arrow
			RECT rcText;

			CopyRect(&rcText, &rcClient);
			SetBkMode(hdcMem, TRANSPARENT);
			if(!ctl->bSkinned)
				Gfx::setTextColor(IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
			if(ctl->arrow) {
				DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->arrow, 0, rcClient.right - rcClient.left - 5 - CXSMICON + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - CYSMICON / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), CXSMICON, CYSMICON, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
				rcText.left += (4 + CXSMICON);
			}
			if(xOffset)
				rcText.left += (4 + CXSMICON);
			Gfx::renderText(hdcMem, ctl->hThemeButton, ctl->szText, &rcText, DT_VCENTER | DT_CENTER | DT_SINGLELINE, 0);
		}
		if(hOldFont)
			SelectObject(hdcMem, hOldFont);
#ifndef _USE_D2D
		FINALIZE_PAINT(hbp, &rcBp, 0);
#endif
	}
}
Esempio n. 4
0
void FaceRender::DrawMore(HDC hdc, double sx, double sy) {
    for (std::map<pxcUID,FaceData>::iterator itr2=m_faces.begin(); itr2!=m_faces.end(); itr2++) {
        FaceData& itr=itr2->second;

        // draw face rectangle
        if (itr.location.w>0 && itr.location.h>0) {
            RECT rect= { (LONG)(itr.location.x*sx), (LONG)(itr.location.y*sy), (LONG)((itr.location.w+itr.location.x)*sx), (LONG)((itr.location.h+itr.location.y)*sy) };
            DrawEdge(hdc, &rect, EDGE_RAISED, BF_TOP|BF_RIGHT|BF_LEFT|BF_BOTTOM);
        }

        // draw landmark points
        for (int i=0; i<7; i++) {
            if (itr.landmark[i].x<0 || itr.landmark[i].y<0) continue;
            int x=(int)(itr.landmark[i].x*sx);
            int y=(int)(itr.landmark[i].y*sy);
            int rx=(int)(5*sx);
            int ry=(int)(5*sy);
            Ellipse(hdc,x-rx,y-ry,x+rx,y+ry);
        }

        // draw name or fid
        if (itr.location.w>0 && itr.location.h>0) {
            int x=(int)(itr.location.x*sx);
            int y=(int)((itr.location.y+itr.location.h)*sy-TEXT_HEIGHT*5);
            if (itr.name[0]) {
                TextOut(hdc, x, y, itr.name, (int)_tcslen(itr.name));
            } else {
                TCHAR idstring[32];
                _stprintf_s(idstring,32,TEXT("%d"),itr2->first);
                TextOut(hdc, x, y, idstring, (int)_tcslen(idstring));
            }
        }

        // draw age group
        for (int j=0; j<sizeof(itr.agegroup)/sizeof(itr.agegroup[0]); j++) {
            static pxcCHAR *labels[]= { TEXT("baby"), TEXT("toddler"), TEXT("youth"), TEXT("adult"), TEXT("senior") };
            if (!itr.agegroup[j]) continue;
            int x=(int)(itr.location.x*sx);
            int y=(int)((itr.location.y+itr.location.h)*sy-TEXT_HEIGHT*4);
            TextOut(hdc, x, y, labels[j], (int)_tcslen(labels[j]));
        }

        // draw gender
        if (itr.gender[0] || itr.gender[1]) {
            pxcCHAR *label=itr.gender[0]?TEXT("male"):TEXT("female");
            int x=(int)(itr.location.x*sx);
            int y=(int)((itr.location.y+itr.location.h)*sy-TEXT_HEIGHT*3);
            TextOut(hdc, x, y, label, (int)_tcslen(label));
        }

        // draw emotion
        if (itr.emotion[0]) {
            pxcCHAR *label=TEXT("smile");
            int x=(int)(itr.location.x*sx);
            int y=(int)((itr.location.y+itr.location.h)*sy-TEXT_HEIGHT*2);
            TextOut(hdc, x, y, label, (int)_tcslen(label));
        }

        // draw eye-closed
        if (itr.eyeclosed[0] || itr.eyeclosed[1]) {
            pxcCHAR *label=0;
            if (itr.eyeclosed[0] && itr.eyeclosed[1]) label=TEXT("both-eyes closed");
            if (itr.eyeclosed[0] && !itr.eyeclosed[1]) label=TEXT("left-eye closed");
            if (!itr.eyeclosed[0] && itr.eyeclosed[1]) label=TEXT("right-eye closed");
            int x=(int)(itr.location.x*sx);
            int y=(int)((itr.location.y+itr.location.h)*sy-TEXT_HEIGHT);
            if (label) TextOut(hdc, x, y, label, (int)_tcslen(label));
        }
    }
}
void EdgeActor::TickLocal(const dtGame::Message &tickMessage)
{
    DrawEdge();
}
Esempio n. 6
0
LRESULT CALLBACK EventAreaWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_CREATE:
		hwndEventFrame = hwnd;
		return FALSE;

	case WM_MEASUREITEM:
		{
			MEASUREITEMSTRUCT *lpi = (LPMEASUREITEMSTRUCT)lParam;
			MENUITEMINFOA mii = { 0 };

			mii.cbSize = sizeof(mii);
			mii.fMask = MIIM_DATA | MIIM_ID;
			if (GetMenuItemInfoA(cfg::dat.hMenuNotify, lpi->itemID, FALSE, &mii) != 0) {
				if (mii.dwItemData == lpi->itemData) {
					lpi->itemWidth = 8 + 16;
					lpi->itemHeight = 0;
					return TRUE;
				}
			}
			break;
		}
	case WM_NCCALCSIZE:
		return FrameNCCalcSize(hwnd, DefWindowProc, wParam, lParam,
			wndFrameEventArea ? wndFrameEventArea->TitleBar.ShowTitleBar : 0);
	case WM_NCPAINT:
		return FrameNCPaint(hwnd, DefWindowProc, wParam, lParam,
			wndFrameEventArea ? wndFrameEventArea->TitleBar.ShowTitleBar : 0);
	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;

			if (dis->hwndItem == (HWND)cfg::dat.hMenuNotify) {
				MENUITEMINFOA mii = { 0 };

				struct NotifyMenuItemExData *nmi = 0;
				int iIcon;
				HICON hIcon;

				mii.cbSize = sizeof(mii);
				mii.fMask = MIIM_DATA;
				if (GetMenuItemInfoA(cfg::dat.hMenuNotify, (UINT)dis->itemID, FALSE, &mii) != 0) {
					nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
					if (nmi) {
						iIcon = pcli->pfnGetContactIcon(nmi->hContact);
						hIcon = ImageList_GetIcon(hCListImages, iIcon, ILD_NORMAL);
						pcli->pfnDrawMenuItem(dis, hIcon, nmi->hIcon);
						return TRUE;
					}
				}
			}
			break;
		}
	case WM_LBUTTONUP:
		if (cfg::dat.bEventAreaEnabled)
			SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_NOTIFYBUTTON, 0), 0);
		break;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDC_NOTIFYBUTTON) {
			int iSelection;
			struct NotifyMenuItemExData *nmi = 0;
			int iCount = GetMenuItemCount(cfg::dat.hMenuNotify);

			POINT pt;
			GetCursorPos(&pt);

			MENUITEMINFO mii = { 0 };
			mii.cbSize = sizeof(mii);
			mii.fMask = MIIM_DATA;
			if (iCount > 1)
				iSelection = TrackPopupMenu(cfg::dat.hMenuNotify, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
			else
				iSelection = GetMenuItemID(cfg::dat.hMenuNotify, 0);
			
			BOOL result = GetMenuItemInfo(cfg::dat.hMenuNotify, (UINT)iSelection, FALSE, &mii);
			if (result != 0) {
				nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
				if (nmi) {
					CLISTEVENT *cle = MyGetEvent(iSelection);
					if (cle) {
						CLISTEVENT *cle1 = NULL;
						CallService(cle->pszService, (WPARAM)NULL, (LPARAM)cle);
						// re-obtain the pointer, it may already be invalid/point to another event if the
						// event we're interested in was removed by the service (nasty one...)
						cle1 = MyGetEvent(iSelection);
						if (cle1 != NULL)
							CallService(MS_CLIST_REMOVEEVENT, (WPARAM)cle->hContact, (LPARAM)cle->hDbEvent);
					}
				}
			}
		}
		break;

	case WM_ERASEBKGND:
		return TRUE;

	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hwnd, &ps);

			RECT rc, rcClient;
			GetClientRect(hwnd, &rc);
			rcClient = rc;

			HDC hdcMem = CreateCompatibleDC(hdc);
			HBITMAP hbm = CreateCompatibleBitmap(hdc, rc.right, rc.bottom);
			HBITMAP hbmold = reinterpret_cast<HBITMAP>(SelectObject(hdcMem, hbm));
			SetBkMode(hdcMem, TRANSPARENT);

			HFONT hFontOld = 0;
			if (cfg::clcdat) {
				int height;
				hFontOld = ChangeToFont(hdcMem, cfg::clcdat, FONTID_EVENTAREA, &height);
			}

			if (cfg::dat.bWallpaperMode)
				SkinDrawBg(hwnd, hdcMem);

			StatusItems_t *item = arStatusItems[ID_EXTBKEVTAREA - ID_STATUS_OFFLINE];
			if (item->IGNORED)
				FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE));
			else {
				rc.top += item->MARGIN_TOP; rc.bottom -= item->MARGIN_BOTTOM;
				rc.left += item->MARGIN_LEFT; rc.right -= item->MARGIN_RIGHT;

				DrawAlpha(hdcMem, &rc, item->COLOR, item->ALPHA, item->COLOR2, item->COLOR2_TRANSPARENT,
					item->GRADIENT, item->CORNER, item->BORDERSTYLE, item->imageItem);
				SetTextColor(hdcMem, item->TEXTCOLOR);
			}

			LONG dwLeft = rc.left;

			PaintNotifyArea(hdcMem, &rc);
			if (cfg::dat.dwFlags & CLUI_FRAME_EVENTAREASUNKEN) {
				rc.left = dwLeft;
				InflateRect(&rc, -2, -2);
				DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT);
			}
			BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcMem, 0, 0, SRCCOPY);
			SelectObject(hdcMem, hbmold);
			if (hFontOld)
				SelectObject(hdcMem, hFontOld);
			DeleteObject(hbm);
			DeleteDC(hdcMem);
			ps.fErase = FALSE;
			EndPaint(hwnd, &ps);
		}
		return 0;

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return TRUE;
}
Esempio n. 7
0
static void
button_paint_split(HWND win, button_t* button, HDC dc)
{
    RECT rect;
    RECT rect_left, rect_right;
    int state_left, state_right;
    int text_offset = 0;
    HFONT font, old_font;
    int old_bk_mode;
    COLORREF old_text_color;
    HRGN old_clip;
    HICON glyph;
    int width_right = DROPDOWN_W;

    glyph = ImageList_GetIcon(mc_bmp_glyphs, MC_BMP_GLYPH_MORE_OPTIONS, ILD_TRANSPARENT);
    GetClientRect(win, &rect);

    font = (HFONT) MC_SEND(win, WM_GETFONT, 0, 0);
    if(font == NULL)
        font = GetStockObject(SYSTEM_FONT);

    old_font = SelectObject(dc, font);
    old_bk_mode = GetBkMode(dc);
    old_text_color = GetTextColor(dc);
    old_clip = get_clip(dc);

    /* Draw what's common for left and right parts background. */
    if(!button->theme  &&  (button->style & BS_DEFPUSHBUTTON)) {
        SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
        Rectangle(dc, rect.left, rect.top, rect.right, rect.bottom);
        mc_rect_inflate(&rect, -1, -1);
        width_right--;
    }

    /* Setup subrectangles (mainpart 1 and push-down part 2) */
    mc_rect_copy(&rect_left, &rect);
    rect_left.right -= width_right;
    mc_rect_copy(&rect_right, &rect);
    rect_right.left = rect_left.right;

    /* Draw background. */
    if(button->theme) {
        UINT transparent;
        RECT tmp;

        /* Determine styles for left and right parts */
        if(button->style & WS_DISABLED) {
            state_left = state_right = PBS_DISABLED;
        } else {
            LRESULT state;

            state = MC_SEND(win, BM_GETSTATE, 0, 0);
            if(state & MC_BST_DROPDOWNPUSHED) {
                state_left = PBS_NORMAL;
                state_right = PBS_PRESSED;
            } else {
                if(state & BST_PUSHED)
                    state_left = state_right = PBS_PRESSED;
                else if(state & BST_HOT)
                    state_left = state_right = PBS_HOT;
                else if(button->style & BS_DEFPUSHBUTTON)
                    state_left = state_right = PBS_DEFAULTED;
                else
                    state_left = state_right = PBS_NORMAL;
            }
        }

        /* Handle (semi-)transparent themes. */
        transparent = 0;
        if(mcIsThemeBackgroundPartiallyTransparent(button->theme,
                    BP_PUSHBUTTON, state_left))
            transparent |= 0x1;
        if(mcIsThemeBackgroundPartiallyTransparent(button->theme,
                    BP_PUSHBUTTON, state_right))
            transparent |= 0x2;
        switch(transparent) {
            case 0x1:
                mcDrawThemeParentBackground(win, dc, &rect_left);
                break;
            case 0x2:
                mcDrawThemeParentBackground(win, dc, &rect_right);
                break;
            case 0x3:
                mcDrawThemeParentBackground(win, dc, &rect);
                break;
        }

        /* Draw backgrond. */
        mcDrawThemeBackground(button->theme, dc, BP_PUSHBUTTON, state_left, &rect, &rect_left);
        mcDrawThemeBackground(button->theme, dc, BP_PUSHBUTTON, state_right, &rect, &rect_right);

        /* Deflate both rects to content rects only */
        mcGetThemeBackgroundContentRect(button->theme, dc, BP_PUSHBUTTON, state_left, &rect_left, &tmp);
        rect_left.left = tmp.left;
        rect_left.top = tmp.top;
        rect_left.bottom = tmp.bottom;
        mcGetThemeBackgroundContentRect(button->theme, dc, BP_PUSHBUTTON, state_right, &rect_right, &tmp);
        rect_right.top = tmp.top;
        rect_right.right = tmp.right;
        rect_right.bottom = tmp.bottom;

        /* Draw delimiter of left and right parts. */
        rect_right.top += 1;
        rect_right.bottom -= 1;
        mcDrawThemeEdge(button->theme, dc, BP_PUSHBUTTON, state_right, &rect_right, BDR_SUNKEN, BF_LEFT, NULL);
        rect_right.left = tmp.left;
    } else {
        /* Determine styles for left and right parts */
        if(button->style & WS_DISABLED) {
            state_left = state_right = DFCS_INACTIVE;
        } else {
            LRESULT s = MC_SEND(win, BM_GETSTATE, 0, 0);
            if(s & MC_BST_DROPDOWNPUSHED) {
                state_left = 0;
                state_right = DFCS_PUSHED;
            } else {
                if(s & BST_PUSHED) {
                    state_left = state_right = DFCS_PUSHED;
                } else {
                    state_left = state_right = 0;
                }
            }
        }

        button_send_ctlcolorbtn(win, dc);

        /* Draw control edges */
        IntersectClipRect(dc, rect_left.left, rect_left.top, rect_left.right, rect_left.bottom);
        DrawFrameControl(dc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | state_left);
        SelectClipRgn(dc, NULL);
        IntersectClipRect(dc, rect_right.left, rect_right.top, rect_right.right, rect_right.bottom);
        DrawFrameControl(dc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | state_right);

        /* Parts which are pushed, should have the contents moved a bit */
        if(state_left == DFCS_PUSHED)
            mc_rect_offset(&rect_left, 1, 1);
        if(state_right == DFCS_PUSHED)
            mc_rect_offset(&rect_right, 1, 1);

        /* Draw delimiter */
        if(state_left == state_right) {
            DrawEdge(dc, &rect_right, BDR_SUNKENOUTER | BDR_RAISEDINNER, BF_LEFT | BF_SOFT);
        } else {
            rect_right.left--;
            DrawEdge(dc, &rect_right, BDR_SUNKENOUTER, BF_LEFT | BF_SOFT);
            rect_right.left++;
        }

        /* Adjust for the outer control edges */
        mc_rect_inflate(&rect_left, 0, -2);
        rect_left.left += 2;
        mc_rect_inflate(&rect_right, -2, -2);
    }

    /* Draw focus rectangle. */
    if((MC_SEND(win, BM_GETSTATE, 0, 0) & BST_FOCUS) && !button->hide_focus) {
        SelectClipRgn(dc, NULL);
        if(button->theme) {
            mc_rect_set(&rect, rect_left.left, rect_left.top,
                        rect_right.right - DROPDOWN_W, rect_right.bottom);
            DrawFocusRect(dc, &rect);
        } else {
            mc_rect_inflate(&rect_left, -1, -2);
            DrawFocusRect(dc, &rect_left);
            mc_rect_inflate(&rect_left, -1, -1);
        }
    }

    /* Draw glyph into the right part */
    SelectClipRgn(dc, NULL);
    IntersectClipRect(dc, rect_right.left, rect_right.top,
                          rect_right.right, rect_right.bottom);
    DrawIconEx(dc, (rect_right.right + rect_right.left - MC_BMP_GLYPH_W) / 2,
                   (rect_right.bottom + rect_right.top - MC_BMP_GLYPH_H) / 2,
                   glyph, MC_BMP_GLYPH_W, MC_BMP_GLYPH_H, 0, NULL, DI_NORMAL);

    /* Draw left part contents */
    SelectClipRgn(dc, NULL);
    IntersectClipRect(dc, rect_left.left, rect_left.top,
                          rect_left.right, rect_left.bottom);
    if(button->style & BS_ICON) {
        /* Paint (BS_SPLITBUTTON | BS_ICON). Note that this is used even on
         * Vista, as according to some my testing this style combination
         * is not supported there... */
        HICON icon;

        icon = (HICON) MC_SEND(win, BM_GETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) 0);
        if(icon != NULL) {
            SIZE size;
            UINT flags;

            mc_icon_size(icon, &size);

            flags = DST_ICON;
            if(button->style & WS_DISABLED)
                flags |= DSS_DISABLED;

            DrawState(dc, NULL, NULL, (LPARAM) icon, 0,
                      (rect_left.right + rect_left.left - size.cx) / 2,
                      (rect_left.bottom + rect_left.top - size.cy) / 2,
                      size.cx, size.cy, flags);
        }
    } else {
        /* Paint text label */
        TCHAR buffer[256];
        int n;
        UINT flags = 0;

        /* Setup flags for TextOut/mcDrawThemeText */
        switch(button->style & (BS_LEFT | BS_CENTER | BS_RIGHT)) {
            case BS_LEFT:
                flags |= DT_LEFT;
                break;
            case BS_RIGHT:
                flags |= DT_RIGHT;
                break;
            default:
                if(GetWindowLong(win, GWL_EXSTYLE) & WS_EX_RIGHT)
                    flags |= DT_RIGHT;
                else
                    flags |= DT_CENTER;
                break;
        }
        switch(button->style & (BS_TOP | BS_VCENTER | BS_BOTTOM)) {
            case BS_TOP:
                flags |= DT_TOP;
                break;
            case BS_BOTTOM:
                flags |= DT_BOTTOM;
                break;
            default:
                flags |= DT_VCENTER;
                break;
        }
        if(button->style & BS_MULTILINE)
            flags |= DT_WORDBREAK;
        else
            flags |= DT_SINGLELINE;

        if(button->hide_accel)
            flags |= DT_HIDEPREFIX;

        n = MC_SEND(win, WM_GETTEXT, MC_SIZEOF_ARRAY(buffer), buffer);

        if(button->theme) {
            mcDrawThemeText(button->theme, dc, BP_PUSHBUTTON,
                        state_left, buffer, n, flags, 0, &rect_left);
        } else {
            SetBkMode(dc, TRANSPARENT);
            SetTextColor(dc, GetSysColor(COLOR_BTNTEXT));
            mc_rect_offset(&rect_left, text_offset, text_offset);
            DrawText(dc, buffer, n, &rect_left, flags);
        }
    }

    SelectObject(dc, old_font);
    SetBkMode(dc, old_bk_mode);
    SetTextColor(dc, old_text_color);
    SelectObject(dc, old_clip);
}
Esempio n. 8
0
//  This function is called by the Windows function DispatchMessage()
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) //all the handles to different controls
{
    static HWND hwndInputText,hwndInputText2;
    static HWND hwndOutputText,hwndOutputText2;
    LRESULT textSize;
    char * message = new char[100];
    char * placeholder = new char[26];
    placeholder = "Please enter your name...";
    HBRUSH color;
    int iScreenW;                                //characters ave width of string
    int iScreenH;                                //characters ave height of string
    PAINTSTRUCT ps;
    RECT rect;
    HDC hdc;                                     //device context handle

    switch(msg) // handle the messages
    {

        case WM_CREATE:
            //Getting information about the average height and width of a letter
            iScreenW = GetSystemMetrics(SM_CXSCREEN);
            iScreenH = GetSystemMetrics(SM_CYSCREEN);

            //Getting the dimensions of the client area
            GetWindowRect(hwnd, &rect);
            SetWindowPos(
                hwnd, 0,
                (iScreenW - rect.right)/2,
                (iScreenH - rect.bottom)/2,
                0, 0,
                SWP_NOZORDER|SWP_NOSIZE);

            CreateWindowEx(
               (DWORD)NULL,
                TEXT("button"),                                       // The class name required is button
                TEXT("Add"),                                          // the caption of the button
                WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON,                 // the styles
                35, 270,                                              // the left and top co-ordinates
                60, 20,                                               // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_ADD_BUTTON,                                // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            CreateWindowEx(
               (DWORD)NULL,
                TEXT("button"),                                       // The class name required is button
                TEXT("Add"),                                          // the caption of the button
                WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON,                 // the styles
                265, 270,                                             // the left and top co-ordinates
                60, 20,                                               // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_ADD_BUTTON2,                               // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            CreateWindowEx(
                (DWORD)NULL,
                TEXT("button"),                                       // The class name required is button
                TEXT("Reset"),                                        // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                // the styles
                135, 270,                                             // the left and top co-ordinates
                60, 20,                                               // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_RESET_BUTTON,                              // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            CreateWindowEx(
                (DWORD)NULL,
                TEXT("button"),                                       // The class name required is button
                TEXT("Reset"),                                        // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                // the styles
                365, 270,                                             // the left and top co-ordinates
                60, 20,                                               // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_RESET_BUTTON2,                             // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            CreateWindowEx(
                (DWORD)NULL,
                TEXT("button"),                                       // The class name required is button
                TEXT("Red pill"),                                     // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, // the styles
                75, 35,                                               // the left and top co-ordinates
                80, 35,                                               // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_RED_BUTTON,                                // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            CreateWindowEx(
                (DWORD)NULL,
                TEXT("button"),                                       // The class name required is button
                TEXT("Blue pill"),                                    // the caption of the button
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, // the styles
                315, 35,                                              // the left and top co-ordinates
                80, 35,                                               // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_BLUE_BUTTON,                               // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            hwndOutputText = CreateWindowEx(
                (DWORD)NULL,                                          // The class name required is edit
                TEXT("edit"),                                         // the caption of the button
                TEXT(""),                                             // Default text.
                WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL |      // Textbox styles
                ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY,
                20, 80,                                               // the left and top co-ordinates
                200, 150,                                             // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_OUTPUT_TEXT,                               // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            hwndInputText = CreateWindowEx(
                 (DWORD)NULL,
                TEXT("edit"),                                         // The class name required is edit
                TEXT(placeholder),                                    // Default text.
                WS_VISIBLE | WS_CHILD | WS_BORDER,                    // Textbox styles
                20, 235,                                              // the left and top co-ordinates
                200, 20,                                              // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_INPUT_TEXT,                                // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            hwndOutputText2 = CreateWindowEx(
                (DWORD)NULL,                                          // The class name required is edit
                TEXT("edit"),                                         // the caption of the button
                TEXT(""),                                             // Default text.
                WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL |      // Textbox styles
                ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY,
                250, 80,                                              // the left and top co-ordinates
                200, 150,                                             // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_OUTPUT_TEXT2,                              // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);

            hwndInputText2 = CreateWindowEx(
                 (DWORD)NULL,
                TEXT("edit"),                                         // The class name required is edit
                TEXT(placeholder),                                    // Default text.
                WS_VISIBLE | WS_CHILD | WS_BORDER,                    // Textbox styles
                250, 235,                                             // the left and top co-ordinates
                200, 20,                                              // width and height
                hwnd,                                                 // parent window handle
                (HMENU)IDC_INPUT_TEXT2,                               // the ID of your button
                hProgramInstance,                                     // the instance of your application
                NULL);
            break;

       case WM_COMMAND:
            //Handling button presses
            switch(LOWORD(wParam)) {
                case IDC_INPUT_TEXT:
                    if(HIWORD(wParam) == EN_SETFOCUS)
                    {
                        textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message);
                        message[textSize] = _T('\0');

                        if(!strcmp(message, placeholder))
                        {
                            SendMessage(hwndInputText, WM_SETTEXT, TRUE,(LPARAM)"");     // Reseting the text input
                            focused = 1;
                            RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
                        }
                    }
                    else if(HIWORD(wParam) == EN_KILLFOCUS)
                    {
                        textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message);
                        message[textSize] = _T('\0');

                        if(!strcmp(message, ""))
                        {
                            SendMessage(
                                hwndInputText,
                                WM_SETTEXT,
                                TRUE,
                                (LPARAM)placeholder);                                   // Recovering the placeholder
                            focused = 0;
                            RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
                        }
                    }
                    break;

                case IDC_INPUT_TEXT2:
                    if(HIWORD(wParam) == EN_SETFOCUS)
                    {
                        textSize = SendMessage(hwndInputText2, WM_GETTEXT, 100, (LPARAM)message);
                        message[textSize] = _T('\0');

                        if(!strcmp(message, placeholder))
                        {
                            SendMessage(hwndInputText2, WM_SETTEXT, TRUE,(LPARAM)"");     // Reseting the text input
                            focused2 = 1;
                            RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
                        }
                    }
                    else if(HIWORD(wParam) == EN_KILLFOCUS)
                    {
                        textSize = SendMessage(hwndInputText2, WM_GETTEXT, 100, (LPARAM)message);
                        message[textSize] = _T('\0');

                        if(!strcmp(message, ""))
                        {
                            SendMessage(
                                hwndInputText2,
                                WM_SETTEXT,
                                TRUE,
                                (LPARAM)placeholder);                                   // Recovering the placeholder
                            focused2 = 0;
                            RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
                        }
                    }
                    break;

                case IDC_ADD_BUTTON:
                    //sending the message from the edit box to the first list box
                    textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message);
                    message[textSize] = _T('\0');

                    if(strlen(message) && strcmp(message, placeholder))
                    {
                        char *item = new char[200];
                        if(items)
                            strcpy(item, "\r\n - ");
                        else
                            strcpy(item, " - ");                                    // Managing the new string
                        strcat(item, message);
                        SendMessage(hwndOutputText, EM_REPLACESEL,
                            TRUE, (LPARAM)item);                                    // Appending a new item in the list
                        SendMessage(hwndInputText, WM_SETTEXT, TRUE,(LPARAM)"");    // RESETing the text input
                        delete [] item;                                             // Managing the memory
                        items += 1;                                                 // Incrementing the number of items
                        SendMessage(
                            hwndInputText,
                            WM_SETTEXT,
                            TRUE,
                            (LPARAM)placeholder);                                   // Recovering the placeholder
                        focused = 0;
                    }
                    RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
                    break;

                case IDC_ADD_BUTTON2:
                    //sending the message from the edit box to the second list box
                    textSize = SendMessage(hwndInputText2, WM_GETTEXT, 100, (LPARAM)message);
                    message[textSize] = _T('\0');

                    if(strlen(message) && strcmp(message, placeholder))
                    {
                        char *item = new char[200];
                        if(items2)
                            strcpy(item, "\r\n - ");
                        else
                            strcpy(item, " - ");                                    // Managing the new string
                        strcat(item, message);
                        SendMessage(hwndOutputText2, EM_REPLACESEL,
                            TRUE, (LPARAM)item);                                    // Appending a new item in the list
                        SendMessage(hwndInputText2, WM_SETTEXT, TRUE,(LPARAM)"");   // RESETing the text input
                        delete [] item;                                             // Managing the memory
                        items2 += 1;                                                // Incrementing the number of items
                        SendMessage(
                            hwndInputText2,
                            WM_SETTEXT,
                            TRUE,
                            (LPARAM)placeholder);                                   // Recovering the placeholder
                        focused2 = 0;
                    }
                    RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
                    break;

                case IDC_RESET_BUTTON:
                    SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)"");
                    break;
                case IDC_RESET_BUTTON2:
                    SendMessage(hwndOutputText2, WM_SETTEXT, 0, (LPARAM)"");
                    break;
                case IDC_RED_BUTTON:
                    if (MessageBox(NULL, TEXT("Are you sure you want to choose the red pill?"), TEXT("Are you sure?"), MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) == IDYES) {
                        return MessageBox(NULL, TEXT("YOU ARE A TRUE SPARTAN !!!"), TEXT("Right choice!"), MB_OK | MB_ICONASTERISK);
                    };
                   break;
                case IDC_BLUE_BUTTON:
                return MessageBox(NULL, TEXT("Good Luck with the report ;)"), TEXT("Wrong choice!"), MB_OK | MB_ICONWARNING);
            }
            break;

        case WM_CTLCOLOREDIT:
                if(GetDlgCtrlID((HWND)lParam) == IDC_INPUT_TEXT)
          {
                hdc = (HDC)wParam;                                              //Get handles
                if(focused)
                {
                    color = CreateSolidBrush(RGB(255, 255, 255));
                    SetTextColor(hdc, RGB(0, 0, 0));                            // Text color
                    SetBkMode(hdc, TRANSPARENT);                                // EditBox Backround Mode
                    SetBkColor(hdc,(LONG)color);                                // Backround color for EditBox
                }
                else
                {
                    color = CreateSolidBrush(RGB(255, 255, 255));
                    SetTextColor(hdc, RGB(150, 150, 150));                      // Text color
                    SetBkMode(hdc, TRANSPARENT);                                // EditBox Backround Mode
                    SetBkColor(hdc,(LONG)color);                                // Backround color for EditBox
                }

                return (LONG)color;                                             // Paint it
            }
                if(GetDlgCtrlID((HWND)lParam) == IDC_INPUT_TEXT2)
          {
                hdc = (HDC)wParam;                                              //Get handles
                if(focused2)
                {
                    color = CreateSolidBrush(RGB(255, 255, 255));
                    SetTextColor(hdc, RGB(0, 0, 0));                            // Text color
                    SetBkMode(hdc, TRANSPARENT);                                // EditBox Backround Mode
                    SetBkColor(hdc,(LONG)color);                                // Backround color for EditBox
                }
                else
                {
                    color = CreateSolidBrush(RGB(255, 255, 255));
                    SetTextColor(hdc, RGB(150, 150, 150));                      // Text color
                    SetBkMode(hdc, TRANSPARENT);                                // EditBox Backround Mode
                    SetBkColor(hdc,(LONG)color);                                // Backround color for EditBox
                }

                return (LONG)color;                                             // Paint it
            }
            break;

        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &rect);                                         // Getting coordinates of window client area
            SetBkMode(hdc, TRANSPARENT);                                        // Set the background to be transparent
            SetTextColor(hdc, RGB(0, 0, 0));                                    // Setting the text color to black
            DrawText(hdc, "\n Choose your destiny!", -1, &rect, DT_CENTER | DT_TOP);
            EndPaint(hwnd, &ps);
            break;



        case WM_DRAWITEM:
            if ((UINT)wParam == IDC_RED_BUTTON) {
                LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam;
                SIZE size;
                char szRedBtnText[5];

                strcpy(szRedBtnText, "Red Pill");
                GetTextExtentPoint32(lpdis->hDC, szRedBtnText, strlen(szRedBtnText), &size);
                SetTextColor(lpdis->hDC, RGB(250, 250, 250));
                SetBkColor(lpdis->hDC, RGB(200, 50, 50));

                ExtTextOut(
                    lpdis->hDC,
                    ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2,
                    ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2,
                    ETO_OPAQUE | ETO_CLIPPED,
                    &lpdis->rcItem,
                    szRedBtnText,
                    strlen(szRedBtnText),
                    NULL);

                DrawEdge(
                    lpdis->hDC,
                    &lpdis->rcItem,
                    (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ),
                    BF_RECT);
                return TRUE;
            }
            else if ((UINT)wParam == IDC_BLUE_BUTTON) {
                LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam;
                SIZE size;
                char szRedBtnText[5];

                strcpy(szRedBtnText, "Blue Pill");
                GetTextExtentPoint32(lpdis->hDC, szRedBtnText, strlen(szRedBtnText), &size);
                SetTextColor(lpdis->hDC, RGB(250, 250, 250));
                SetBkColor(lpdis->hDC, RGB(24, 116, 205));

                ExtTextOut(
                    lpdis->hDC,
                    ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2,
                    ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2,
                    ETO_OPAQUE | ETO_CLIPPED,
                    &lpdis->rcItem,
                    szRedBtnText,
                    strlen(szRedBtnText),
                    NULL);

                DrawEdge(
                    lpdis->hDC,
                    &lpdis->rcItem,
                    (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ),
                    BF_RECT);
                return TRUE;
            }

            break;

        case WM_SYSCOMMAND:
            switch(wParam) {
                case SC_MAXIMIZE:
                    return MessageBox(NULL, TEXT("Congratulations!You clicked the Maximize Button..."), TEXT("Maximize "), MB_OK | MB_ICONASTERISK);

                case SC_CLOSE:
                     if(MessageBox(hwnd, "Do you really want to quit?", "Lab#1", MB_OKCANCEL) == IDOK)
                DestroyWindow(hwnd);
                break;

                default:
                    return DefWindowProc(hwnd, msg, wParam, lParam);
            }
            break;

        case WM_DESTROY:
            PostQuitMessage (0);
            break;

        default:
            return DefWindowProc (hwnd, msg, wParam, lParam);
    }

    return 0;
}
Esempio n. 9
0
static LRESULT IPADDRESS_Draw (const IPADDRESS_INFO *infoPtr, HDC hdc)
{
    static const WCHAR dotW[] = { '.', 0 };
    RECT rect, rcPart;
    COLORREF bgCol, fgCol;
    HTHEME theme;
    int i, state = ETS_NORMAL;

    TRACE("\n");

    GetClientRect (infoPtr->Self, &rect);

    theme = OpenThemeData(infoPtr->Self, WC_EDITW);

    if (theme) {
        DWORD dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);

        if (!infoPtr->Enabled)
            state = ETS_DISABLED;
        else if (dwStyle & ES_READONLY)
            state = ETS_READONLY;
        else if (GetFocus() == infoPtr->Self)
            state = ETS_FOCUSED;

        GetThemeColor(theme, EP_EDITTEXT, state, TMT_FILLCOLOR, &bgCol);
        GetThemeColor(theme, EP_EDITTEXT, state, TMT_TEXTCOLOR, &fgCol);

        if (IsThemeBackgroundPartiallyTransparent (theme, EP_EDITTEXT, state))
            DrawThemeParentBackground(infoPtr->Self, hdc, &rect);
        DrawThemeBackground (theme, hdc, EP_EDITTEXT, state, &rect, 0);
    } else {
        if (infoPtr->Enabled) {
            bgCol = comctl32_color.clrWindow;
            fgCol = comctl32_color.clrWindowText;
        } else {
            bgCol = comctl32_color.clr3dFace;
            fgCol = comctl32_color.clrGrayText;
        }

        FillRect (hdc, &rect, (HBRUSH)(DWORD_PTR)(bgCol+1));
        DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
    }
    
    SetBkColor  (hdc, bgCol);
    SetTextColor(hdc, fgCol);

    for (i = 0; i < 3; i++) {
        GetWindowRect (infoPtr->Part[i].EditHwnd, &rcPart);
        MapWindowPoints( 0, infoPtr->Self, (POINT *)&rcPart, 2 );
        rect.left = rcPart.right;
        GetWindowRect (infoPtr->Part[i+1].EditHwnd, &rcPart);
        MapWindowPoints( 0, infoPtr->Self, (POINT *)&rcPart, 2 );
        rect.right = rcPart.left;

        if (theme)
            DrawThemeText(theme, hdc, EP_EDITTEXT, state, dotW, 1, DT_SINGLELINE | DT_CENTER | DT_BOTTOM, 0, &rect);
        else
            DrawTextW(hdc, dotW, 1, &rect, DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
    }

    if (theme)
        CloseThemeData(theme);

    return 0;
}
Esempio n. 10
0
FX_BOOL CFWL_FormTP::DrawBackground(CFWL_ThemeBackground* pParams) {
  if (!pParams)
    return FALSE;
  int32_t iActive = 0;
  if (pParams->m_dwStates & FWL_PARTSTATE_FRM_Inactive) {
    iActive = 1;
  }
  FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;
  switch (pParams->m_dwStates & 0x03) {
    case FWL_PARTSTATE_FRM_Hover: {
      eState = FWLTHEME_STATE_Hover;
      break;
    }
    case FWL_PARTSTATE_FRM_Pressed: {
      eState = FWLTHEME_STATE_Pressed;
      break;
    }
    case FWL_PARTSTATE_FRM_Disabled: {
      eState = FWLTHEME_STATE_Disabale;
      break;
    }
    default: {}
  }
  switch (pParams->m_iPart) {
    case FWL_PART_FRM_Border: {
      DrawFormBorder(pParams->m_pGraphics, &pParams->m_rtPart, eState,
                     &pParams->m_matrix, iActive);
      break;
    }
    case FWL_PART_FRM_Edge: {
      DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(),
               &pParams->m_rtPart, &pParams->m_matrix);
      break;
    }
    case FWL_PART_FRM_Background: {
      FillBackground(pParams->m_pGraphics, &pParams->m_rtPart,
                     &pParams->m_matrix);
      break;
    }
    case FWL_PART_FRM_Caption: {
      DrawCaption(pParams->m_pGraphics, &pParams->m_rtPart, eState,
                  &pParams->m_matrix, iActive);
      break;
    }
    case FWL_PART_FRM_NarrowCaption: {
      DrawNarrowCaption(pParams->m_pGraphics, &pParams->m_rtPart, eState,
                        &pParams->m_matrix, iActive);
      break;
    }
    case FWL_PART_FRM_CloseBox: {
      DrawCloseBox(pParams->m_pGraphics, &pParams->m_rtPart, eState,
                   &pParams->m_matrix, iActive);
      break;
    }
    case FWL_PART_FRM_MinimizeBox: {
      DrawMinimizeBox(pParams->m_pGraphics, &pParams->m_rtPart, eState,
                      &pParams->m_matrix, iActive);
      break;
    }
    case FWL_PART_FRM_MaximizeBox: {
      DrawMaximizeBox(pParams->m_pGraphics, &pParams->m_rtPart, eState,
                      pParams->m_dwData, &pParams->m_matrix, iActive);
      break;
    }
    case FWL_PART_FRM_Icon: {
      DrawIconImage(pParams->m_pGraphics, pParams->m_pImage, &pParams->m_rtPart,
                    eState, &pParams->m_matrix, iActive);
      break;
    }
    default: {}
  }
  return TRUE;
}
Esempio n. 11
0
FWL_ERR CFWL_PushButtonImp::DrawWidget(CFX_Graphics* pGraphics,
                                       const CFX_Matrix* pMatrix) {
  if (!pGraphics)
    return FWL_ERR_Indefinite;
  if (!m_pProperties->m_pThemeProvider)
    return FWL_ERR_Indefinite;
  IFWL_PushButtonDP* pData =
      static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider);
  CFX_DIBitmap* pPicture = NULL;
  IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
  if (HasBorder()) {
    DrawBorder(pGraphics, FWL_PART_PSB_Border, m_pProperties->m_pThemeProvider,
               pMatrix);
  }
  if (HasEdge()) {
    DrawEdge(pGraphics, FWL_PART_PSB_Edge, m_pProperties->m_pThemeProvider,
             pMatrix);
  }
  DrawBkground(pGraphics, m_pProperties->m_pThemeProvider, pMatrix);
  CFX_Matrix matrix;
  matrix.Concat(*pMatrix);
  FX_FLOAT iPicwidth = 0;
  FX_FLOAT ipicheight = 0;
  CFX_WideString wsCaption;
  if (pData) {
    pData->GetCaption(m_pInterface, wsCaption);
  }
  CFX_RectF rtText;
  rtText.Set(0, 0, 0, 0);
  if (!wsCaption.IsEmpty()) {
    CalcTextRect(wsCaption, pTheme, 0, m_iTTOAlign, rtText);
  }
  switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_PSB_ModeMask) {
    case FWL_STYLEEXT_PSB_TextOnly:
      DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix);
      break;
    case FWL_STYLEEXT_PSB_IconOnly:
      if (pData) {
        pPicture = pData->GetPicture(m_pInterface);
      }
      if (pPicture) {
        CFX_PointF point;
        switch (m_iTTOAlign) {
          case 0: {
            point.x = m_rtClient.left;
            point.y = m_rtClient.top;
            break;
          }
          case 1: {
            point.x = m_rtClient.left +
                      (m_rtClient.width / 2 - pPicture->GetWidth() / 2);
            point.y = m_rtClient.top;
            break;
          }
          case 2:
            point.x = m_rtClient.left + m_rtClient.width - pPicture->GetWidth();
            point.y = m_rtClient.top;
            break;
          case 4:
            point.x = m_rtClient.left;
            point.y = m_rtClient.top + m_rtClient.height / 2 -
                      pPicture->GetHeight() / 2;
            break;
          case 5:
            point.x = m_rtClient.left +
                      (m_rtClient.width / 2 - pPicture->GetWidth() / 2);
            point.y = m_rtClient.top + m_rtClient.height / 2 -
                      pPicture->GetHeight() / 2;
            break;
          case 6:
            point.x = m_rtClient.left + m_rtClient.width - pPicture->GetWidth();
            point.y = m_rtClient.top + m_rtClient.height / 2 -
                      pPicture->GetHeight() / 2;
            break;
          case 8:
            point.x = m_rtClient.left;
            point.y =
                m_rtClient.top + m_rtClient.height - pPicture->GetHeight();
            break;
          case 9:
            point.x = m_rtClient.left +
                      (m_rtClient.width / 2 - pPicture->GetWidth() / 2);
            point.y =
                m_rtClient.top + m_rtClient.height - pPicture->GetHeight();
            break;
          case 10:
            point.x = m_rtClient.left + m_rtClient.width - pPicture->GetWidth();
            point.y =
                m_rtClient.top + m_rtClient.height - pPicture->GetHeight();
            break;
        }
        pGraphics->DrawImage(pPicture, point, &matrix);
      }
      break;
    case FWL_STYLEEXT_PSB_TextIcon:
      if (pPicture) {
        CFX_PointF point;
        switch (m_iTTOAlign) {
          case 0: {
            point.x = m_rtClient.left;
            point.y = m_rtClient.top;
            iPicwidth = (FX_FLOAT)(pPicture->GetWidth() - 7);
            ipicheight =
                pPicture->GetHeight() / 2 - m_rtCaption.top - rtText.height / 2;
            break;
          }
          case 1: {
            point.x =
                m_rtClient.left + (m_rtClient.width / 2 -
                                   (pPicture->GetWidth() + rtText.width) / 2);
            point.y = m_rtClient.top;
            iPicwidth = pPicture->GetWidth() -
                        ((m_rtClient.width) / 2 - rtText.width / 2 - point.x) +
                        rtText.width / 2 - 7;
            ipicheight =
                pPicture->GetHeight() / 2 - m_rtCaption.top - rtText.height / 2;
            break;
          }
          case 2:
            point.x = m_rtClient.left + m_rtClient.width -
                      pPicture->GetWidth() - rtText.width;
            point.y = m_rtClient.top;
            iPicwidth = m_rtClient.left + m_rtClient.width - point.x -
                        pPicture->GetWidth() - rtText.width + 7;
            ipicheight =
                pPicture->GetHeight() / 2 - m_rtCaption.top - rtText.height / 2;
            break;
          case 4:
            point.x = m_rtClient.left;
            point.y = m_rtClient.top + m_rtClient.height / 2 -
                      pPicture->GetHeight() / 2;
            iPicwidth = m_rtClient.left + pPicture->GetWidth() - 7;
            break;
          case 5:
            point.x =
                m_rtClient.left + (m_rtClient.width / 2 -
                                   (pPicture->GetWidth() + rtText.width) / 2);
            point.y = m_rtClient.top + m_rtClient.height / 2 -
                      pPicture->GetHeight() / 2;
            iPicwidth = pPicture->GetWidth() -
                        ((m_rtClient.width) / 2 - rtText.width / 2 - point.x) +
                        rtText.width / 2 - 7;
            break;
          case 6:
            point.x = m_rtClient.left + m_rtClient.width -
                      pPicture->GetWidth() - rtText.width;
            point.y = m_rtClient.top + m_rtClient.height / 2 -
                      pPicture->GetHeight() / 2;
            iPicwidth = m_rtClient.left + m_rtClient.width - point.x -
                        pPicture->GetWidth() - rtText.width + 7;
            break;
          case 8:
            point.x = m_rtClient.left;
            point.y =
                m_rtClient.top + m_rtClient.height - pPicture->GetHeight();
            iPicwidth = (FX_FLOAT)(pPicture->GetWidth() - 7);
            ipicheight -= rtText.height / 2;
            break;
          case 9:
            point.x =
                m_rtClient.left + (m_rtClient.width / 2 -
                                   (pPicture->GetWidth() + rtText.width) / 2);
            point.y =
                m_rtClient.top + m_rtClient.height - pPicture->GetHeight();
            iPicwidth = pPicture->GetWidth() -
                        ((m_rtClient.width) / 2 - rtText.width / 2 - point.x) +
                        rtText.width / 2 - 7;
            ipicheight -= rtText.height / 2;
            break;
          case 10:
            point.x = m_rtClient.left + m_rtClient.width -
                      pPicture->GetWidth() - rtText.width;
            point.y =
                m_rtClient.top + m_rtClient.height - pPicture->GetHeight();
            iPicwidth = m_rtClient.left + m_rtClient.width - point.x -
                        pPicture->GetWidth() - rtText.width + 7;
            ipicheight -= rtText.height / 2;
            break;
        }
        pGraphics->DrawImage(pPicture, point, &matrix);
      }
      matrix.e += m_rtClient.left + iPicwidth;
      matrix.f += m_rtClient.top + ipicheight;
      DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix);
      break;
  }
  return FWL_ERR_Succeeded;
}
Esempio n. 12
0
INT_PTR CALLBACK DlgProcColorToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static COLORCHOOSER* pCC = NULL;
    static int iCurrentHotTrack;
    static BOOL bChoosing;
    static int iRows;
    static int iColumns;
    static HWND hPreviousActiveWindow;

    switch(msg) {
    case WM_INITDIALOG:
    {
        RECT rc;
        int iSquareRoot;
        int width ;
        int height;

        TranslateDialogDefault(hwndDlg);
        pCC = (COLORCHOOSER*) lParam;

        iCurrentHotTrack = -2;
        bChoosing = FALSE;

        iSquareRoot = (int)sqrt(pCC->pModule->nColorCount);

        iColumns = iSquareRoot * iSquareRoot == pCC->pModule->nColorCount?iSquareRoot:iSquareRoot+1;
        iRows = iSquareRoot;

        rc.top = rc.left = 100;
        rc.right =  100 +  iColumns * 25 + 1;
        rc.bottom = iRows * 20 + 100 + 20;

        AdjustWindowRectEx(&rc, GetWindowLong(hwndDlg, GWL_STYLE), FALSE, GetWindowLong(hwndDlg, GWL_EXSTYLE));

        width = rc.right - rc.left;
        height = rc.bottom - rc.top;

        pCC->yPosition -= height;


        SetDlgItemText(hwndDlg, IDC_CHAT_COLORTEXT, pCC->bForeground?TranslateT("Text colour"):TranslateT("Background colour"));
        SetWindowPos(GetDlgItem(hwndDlg, IDC_CHAT_COLORTEXT), NULL,  0, 0, width, 20, 0);
        SetWindowPos(hwndDlg, NULL, pCC->xPosition, pCC->yPosition, width, height, SWP_SHOWWINDOW);
    }
    break;

    case WM_CTLCOLOREDIT:
    case WM_CTLCOLORSTATIC:
        if((HWND)lParam==GetDlgItem(hwndDlg,IDC_CHAT_COLORTEXT)) {
            SetTextColor((HDC)wParam,RGB(60,60,150));
            SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW));
            return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
        }
        break;

    case WM_COMMAND:
        switch ( LOWORD( wParam )) {
        case IDOK:
            if (iCurrentHotTrack >= 0)
                PostMessage(hwndDlg, WM_LBUTTONUP, 0, 0);
            break;
        case IDCANCEL:
            DestroyWindow(hwndDlg);
            break;
        }
        break;

    case WM_LBUTTONUP:
        if (iCurrentHotTrack >= 0 && iCurrentHotTrack < pCC->pModule->nColorCount && pCC->hWndTarget != NULL) {
            HWND hWindow;
            CHARFORMAT2 cf;
            cf.cbSize = sizeof(CHARFORMAT2);
            cf.dwMask = 0;
            cf.dwEffects = 0;
            hWindow = GetParent(pCC->hWndTarget);

            if ( pCC->bForeground ) {
                pCC->si->bFGSet = TRUE;
                pCC->si->iFG = iCurrentHotTrack;
                if ( IsDlgButtonChecked( hWindow, IDC_CHAT_COLOR )) {
                    cf.dwMask = CFM_COLOR;
                    cf.crTextColor = pCC->pModule->crColors[iCurrentHotTrack];
                    if (pCC->pModule->bSingleFormat) {
                        SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
                    } else {
                        SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
                    }
                }
            }
            else {
                pCC->si->bBGSet = TRUE;
                pCC->si->iBG = iCurrentHotTrack;
                if(IsDlgButtonChecked(hWindow, IDC_CHAT_BKGCOLOR)) {
                    cf.dwMask = CFM_BACKCOLOR;
                    cf.crBackColor = pCC->pModule->crColors[iCurrentHotTrack];
                    if (pCC->pModule->bSingleFormat) {
                        SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
                    } else {
                        SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
                    }
                }
            }
        }
        PostMessage(hwndDlg, WM_CLOSE, 0, 0);
        break;

    case WM_ACTIVATE:
        if (wParam == WA_INACTIVE)
            PostMessage(hwndDlg, WM_CLOSE, 0, 0);
        else if ((wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE))
            hPreviousActiveWindow = (HWND)lParam;
        break;

    case WM_MOUSEMOVE:
    {
        HDC hdc = GetDC(hwndDlg);
        POINT pt;
        RECT rect;
        int but;

        pt.x = LOWORD(lParam);
        pt.y = HIWORD(lParam);

        if (iCurrentHotTrack == -2)
            return 0; // prevent focussing when not drawn yet!

        but = CalculateCoordinatesToButton(pCC, pt);

        // weird stuff
        if (but != iCurrentHotTrack) {
            if (iCurrentHotTrack >= 0) {
                rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
                DrawFocusRect(hdc, &rect);
                iCurrentHotTrack = -1;
            }
            iCurrentHotTrack = but;

            if (iCurrentHotTrack >= 0) {
                rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
                DrawFocusRect(hdc, &rect);
            }
        }
        ReleaseDC(hwndDlg, hdc);
    }
    break;

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc;
        RECT rc;
        int i;
        int iThisRow = 1;
        int iThisColumn = 0;

        GetClientRect(hwndDlg, &rc);

        rc.top += 20;

        hdc = BeginPaint(hwndDlg, &ps);

        // fill background
        FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW));

        for (i=0; i < pCC->pModule->nColorCount; i++)
        {
            HBRUSH hbr;

            // decide place to draw the color block in the window
            iThisColumn ++;
            if (iThisColumn > iColumns) {
                iThisColumn = 1;
                iThisRow++;
            }

            if ( (pCC->bForeground && pCC->si->bFGSet && pCC->si->iFG == i) ||
                    (!pCC->bForeground && pCC->si->bBGSet && pCC->si->iBG == i) ) {
                rc.top = (iThisRow-1) * 20+ 1 +20 ;
                rc.left = (iThisColumn-1) * 25 + 1 + 1 ;
                rc.bottom = iThisRow * 20- 1 + 20 ;
                rc.right = iThisColumn * 25-1 ;

                DrawEdge(hdc, &rc, EDGE_RAISED, BF_TOP|BF_LEFT|BF_RIGHT|BF_BOTTOM);
            }

            rc.top = (iThisRow-1) * 20+ 3 +20 ;
            rc.left = (iThisColumn-1) * 25 + 3 + 1 ;
            rc.bottom = iThisRow * 20- 3 + 20 ;
            rc.right = iThisColumn * 25-3 ;

            FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));

            hbr = CreateSolidBrush(pCC->pModule->crColors[i]);

            rc.top = (iThisRow-1) * 20+4 +20;
            rc.left = (iThisColumn-1) * 25+ 4 + 1;
            rc.bottom = iThisRow * 20-4 + 20;
            rc.right = iThisColumn * 25-4;

            FillRect(hdc, &rc, hbr);
            DeleteObject(hbr);
        }

        EndPaint(hwndDlg, &ps);
        iCurrentHotTrack = -1;
    }
    break;

    case WM_CLOSE:
        SetFocus(pCC->hWndTarget);
        DestroyWindow(hwndDlg);
        break;

    case WM_DESTROY:
        mir_free( pCC );
        return TRUE;
    }

    return FALSE;
}
Esempio n. 13
0
BOOL DrawMeter(HDC hdc, RECT rect)
{
    static HFONT font;

    // Plain vanilla font

    static LOGFONT lf =
	{0, 0, 0, 0,
	 FW_NORMAL,
	 FALSE, FALSE, FALSE,
	 DEFAULT_CHARSET,
	 OUT_DEFAULT_PRECIS,
	 CLIP_DEFAULT_PRECIS,
	 DEFAULT_QUALITY,
	 DEFAULT_PITCH | FF_DONTCARE,
	 ""};

    // Draw nice etched edge

    DrawEdge(hdc, &rect , EDGE_SUNKEN, BF_ADJUST | BF_RECT);

    // Select font

    if (font == NULL)
    {
	lf.lfHeight = 16;
	font = CreateFontIndirect(&lf);
    }

    // Calculate dimensions

    int width = rect.right - rect.left;

    // Move the origin

    SetViewportOrgEx(hdc, 2, 2, NULL);

    SelectObject(hdc, font);

    SetTextAlign(hdc, TA_CENTER);

    // Draw the meter scale

    static int as[] =
	{-40, -20, -14, -10, -8, -7, -6, -5,
	 -4, -3, -2, -1, 0, 1, 2, 3};

    for (int i = 0; i < LENGTH(as); i++)
    {
	static char s[16];

	sprintf(s, "%d", abs(as[i]));

	float x = pow(10.0, (as[i] + 20.0) / 20.0) / 10.0;

	x /= pow(10.0, 23.0 / 20.0) / 10.0;

	x *= (width - 22);

	x += 10;

	TextOut(hdc, x, 0, s, strlen(s));
    }

    MoveToEx(hdc, 3, 20, NULL);
    LineTo(hdc, 8, 20);

    MoveToEx(hdc, width - 8, 20, NULL);
    LineTo(hdc, width - 3, 20);
    MoveToEx(hdc, width - 6, 18, NULL);
    LineTo(hdc, width - 6, 23);

    static int at[] =
	{-10, -5, 0, 1, 2, 3, 4, 5,
	 6, 7, 8, 9, 10, 11, 12, 13};

    for (int i = 0; i < LENGTH(at); i++)
    {
	float x = pow(10.0, at[i] / 10.0) / 10.0;

	x /= pow(10.0, 23.0 / 20.0) / 10.0;

	x *= (width - 22);

	x += 10;

	MoveToEx(hdc, x, 16, NULL);
	LineTo(hdc, x, 24);
    }

    for (int i = 1; i < 26; i += 2)
    {
	float x = pow(10.0, (i / 20.0)) / 10.0;

	x /= pow(10.0, 23.0 / 20.0) / 10.0;

	x *= (width - 22);

	x += 10;

	MoveToEx(hdc, x, 18, NULL);
	LineTo(hdc, x, 24);
    }

    for (int i = 17; i < 48; i += 2)
    {
	float x = pow(10.0, (i / 40.0)) / 10.0;

	x /= pow(10.0, 23.0 / 20.0) / 10.0;

	x *= (width - 22);

	x += 10;

	MoveToEx(hdc, x, 20, NULL);
	LineTo(hdc, x, 24);
    }

    return TRUE;
}
Esempio n. 14
0
BOOL DrawSpectrum(HDC hdc, RECT rect)
{
    static HBITMAP bitmap;
    static HDC hbdc;

    // Draw nice etched edge

    DrawEdge(hdc, &rect , EDGE_SUNKEN, BF_ADJUST | BF_RECT);

    // Calculate bitmap dimensions

    int width = rect.right - rect.left;
    int height = rect.bottom - rect.top;

    // Create DC

    if (hbdc == NULL)
    {
	hbdc = CreateCompatibleDC(hdc);
	bitmap = CreateCompatibleBitmap(hdc, width, height);
	SelectObject(hbdc, bitmap);
	SelectObject(hbdc, GetStockObject(DC_PEN));
    }

    // Erase background

    RECT brct =
	{0, 0, width, height};
    FillRect(hbdc, &brct, GetStockObject(BLACK_BRUSH));

    // Dark green graticule

    SetDCPenColor(hbdc, RGB(0, 128, 0));

    // Draw graticule

    for (int i = 4; i < width; i += 5)
    {
	MoveToEx(hbdc, i, 0, NULL);
	LineTo(hbdc, i, height);
    }

    for (int i = 4; i < height; i += 5)
    {
	MoveToEx(hbdc, 0, i, NULL);
	LineTo(hbdc, width, i);
    }

    // Don't attempt the trace until there's a buffer

    if (spectrum.data == NULL)
    {
	// Copy the bitmap

	BitBlt(hdc, rect.left, rect.top, width, height,
	       hbdc, 0, 0, SRCCOPY);

	return TRUE;
    }

    // Move the origin

    SetViewportOrgEx(hbdc, 0, height - 1, NULL);

    // Green pen for spectrum trace

    SetDCPenColor(hbdc, RGB(0, 255, 0));

    static float max;

    if (max < 1.0)
	max = 1.0;

    // Calculate the scaling

    float yscale = (float)height / max;

    max = 0.0;

    // Draw the spectrum

    MoveToEx(hbdc, 0, 0, NULL);

    float xscale = (float)log(spectrum.length) / width;

    // Create trace

    int last = 1;
    for (int x = 0; x < width; x++)
    {
	float value = 0.0;

	int index = (int)round(pow(M_E, x * xscale));
	for (int i = last; i <= index; i++)
	{
	    // Don't show DC component

	    if (i > 0 && i < spectrum.length)
	    {
		if (value < spectrum.data[i])
		    value = spectrum.data[i];
	    }
	}

	// Update last index

	last = index + 1;

	if (max < value)
	    max = value;

	int y = -round(value * yscale);

	LineTo(hbdc, x, y);
    }

    // Move the origin back

    SetViewportOrgEx(hbdc, 0, 0, NULL);

    // Copy the bitmap

    BitBlt(hdc, rect.left, rect.top, width, height,
	   hbdc, 0, 0, SRCCOPY);

    return TRUE;
}
Esempio n. 15
0
void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint)
{
	RECT clRect;
	int indent, index, fontHeight;
	struct ClcGroup *group;
	HFONT hOldFont;
	LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
	int status = GetGeneralisedStatus();
	int grey = 0, groupCountsFontTopShift;
	HBRUSH hBrushAlternateGrey = NULL;
	// yes I know about GetSysColorBrush()
	COLORREF tmpbkcolour = style & CLS_CONTACTLIST ? (dat->useWindowsColours ? GetSysColor(COLOR_3DFACE) : dat->bkColour) : dat->bkColour;

	if (dat->greyoutFlags & pcli->pfnClcStatusToPf2(status) || style & WS_DISABLED)
		grey = 1;
	else if (GetFocus() != hwnd && dat->greyoutFlags & GREYF_UNFOCUS)
		grey = 1;
	GetClientRect(hwnd, &clRect);
	if (rcPaint == NULL)
		rcPaint = &clRect;
	if (IsRectEmpty(rcPaint))
		return;

	HDC hdcMem = CreateCompatibleDC(hdc);
	HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL);
	HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBmpOsb);
	{
		TEXTMETRIC tm;
		hOldFont = (HFONT)SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPS].hFont);
		GetTextMetrics(hdcMem, &tm);
		groupCountsFontTopShift = tm.tmAscent;
		SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPCOUNTS].hFont);
		GetTextMetrics(hdcMem, &tm);
		groupCountsFontTopShift -= tm.tmAscent;
	}
	if (style & CLS_GREYALTERNATE)
		hBrushAlternateGrey =
		CreateSolidBrush(GetNearestColor(hdcMem, RGB(GetRValue(tmpbkcolour) - 10, GetGValue(tmpbkcolour) - 10, GetBValue(tmpbkcolour) - 10)));

	ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight);
	SetBkMode(hdcMem, TRANSPARENT);
	{
		HBRUSH hBrush = CreateSolidBrush(tmpbkcolour);
		FillRect(hdcMem, rcPaint, hBrush);
		DeleteObject(hBrush);
		if (dat->hBmpBackground) {
			// XXX: Halftone isnt supported on 9x, however the scretch problems dont happen on 98.
			SetStretchBltMode(hdcMem, HALFTONE);

			BITMAP bmp;
			GetObject(dat->hBmpBackground, sizeof(bmp), &bmp);
			HDC hdcBmp = CreateCompatibleDC(hdcMem);
			SelectObject(hdcBmp, dat->hBmpBackground);
			int y = dat->backgroundBmpUse & CLBF_SCROLL ? -dat->yScroll : 0;
			int maxx = dat->backgroundBmpUse & CLBF_TILEH ? clRect.right : 1;
			int maxy = dat->backgroundBmpUse & CLBF_TILEV ? rcPaint->bottom : y + 1;
			int destw, desth;
			switch (dat->backgroundBmpUse & CLBM_TYPE) {
			case CLB_STRETCH:
				if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) {
					if (clRect.right * bmp.bmHeight < clRect.bottom * bmp.bmWidth) {
						desth = clRect.bottom;
						destw = desth * bmp.bmWidth / bmp.bmHeight;
					}
					else {
						destw = clRect.right;
						desth = destw * bmp.bmHeight / bmp.bmWidth;
					}
				}
				else {
					destw = clRect.right;
					desth = clRect.bottom;
				}
				break;
			case CLB_STRETCHH:
				if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) {
					destw = clRect.right;
					desth = destw * bmp.bmHeight / bmp.bmWidth;
				}
				else {
					destw = clRect.right;
					desth = bmp.bmHeight;
				}
				break;
			case CLB_STRETCHV:
				if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) {
					desth = clRect.bottom;
					destw = desth * bmp.bmWidth / bmp.bmHeight;
				}
				else {
					destw = bmp.bmWidth;
					desth = clRect.bottom;
				}
				break;
			default:       //clb_topleft
				destw = bmp.bmWidth;
				desth = bmp.bmHeight;
				break;
			}
			for (; y < maxy; y += desth) {
				if (y < rcPaint->top - desth)
					continue;
				for (int x = 0; x < maxx; x += destw)
					StretchBlt(hdcMem, x, y, destw, desth, hdcBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
			}
			DeleteDC(hdcBmp);
		}
	}

	int y = -dat->yScroll;
	group = &dat->list;
	group->scanIndex = 0;
	indent = 0;
	for (index = 0; y < rcPaint->bottom;) {
		if (group->scanIndex == group->cl.count) {
			group = group->parent;
			indent--;
			if (group == NULL)
				break;
			group->scanIndex++;
			continue;
		}

		ClcContact *cc = group->cl.items[group->scanIndex];
		if (y > rcPaint->top - dat->rowHeight) {
			int iImage = -1;
			int selected = index == dat->selection && (dat->showSelAlways || dat->exStyle & CLS_EX_SHOWSELALWAYS || GetFocus() == hwnd) && cc->type != CLCIT_DIVIDER;
			int hottrack = dat->exStyle & CLS_EX_TRACKSELECT && cc->type != CLCIT_DIVIDER && dat->iHotTrack == index;
			SIZE textSize, countsSize = { 0 }, spaceSize = { 0 };
			int width, checkboxWidth;
			TCHAR *szCounts = NULL;

			// alternating grey
			if (style & CLS_GREYALTERNATE && index & 1) {
				RECT rc;
				rc.top = y;
				rc.bottom = rc.top + dat->rowHeight;
				rc.left = 0;
				rc.right = clRect.right;
				FillRect(hdcMem, &rc, hBrushAlternateGrey);
			}

			// setup
			if (cc->type == CLCIT_GROUP)
				ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight);
			else if (cc->type == CLCIT_INFO) {
				if (cc->flags & CLCIIF_GROUPFONT)
					ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight);
				else
					ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight);
			}
			else if (cc->type == CLCIT_DIVIDER)
				ChangeToFont(hdcMem, dat, FONTID_DIVIDERS, &fontHeight);
			else if (cc->type == CLCIT_CONTACT && cc->flags & CONTACTF_NOTONLIST)
				ChangeToFont(hdcMem, dat, FONTID_NOTONLIST, &fontHeight);
			else if (cc->type == CLCIT_CONTACT &&
				((cc->flags & CONTACTF_INVISTO && GetRealStatus(cc, status) != ID_STATUS_INVISIBLE) || (cc->flags & CONTACTF_VISTO && GetRealStatus(cc, status) == ID_STATUS_INVISIBLE))) {
				// the contact is in the always visible list and the proto is invisible
				// the contact is in the always invisible and the proto is in any other mode
				ChangeToFont(hdcMem, dat, cc->flags & CONTACTF_ONLINE ? FONTID_INVIS : FONTID_OFFINVIS, &fontHeight);
			}
			else if (cc->type == CLCIT_CONTACT && !(cc->flags & CONTACTF_ONLINE))
				ChangeToFont(hdcMem, dat, FONTID_OFFLINE, &fontHeight);
			else
				ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight);
			GetTextExtentPoint32(hdcMem, cc->szText, (int)mir_tstrlen(cc->szText), &textSize);
			width = textSize.cx;
			if (cc->type == CLCIT_GROUP) {
				szCounts = pcli->pfnGetGroupCountsText(dat, cc);
				if (szCounts[0]) {
					GetTextExtentPoint32(hdcMem, _T(" "), 1, &spaceSize);
					ChangeToFont(hdcMem, dat, FONTID_GROUPCOUNTS, &fontHeight);
					GetTextExtentPoint32(hdcMem, szCounts, (int)mir_tstrlen(szCounts), &countsSize);
					width += spaceSize.cx + countsSize.cx;
				}
			}

			if ((style & CLS_CHECKBOXES && cc->type == CLCIT_CONTACT) || (style & CLS_GROUPCHECKBOXES && cc->type == CLCIT_GROUP) || (cc->type == CLCIT_INFO && cc->flags & CLCIIF_CHECKBOX))
				checkboxWidth = dat->checkboxSize + 2;
			else
				checkboxWidth = 0;

			// background
			if (selected) {
				int x = dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace - 2;
				ImageList_DrawEx(dat->himlHighlight, 0, hdcMem, x, y, min(width + 5, clRect.right - x), dat->rowHeight, CLR_NONE, CLR_NONE,
					dat->exStyle & CLS_EX_NOTRANSLUCENTSEL ? ILD_NORMAL : ILD_BLEND25);
				SetTextColor(hdcMem, dat->selTextColour);
			}
			else if (hottrack)
				SetHotTrackColour(hdcMem, dat);

			// checkboxes
			if (checkboxWidth) {
				RECT rc;
				HANDLE hTheme = OpenThemeData(hwnd, L"BUTTON");
				rc.left = dat->leftMargin + indent * dat->groupIndent;
				rc.right = rc.left + dat->checkboxSize;
				rc.top = y + ((dat->rowHeight - dat->checkboxSize) >> 1);
				rc.bottom = rc.top + dat->checkboxSize;
				DrawThemeBackground(hTheme, hdcMem, BP_CHECKBOX, cc->flags & CONTACTF_CHECKED ? (hottrack ? CBS_CHECKEDHOT : CBS_CHECKEDNORMAL) : (hottrack ? CBS_UNCHECKEDHOT : CBS_UNCHECKEDNORMAL), &rc, &rc);
				CloseThemeData(hTheme);
			}

			// icon
			if (cc->type == CLCIT_GROUP)
				iImage = cc->group->expanded ? IMAGE_GROUPOPEN : IMAGE_GROUPSHUT;
			else if (cc->type == CLCIT_CONTACT)
				iImage = cc->iImage;
			if (iImage != -1) {
				// this doesnt use CLS_CONTACTLIST since the colour prolly wont match anyway
				COLORREF colourFg = dat->selBkColour;
				int mode = ILD_NORMAL;
				if (hottrack) {
					colourFg = dat->hotTextColour;
				}
				else if (cc->type == CLCIT_CONTACT && cc->flags & CONTACTF_NOTONLIST) {
					colourFg = dat->fontInfo[FONTID_NOTONLIST].colour;
					mode = ILD_BLEND50;
				}
				if (cc->type == CLCIT_CONTACT && dat->showIdle
					&& (cc->flags & CONTACTF_IDLE)
					&& GetRealStatus(cc, ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
					mode = ILD_SELECTED;
				ImageList_DrawEx(himlCListClc, iImage, hdcMem, dat->leftMargin + indent * dat->groupIndent + checkboxWidth,
					y + ((dat->rowHeight - 16) >> 1), 0, 0, CLR_NONE, colourFg, mode);
			}

			// text
			if (cc->type == CLCIT_DIVIDER) {
				RECT rc;
				rc.top = y + (dat->rowHeight >> 1);
				rc.bottom = rc.top + 2;
				rc.left = dat->leftMargin + indent * dat->groupIndent;
				rc.right = rc.left + ((clRect.right - rc.left - textSize.cx) >> 1) - 3;
				DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT);
				TextOut(hdcMem, rc.right + 3, y + ((dat->rowHeight - fontHeight) >> 1), cc->szText,
					(int)mir_tstrlen(cc->szText));
				rc.left = rc.right + 6 + textSize.cx;
				rc.right = clRect.right;
				DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT);
			}
Esempio n. 16
0
bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc,
                            wxODAction WXUNUSED(act), wxODStatus stat)
{
    const MenuDrawData* data = MenuDrawData::Get();

    wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
    HDC hdc = GetHdcOf(*impl);

    RECT rect;
    wxCopyRectToRECT(rc, rect);

    int imgWidth = wxMax(GetMarginWidth(), data->CheckSize.cx);

    if ( IsOwnerDrawn() )
    {
        // font and colors to use
        wxFont font;
        GetFontToUse(font);

        wxColour colText, colBack;
        GetColourToUse(stat, colText, colBack);

        // calculate metrics of item parts
        RECT rcSelection = rect;
        data->ItemMargin.ApplyTo(rcSelection);

        RECT rcSeparator = rcSelection;
        data->SeparatorMargin.ApplyTo(rcSeparator);

        RECT rcGutter = rcSelection;
        rcGutter.right = data->ItemMargin.cxLeftWidth
                       + data->CheckBgMargin.cxLeftWidth
                       + data->CheckMargin.cxLeftWidth
                       + imgWidth
                       + data->CheckMargin.cxRightWidth
                       + data->CheckBgMargin.cxRightWidth;

        RECT rcText = rcSelection;
        rcText.left = rcGutter.right + data->TextBorder;

        // we draw the text label vertically centered, but this results in it
        // being 1px too low compared to native menus for some reason, fix it
        if ( data->MenuLayout() != MenuDrawData::FullTheme )
            rcText.top--;

#if wxUSE_UXTHEME
        // If a custom background colour is explicitly specified, we should use
        // it instead of the default theme background.
        wxUxThemeEngine* const theme = GetBackgroundColour().IsOk()
                                        ? NULL
                                        : MenuDrawData::GetUxThemeEngine();
        if ( theme )
        {
            POPUPITEMSTATES state;
            if ( stat & wxODDisabled )
            {
                state = (stat & wxODSelected) ? MPI_DISABLEDHOT
                                              : MPI_DISABLED;
            }
            else if ( stat & wxODSelected )
            {
                state = MPI_HOT;
            }
            else
            {
                state = MPI_NORMAL;
            }

            wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU");

            if ( theme->IsThemeBackgroundPartiallyTransparent(hTheme,
                    MENU_POPUPITEM, state) )
            {
                theme->DrawThemeBackground(hTheme, hdc,
                                           MENU_POPUPBACKGROUND,
                                           0, &rect, NULL);
            }

            theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPGUTTER,
                                       0, &rcGutter, NULL);

            if ( IsSeparator() )
            {
                rcSeparator.left = rcGutter.right;
                theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPSEPARATOR,
                                           0, &rcSeparator, NULL);
                return true;
            }

            theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPITEM,
                                       state, &rcSelection, NULL);

        }
        else
#endif // wxUSE_UXTHEME
        {
            if ( IsSeparator() )
            {
                DrawEdge(hdc, &rcSeparator, EDGE_ETCHED, BF_TOP);
                return true;
            }

            AutoHBRUSH hbr(colBack.GetPixel());
            SelectInHDC selBrush(hdc, hbr);
            ::FillRect(hdc, &rcSelection, hbr);
        }


        // draw text label
        // using native API because it recognizes '&'

        HDCTextColChanger changeTextCol(hdc, colText.GetPixel());
        HDCBgColChanger changeBgCol(hdc, colBack.GetPixel());
        HDCBgModeChanger changeBgMode(hdc, TRANSPARENT);

        SelectInHDC selFont(hdc, GetHfontOf(font));


        // item text name without mnemonic for calculating size
        wxString text = GetName();

        SIZE textSize;
        ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &textSize);

        // item text name with mnemonic
        text = GetItemLabel().BeforeFirst('\t');

        int flags = DST_PREFIXTEXT;
        // themes menu is using specified color for disabled labels
        if ( data->MenuLayout() == MenuDrawData::Classic &&
             (stat & wxODDisabled) && !(stat & wxODSelected) )
            flags |= DSS_DISABLED;

        if ( (stat & wxODHidePrefix) && !data->AlwaysShowCues )
            flags |= DSS_HIDEPREFIX;

        int x = rcText.left;
        int y = rcText.top + (rcText.bottom - rcText.top - textSize.cy) / 2;

        ::DrawState(hdc, NULL, NULL, wxMSW_CONV_LPARAM(text),
                    text.length(), x, y, 0, 0, flags);

        // ::SetTextAlign(hdc, TA_RIGHT) doesn't work with DSS_DISABLED or DSS_MONO
        // as the last parameter in DrawState() (at least with Windows98). So we have
        // to take care of right alignment ourselves.
        wxString accel = GetItemLabel().AfterFirst(wxT('\t'));
        if ( !accel.empty() )
        {
            SIZE accelSize;
            ::GetTextExtentPoint32(hdc, accel.c_str(), accel.length(), &accelSize);

            int flags = DST_TEXT;
            // themes menu is using specified color for disabled labels
            if ( data->MenuLayout() == MenuDrawData::Classic &&
                 (stat & wxODDisabled) && !(stat & wxODSelected) )
                flags |= DSS_DISABLED;

            int x = rcText.right - data->ArrowMargin.GetTotalX()
                                 - data->ArrowSize.cx
                                 - data->ArrowBorder;

            // right align accel on FullTheme menu, left otherwise
            if ( data->MenuLayout() == MenuDrawData::FullTheme)
                x -= accelSize.cx;
            else
                x -= m_parentMenu->GetMaxAccelWidth();

            int y = rcText.top + (rcText.bottom - rcText.top - accelSize.cy) / 2;

            ::DrawState(hdc, NULL, NULL, wxMSW_CONV_LPARAM(accel),
                        accel.length(), x, y, 0, 0, flags);
        }
    }


    // draw the bitmap

    RECT rcImg;
    SetRect(&rcImg,
            rect.left   + data->ItemMargin.cxLeftWidth
                        + data->CheckBgMargin.cxLeftWidth
                        + data->CheckMargin.cxLeftWidth,
            rect.top    + data->ItemMargin.cyTopHeight
                        + data->CheckBgMargin.cyTopHeight
                        + data->CheckMargin.cyTopHeight,
            rect.left   + data->ItemMargin.cxLeftWidth
                        + data->CheckBgMargin.cxLeftWidth
                        + data->CheckMargin.cxLeftWidth
                        + imgWidth,
            rect.bottom - data->ItemMargin.cyBottomHeight
                        - data->CheckBgMargin.cyBottomHeight
                        - data->CheckMargin.cyBottomHeight);

    if ( IsCheckable() && !m_bmpChecked.IsOk() )
    {
        if ( stat & wxODChecked )
        {
            DrawStdCheckMark((WXHDC)hdc, &rcImg, stat);
        }
    }
    else
    {
        wxBitmap bmp;

        if ( stat & wxODDisabled )
        {
            bmp = GetDisabledBitmap();
        }

        if ( !bmp.IsOk() )
        {
            // for not checkable bitmaps we should always use unchecked one
            // because their checked bitmap is not set
            bmp = GetBitmap(!IsCheckable() || (stat & wxODChecked));

#if wxUSE_IMAGE
            if ( bmp.IsOk() && stat & wxODDisabled )
            {
                // we need to grey out the bitmap as we don't have any specific
                // disabled bitmap
                wxImage imgGrey = bmp.ConvertToImage().ConvertToGreyscale();
                if ( imgGrey.IsOk() )
                    bmp = wxBitmap(imgGrey);
            }
#endif // wxUSE_IMAGE
        }

        if ( bmp.IsOk() )
        {
            wxMemoryDC dcMem(&dc);
            dcMem.SelectObjectAsSource(bmp);

            // center bitmap
            int nBmpWidth  = bmp.GetWidth(),
                nBmpHeight = bmp.GetHeight();

            int x = rcImg.left + (imgWidth - nBmpWidth) / 2;
            int y = rcImg.top  + (rcImg.bottom - rcImg.top - nBmpHeight) / 2;
            dc.Blit(x, y, nBmpWidth, nBmpHeight, &dcMem, 0, 0, wxCOPY, true);
        }
    }

    return true;

}
Esempio n. 17
0
/*
 * FIXME:
 * - Drawing of WS_BORDER after scrollbars
 * - Correct drawing of size-box
 */
LRESULT
DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active)
{
   HDC hDC;
   DWORD Style, ExStyle;
   HWND Parent;
   RECT ClientRect, WindowRect, CurrentRect, TempRect;

   if (!IsWindowVisible(hWnd))
      return 0;

   Style = GetWindowLongPtrW(hWnd, GWL_STYLE);

   hDC = GetDCEx(hWnd, hRgn, DCX_WINDOW | DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN);
   if (hDC == 0)
   {
      return 0;
   }

   Parent = GetParent(hWnd);
   ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE);
   if (Active == -1)
   {
      if (ExStyle & WS_EX_MDICHILD)
      {
         Active = IsChild(GetForegroundWindow(), hWnd);
         if (Active)
            Active = (hWnd == (HWND)SendMessageW(Parent, WM_MDIGETACTIVE, 0, 0));
      }
      else
      {
         Active = (GetForegroundWindow() == hWnd);
      }
   }
   GetWindowRect(hWnd, &WindowRect);
   GetClientRect(hWnd, &ClientRect);

   CurrentRect.top = CurrentRect.left = 0;
   CurrentRect.right = WindowRect.right - WindowRect.left;
   CurrentRect.bottom = WindowRect.bottom - WindowRect.top;

   /* Draw outer edge */
   if (UserHasWindowEdge(Style, ExStyle))
   {
      DrawEdge(hDC, &CurrentRect, EDGE_RAISED, BF_RECT | BF_ADJUST);
   } else
   if (ExStyle & WS_EX_STATICEDGE)
   {
#if 0
      DrawEdge(hDC, &CurrentRect, BDR_SUNKENINNER, BF_RECT | BF_ADJUST | BF_FLAT);
#else
      SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
      PatBlt(hDC, CurrentRect.left, CurrentRect.top, CurrentRect.right - CurrentRect.left, 1, PATCOPY);
      PatBlt(hDC, CurrentRect.left, CurrentRect.top, 1, CurrentRect.bottom - CurrentRect.top, PATCOPY);

      SelectObject(hDC, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
      PatBlt(hDC, CurrentRect.left, CurrentRect.bottom - 1, CurrentRect.right - CurrentRect.left, 1, PATCOPY);
      PatBlt(hDC, CurrentRect.right - 1, CurrentRect.top, 1, CurrentRect.bottom - CurrentRect.top, PATCOPY);

      InflateRect(&CurrentRect, -1, -1);
#endif
   }

   /* Firstly the "thick" frame */
   if ((Style & WS_THICKFRAME) && !(Style & WS_MINIMIZE))
   {
      LONG Width =
         (GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME)) *
         GetSystemMetrics(SM_CXBORDER);
      LONG Height =
         (GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYDLGFRAME)) *
         GetSystemMetrics(SM_CYBORDER);

      SelectObject(hDC, GetSysColorBrush(Active ? COLOR_ACTIVEBORDER :
         COLOR_INACTIVEBORDER));

      /* Draw frame */
      PatBlt(hDC, CurrentRect.left, CurrentRect.top, CurrentRect.right - CurrentRect.left, Height, PATCOPY);
      PatBlt(hDC, CurrentRect.left, CurrentRect.top, Width, CurrentRect.bottom - CurrentRect.top, PATCOPY);
#ifdef __REACTOS__
      PatBlt(hDC, CurrentRect.left, CurrentRect.bottom - 1, CurrentRect.right - CurrentRect.left, -Height, PATCOPY);
      PatBlt(hDC, CurrentRect.right - 1, CurrentRect.top, -Width, CurrentRect.bottom - CurrentRect.top, PATCOPY);
#else
      PatBlt(hDC, CurrentRect.left, CurrentRect.bottom, CurrentRect.right - CurrentRect.left, -Height, PATCOPY);
      PatBlt(hDC, CurrentRect.right, CurrentRect.top, -Width, CurrentRect.bottom - CurrentRect.top, PATCOPY);
#endif

      InflateRect(&CurrentRect, -Width, -Height);
   }

   /* Now the other bit of the frame */
   if (Style & (WS_DLGFRAME | WS_BORDER) || ExStyle & WS_EX_DLGMODALFRAME)
   {
      DWORD Width = GetSystemMetrics(SM_CXBORDER);
      DWORD Height = GetSystemMetrics(SM_CYBORDER);

      SelectObject(hDC, GetSysColorBrush(
         (ExStyle & (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE)) ? COLOR_3DFACE :
         (ExStyle & WS_EX_STATICEDGE) ? COLOR_WINDOWFRAME :
         (Style & (WS_DLGFRAME | WS_THICKFRAME)) ? COLOR_3DFACE :
         COLOR_WINDOWFRAME));

      /* Draw frame */
      PatBlt(hDC, CurrentRect.left, CurrentRect.top, CurrentRect.right - CurrentRect.left, Height, PATCOPY);
      PatBlt(hDC, CurrentRect.left, CurrentRect.top, Width, CurrentRect.bottom - CurrentRect.top, PATCOPY);
#ifdef __REACTOS__
      PatBlt(hDC, CurrentRect.left, CurrentRect.bottom - 1, CurrentRect.right - CurrentRect.left, -Height, PATCOPY);
      PatBlt(hDC, CurrentRect.right - 1, CurrentRect.top, -Width, CurrentRect.bottom - CurrentRect.top, PATCOPY);
#else
      PatBlt(hDC, CurrentRect.left, CurrentRect.bottom, CurrentRect.right - CurrentRect.left, -Height, PATCOPY);
      PatBlt(hDC, CurrentRect.right, CurrentRect.top, -Width, CurrentRect.bottom - CurrentRect.top, PATCOPY);
#endif

      InflateRect(&CurrentRect, -Width, -Height);
   }

   /* Draw caption */
   if ((Style & WS_CAPTION) == WS_CAPTION)
   {
      DWORD CaptionFlags = DC_ICON | DC_TEXT | DC_BUTTONS;
      HPEN PreviousPen;
      BOOL Gradient = FALSE;

      if(SystemParametersInfoW(SPI_GETGRADIENTCAPTIONS, 0, &Gradient, 0) && Gradient)
      {
        CaptionFlags |= DC_GRADIENT;
      }

      TempRect = CurrentRect;

      if (Active)
      {
         CaptionFlags |= DC_ACTIVE;
      }

      if (ExStyle & WS_EX_TOOLWINDOW)
      {
         CaptionFlags |= DC_SMALLCAP;
         TempRect.bottom = TempRect.top + GetSystemMetrics(SM_CYSMCAPTION) - 1;
         CurrentRect.top += GetSystemMetrics(SM_CYSMCAPTION);
      }
      else
      {
         TempRect.bottom = TempRect.top + GetSystemMetrics(SM_CYCAPTION) - 1;
         CurrentRect.top += GetSystemMetrics(SM_CYCAPTION);
      }

      NtUserDrawCaption(hWnd, hDC, &TempRect, CaptionFlags);

      /* Draw buttons */
      if (Style & WS_SYSMENU)
      {
         UserDrawCaptionButton(hWnd, &TempRect, Style, ExStyle, hDC, FALSE, DFCS_CAPTIONCLOSE);
         if ((Style & (WS_MAXIMIZEBOX | WS_MINIMIZEBOX)) && !(ExStyle & WS_EX_TOOLWINDOW))
         {
            UserDrawCaptionButton(hWnd, &TempRect, Style, ExStyle, hDC, FALSE, DFCS_CAPTIONMIN);
            UserDrawCaptionButton(hWnd, &TempRect, Style, ExStyle, hDC, FALSE, DFCS_CAPTIONMAX);
         }
      }
      if(!(Style & WS_MINIMIZE))
      {
        /* Line under caption */
        PreviousPen = SelectObject(hDC, GetStockObject(DC_PEN));
        SetDCPenColor(hDC, GetSysColor(
           ((ExStyle & (WS_EX_STATICEDGE | WS_EX_CLIENTEDGE |
                        WS_EX_DLGMODALFRAME)) == WS_EX_STATICEDGE) ?
           COLOR_WINDOWFRAME : COLOR_3DFACE));
        MoveToEx(hDC, TempRect.left, TempRect.bottom, NULL);
        LineTo(hDC, TempRect.right, TempRect.bottom);
        SelectObject(hDC, PreviousPen);
      }
   }

   if(!(Style & WS_MINIMIZE))
   {
     HMENU menu = GetMenu(hWnd);
     /* Draw menu bar */
     if (menu && !(Style & WS_CHILD))
     {
        TempRect = CurrentRect;
        TempRect.bottom = TempRect.top + (UINT)NtUserxSetMenuBarHeight(menu, 0);
        CurrentRect.top += MenuDrawMenuBar(hDC, &TempRect, hWnd, FALSE);
     }

     if (ExStyle & WS_EX_CLIENTEDGE)
     {
        DrawEdge(hDC, &CurrentRect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
     }

     /* Draw the scrollbars */
     if ((Style & WS_VSCROLL) && (Style & WS_HSCROLL) &&
         IntIsScrollBarVisible(hWnd, OBJID_VSCROLL) && IntIsScrollBarVisible(hWnd, OBJID_HSCROLL))
     {
        RECT ParentClientRect;

        TempRect = CurrentRect;
        if (ExStyle & WS_EX_LEFTSCROLLBAR)
           TempRect.right = TempRect.left + GetSystemMetrics(SM_CXVSCROLL);
        else
           TempRect.left = TempRect.right - GetSystemMetrics(SM_CXVSCROLL);
        TempRect.top = TempRect.bottom - GetSystemMetrics(SM_CYHSCROLL);
        FillRect(hDC, &TempRect, GetSysColorBrush(COLOR_BTNFACE));
        /* FIXME: Correct drawing of size-box with WS_EX_LEFTSCROLLBAR */
        if(Parent)
          GetClientRect(Parent, &ParentClientRect);
        if (HASSIZEGRIP(Style, ExStyle, GetWindowLongPtrW(Parent, GWL_STYLE), WindowRect, ParentClientRect))
        {
           DrawFrameControl(hDC, &TempRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
        }
        IntDrawScrollBar(hWnd, hDC, SB_VERT);
        IntDrawScrollBar(hWnd, hDC, SB_HORZ);
     }
     else
     {
        if (Style & WS_VSCROLL && IntIsScrollBarVisible(hWnd, OBJID_VSCROLL))
           IntDrawScrollBar(hWnd, hDC, SB_VERT);
        else if (Style & WS_HSCROLL && IntIsScrollBarVisible(hWnd, OBJID_HSCROLL))
           IntDrawScrollBar(hWnd, hDC, SB_HORZ);
     }
   }

   ReleaseDC(hWnd, hDC);
   if (hRgn != HRGN_WINDOW)
      DeleteObject(hRgn); // We use DCX_KEEPCLIPRGN

   return 0; // For WM_NCPAINT message, return 0.
}
Esempio n. 18
0
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent,i;
	PAINTSTRUCT ps;
	HDC hdc;
	char* str[100];
	RECT rt;

	switch (message) 
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam); 
		wmEvent = HIWORD(wParam); 
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
			break;
		case IDM_EXIT:
			ILibStopChain(TheChain);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:

		// Paint the complete screen here. Quite workout to get the UI looking
		// event half decent using Win32 directly.
		hdc = BeginPaint(hWnd, &ps);
		GetClientRect(hWndMainWindow, &rt);

		// Paint the top portion of the screen
		RECT r;
		r.left = 1;
		r.right = rt.right-1;
		r.top = 0;
		r.bottom = 40;
		FillRect(hdc,&r,GetSysColorBrush(COLOR_SCROLLBAR));
		DrawEdge(hdc,&r,EDGE_RAISED,BF_RECT);
		DrawIcon(hdc,8,5,HICON_MEDIASERVER2);
		SetBkColor(hdc,GetSysColor(COLOR_SCROLLBAR));

		// Paint the title
		r.left = 50;
		r.right = rt.right-1;
		r.top = 4;
		r.bottom = 50;
		DrawText(hdc,TEXT("Intel Micro Media Server"),-1,&r,0);

		// Paint the transfer count stat label & value
		r.left = 50;
		r.right = rt.right-1;
		r.top = 20;
		r.bottom = 50;
		if (MmsCurrentTransfersCount == 0)
		{
			DrawText(hdc,TEXT("No File Transfers          "),-1,&r,0);
		}
		if (MmsCurrentTransfersCount == 1)
		{
			DrawText(hdc,TEXT("1 File Transfer          "),-1,&r,0);
		}
		if (MmsCurrentTransfersCount > 1)
		{
			sprintf((char*)str,"%d File Transfers        ",MmsCurrentTransfersCount);
			DrawText(hdc,(LPCSTR)str,-1,&r,0);
		}

		// Paint the main portion of the screen
		r.left = 1;
		r.right = rt.right-1;
		r.top = 42;
		r.bottom = 267;
		FillRect(hdc,&r,GetSysColorBrush(COLOR_SCROLLBAR));

		// Paint global media server stats labels
		r.left = 8;
		r.right = 150;
		r.top = 50;
		r.bottom = 70;
		DrawText(hdc,TEXT("Browse Requests"),-1,&r,0);
		r.left = 8;
		r.right = 150;
		r.top = 70;
		r.bottom = 90;
		DrawText(hdc,TEXT("HTTP Requests"),-1,&r,0);

		// Paint global media server stats values
		sprintf((char*)str,"%d",MmsBrowseCount);
		r.left = 180;
		r.right = rt.right-5;
		r.top = 50;
		r.bottom = 70;
		DrawText(hdc,(LPCSTR)str,-1,&r,DT_RIGHT);
		sprintf((char*)str,"%d",MmsHttpRequestCount);
		r.left = 180;
		r.right = rt.right-5;
		r.top = 70;
		r.bottom = 90;
		DrawText(hdc,(LPCSTR)str,-1,&r,DT_RIGHT);

		// Paint the transfer window edge
		r.left = 2;
		r.right = rt.right-1;
		r.top = 94;
		r.bottom = 264;
		DrawEdge(hdc,&r,EDGE_SUNKEN,BF_RECT);

		// Paint the white transfer window
		r.left = 4;
		r.right = rt.right-5;
		r.top = 96;
		r.bottom = 262;
		FillRect(hdc,&r,GetSysColorBrush(COLOR_MENU));

		// Draw all of the active transfers on the screen (up to 5)
		for (i=0;i<5;i++)
		{
			DrawTransferInfo(hdc,i,g_DownloadStatsMapping[i]);
		}

		EndPaint(hWnd, &ps);
		break;
	case WM_CREATE:
		// Clear up all of the active transfers.
		for (i=0;i<DOWNLOAD_STATS_ARRAY_SIZE;i++) {g_DownloadStatsMapping[i] = -1;}

		// Load all of the icon resources we will need to draw the UI.
		HICON_MEDIASERVER  = LoadIcon(g_hInst, (LPCTSTR)IDI_MEDIASERVER);
		HICON_MEDIASERVER2 = LoadIcon(g_hInst, (LPCTSTR)IDI_MEDIASERVER2);
		HICON_RIGHTARROW   = LoadIcon(g_hInst, (LPCTSTR)IDI_RIGHTARROW);
		HICON_LEFTARROW    = LoadIcon(g_hInst, (LPCTSTR)IDI_LEFTARROW);

		CreateThread(NULL, 0, &UPnPMain, hWnd, 0, NULL ); 
		break;
	case WM_CLOSE:
		ILibStopChain(TheChain);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Esempio n. 19
0
LRESULT dlgWndAskPIN::ProcecEvent
			(	UINT		uMsg,			// Message For This Window
				WPARAM		wParam,			// Additional Message Information
				LPARAM		lParam )		// Additional Message Information
{
	PAINTSTRUCT ps;
	RECT rect;

	switch( uMsg )
	{ 
		case WM_COMMAND:
		{
			switch( LOWORD(wParam) )
			{
				case IDC_EDIT:
				{
					if( EN_CHANGE == HIWORD(wParam) )
					{
						long len = (long)SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_GETTEXTLENGTH, 0, 0 );
						EnableWindow( GetDlgItem( m_hWnd, IDOK ), ( (unsigned int)len >= m_ulPinMinLen ) );
					}
					return TRUE;
				}

				case IDB_OK:
					GetPinResult();
					dlgResult = eIDMW::DLG_OK;
					close();
					return TRUE;

				case IDB_CANCEL:
					dlgResult = eIDMW::DLG_CANCEL;
					close();
					return TRUE;

				default:
					unsigned short tmp = LOWORD(wParam);
					if( tmp >= IDB_KeypadStart && tmp < IDB_KeypadEnd ) // Keypad Buttons
					{
						wchar_t nameBuf[128];
						SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_GETTEXT, (WPARAM)(sizeof(nameBuf)), (LPARAM)nameBuf );
						size_t iPos = wcslen( nameBuf );
						if( iPos >= m_ulPinMaxLen )
							return TRUE;
						if( tmp == IDB_KeypadEnd - 1 ) // Keypad Button 0
						{
							nameBuf[ iPos++ ] = L'0';
						}
						else // Keypad Button 1 to 9
						{
							nameBuf[ iPos++ ] = 49 + tmp - IDB_KeypadStart;
						}
						nameBuf[ iPos++ ] = NULL;
						SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_SETTEXT, 0, (LPARAM)nameBuf );
						return TRUE;
					}
					if( tmp == IDB_KeypadEnd ) // Keypad Button CE
					{
						SendMessage( GetDlgItem( m_hWnd, IDC_EDIT ), WM_SETTEXT, 0, (LPARAM)"" );
						//clear
					}
					return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
			}
		}

		case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
			if( lpDrawItem->CtlType & ODT_BUTTON )
			{
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - WM_DRAWITEM lParam=%x, wParam=%ld",lParam,wParam);
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - Entering WM_DRAWITEM lpDrawItem->hDC=%ld",lpDrawItem->hDC);

				FillRect( lpDrawItem->hDC, &lpDrawItem->rcItem, CreateSolidBrush( GetSysColor( COLOR_3DFACE ) ) );
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - WM_DRAWITEM top=%ld, bottom=%ld, left=%ld, right=%ld",
					//lpDrawItem->rcItem.top,lpDrawItem->rcItem.bottom,lpDrawItem->rcItem.left,lpDrawItem->rcItem.right);

				HDC hdcMem = CreateCompatibleDC( lpDrawItem->hDC );
				SelectObject( hdcMem , ImageKP_BTN[11] );
				MaskBlt( lpDrawItem->hDC, (lpDrawItem->rcItem.right - KP_BTN_SIZE) / 2, (lpDrawItem->rcItem.bottom - KP_BTN_SIZE) / 2,
					KP_BTN_SIZE, KP_BTN_SIZE, hdcMem, 0, 0,
					ImageKP_BTN_Mask, 0, 0, MAKEROP4( SRCCOPY, 0x00AA0029 ) );

				unsigned int iNum = 0;
				if( lpDrawItem->CtlID == IDB_KeypadEnd )
				{
					iNum = 10;
				}
				else if( lpDrawItem->CtlID >= IDB_KeypadStart && lpDrawItem->CtlID < IDB_KeypadEnd -2 )
				{
					iNum = lpDrawItem->CtlID - IDB_KeypadStart +1;
				}
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - WM_DRAWITEM iNum=%ld",iNum);

				SelectObject( hdcMem , ImageKP_BTN[iNum] );
				BitBlt( lpDrawItem->hDC, (lpDrawItem->rcItem.right - KP_LBL_SIZE) / 2, (lpDrawItem->rcItem.bottom - KP_LBL_SIZE) / 2, 
						KP_LBL_SIZE, KP_LBL_SIZE, hdcMem, 0, 0, SRCCOPY );
				DeleteDC(hdcMem);

				if( lpDrawItem->itemState & ODS_SELECTED )
					DrawEdge( lpDrawItem->hDC, &lpDrawItem->rcItem, EDGE_RAISED, BF_RECT );
				
				if( lpDrawItem->itemState & ODS_HOTLIGHT )
					DrawEdge( lpDrawItem->hDC, &lpDrawItem->rcItem, EDGE_SUNKEN, BF_RECT );
				
				if( lpDrawItem->itemState & ODS_FOCUS )
				{
					GetClientRect( lpDrawItem->hwndItem, &rect );
					rect.left += 2;
					rect.right -= 2;
					rect.top += 2;
					rect.bottom -= 2;
					DrawFocusRect( lpDrawItem->hDC, &rect );
				}
				//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - Leaving WM_DRAWITEM lpDrawItem->hDC=%ld",lpDrawItem->hDC);
				return TRUE;
			}
			break;
		}

		case WM_SIZE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_SIZE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return 0;
			break;
		}

		case WM_PAINT:
		{
			//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : WM_PAINT");
			m_hDC = BeginPaint( m_hWnd, &ps );

			HDC hdcMem;

			hdcMem = CreateCompatibleDC( m_hDC );

			HGDIOBJ oldObj = SelectObject( hdcMem , ImagePIN );

			GetClientRect( m_hWnd, &rect );
			MaskBlt( m_hDC, 4, m_KeypadHeight + 8,
				IMG_SIZE, IMG_SIZE,	hdcMem, 0, 0,
				ImagePIN_Mask, 0, 0, MAKEROP4( SRCCOPY, 0x00AA0029 ) );
		
			
			SelectObject( hdcMem, oldObj );
			DeleteDC(hdcMem);

			if( m_UseKeypad )
			{
				GetClientRect( m_hWnd, &rect );
				rect.left += 8;
				rect.right -= 8;
				rect.top += 8;
				rect.bottom = m_KeypadHeight;

				DrawEdge( m_hDC, &rect, EDGE_RAISED, BF_RECT );
			}

			GetClientRect( m_hWnd, &rect );
			rect.left += IMG_SIZE + 16;
			rect.top = m_KeypadHeight + 8;
			rect.right -= 8;
			rect.bottom = rect.bottom - 40;
			SetBkColor( m_hDC, GetSysColor( COLOR_3DFACE ) );
			SelectObject( m_hDC, TextFont );
			DrawText( m_hDC, szHeader, -1, &rect, DT_WORDBREAK );

			EndPaint( m_hWnd, &ps );

			SetForegroundWindow( m_hWnd );

			return 0;
		}

		case WM_ACTIVATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_ACTIVATE (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		case WM_NCACTIVATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_NCACTIVATE (wParam=%X, lParam=%X)",wParam,lParam);

			//if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			//{
			//	ShowWindow( m_hWnd, SW_SHOW );
			//	SetFocus( m_hWnd );
			//	return 0;
			//}
			if(!wParam)
			{
				SetFocus( m_hWnd );
				return 0;
			}
			break;
		}

		case WM_SETFOCUS:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_SETFOCUS (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		case WM_KILLFOCUS:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_KILLFOCUS (wParam=%X, lParam=%X)",wParam,lParam);

			//if( !IsIconic( m_hWnd ) && m_ModalHold && Active_hWnd == m_hWnd )
			//{
			//	if( GetParent((HWND)wParam ) != m_hWnd )
			//	{
			//		SetFocus( m_hWnd );
			//		return 0;
			//	}
			//}
			break;
		}

		case WM_CREATE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_CREATE (wParam=%X, lParam=%X)",wParam,lParam);

			HMENU hSysMenu;

			hSysMenu = GetSystemMenu( m_hWnd, FALSE );
			EnableMenuItem( hSysMenu, 3, MF_BYPOSITION | MF_GRAYED );
			SendMessage( m_hWnd, DM_SETDEFID, (WPARAM) IDC_EDIT, (LPARAM) 0); 

			return DefWindowProc( (HWND)((CREATESTRUCT *)lParam)->lpCreateParams, uMsg, wParam, lParam );
		}

		case WM_CLOSE:
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_CLOSE (wParam=%X, lParam=%X)",wParam,lParam);

			if( IsIconic( m_hWnd ) )
				return DefWindowProc( m_hWnd, uMsg, wParam, lParam );

			ShowWindow( m_hWnd, SW_MINIMIZE );
			return 0;
		}

		case WM_DESTROY: 
		{
			MWLOG(LEV_DEBUG, MOD_DLG, L"  --> dlgWndAskPIN::ProcecEvent WM_DESTROY (wParam=%X, lParam=%X)",wParam,lParam);
			break;
		}

		default:
		{
			return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
		}
	}
	return DefWindowProc( m_hWnd, uMsg, wParam, lParam );
}
Esempio n. 20
0
INT_PTR CALLBACK
AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    HWND hWnd;
    HDC hDC;
    RECT rcClient, rcRect;
    char *owner, *org;

    switch (uMsg)
    {
    case WM_NOTIFY:
        switch(((LPNMHDR)lParam)->code)
        {
        case PSN_APPLY:
            /*save registration info to registry */
            owner = get_text(hDlg, IDC_ABT_OWNER);
            org   = get_text(hDlg, IDC_ABT_ORG);

            set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
                        "RegisteredOwner", owner ? owner : "");
            set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
                        "RegisteredOrganization", org ? org : "");
            set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
                        "RegisteredOwner", owner ? owner : "");
            set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
                        "RegisteredOrganization", org ? org : "");
            apply();

            HeapFree(GetProcessHeap(), 0, owner);
            HeapFree(GetProcessHeap(), 0, org);
            break;

        case NM_CLICK:
        case NM_RETURN:
            if(wParam == IDC_ABT_WEB_LINK)
                ShellExecuteA(NULL, "open", PACKAGE_URL, NULL, NULL, SW_SHOW);
            break;
        }
        break;

    case WM_INITDIALOG:

        hDC = GetDC(hDlg);

        /* read owner and organization info from registry, load it into text box */
        owner = get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
                            "RegisteredOwner", "");
        org =   get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
                            "RegisteredOrganization", "");

        SetDlgItemText(hDlg, IDC_ABT_OWNER, owner);
        SetDlgItemText(hDlg, IDC_ABT_ORG, org);

        SendMessage(GetParent(hDlg), PSM_UNCHANGED, 0, 0);

        HeapFree(GetProcessHeap(), 0, owner);
        HeapFree(GetProcessHeap(), 0, org);

        /* prepare the panel */
        hWnd = GetDlgItem(hDlg, IDC_ABT_PANEL);
        if(hWnd)
        {
            GetClientRect(hDlg, &rcClient);
            GetClientRect(hWnd, &rcRect);
            MoveWindow(hWnd, 0, 0, rcClient.right, rcRect.bottom, FALSE);

            logo = LoadImageW((HINSTANCE)GetWindowLongPtrW(hDlg, GWLP_HINSTANCE),
                MAKEINTRESOURCEW(IDI_LOGO), IMAGE_ICON, 0, 0, LR_SHARED);
        }

        /* prepare the title text */
        hWnd = GetDlgItem(hDlg, IDC_ABT_TITLE_TEXT);
        if(hWnd)
        {
            titleFont = CreateFont(
                -MulDiv(24, GetDeviceCaps(hDC, LOGPIXELSY), 72),
                0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0,
                "Tahoma");
            SendMessage(hWnd, WM_SETFONT, (WPARAM)titleFont, TRUE);
            SetWindowTextA(hWnd, PACKAGE_NAME);
        }
        SetDlgItemTextA(hDlg, IDC_ABT_PANEL_TEXT, PACKAGE_VERSION);

        /* prepare the web link */
        SetDlgItemTextA(hDlg, IDC_ABT_WEB_LINK, "<a href=\"" PACKAGE_URL "\">" PACKAGE_URL "</a>");

        ReleaseDC(hDlg, hDC);

        break;

    case WM_DESTROY:
        if(logo)
        {
            DestroyIcon(logo);
            logo = NULL;
        }

        if(titleFont)
        {
            DeleteObject(titleFont);
            titleFont = NULL;
        }

        break;

    case WM_COMMAND:
        switch(HIWORD(wParam))
        {
        case EN_CHANGE:
            /* enable apply button */
            SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
            break;
        }
        break;

    case WM_DRAWITEM:
        if(wParam == IDC_ABT_PANEL)
        {
            LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam;
            FillRect(pDIS->hDC, &pDIS->rcItem, (HBRUSH) (COLOR_WINDOW+1));
            DrawIconEx(pDIS->hDC, 0, 0, logo, 0, 0, 0, 0, DI_IMAGE);
            DrawEdge(pDIS->hDC, &pDIS->rcItem, EDGE_SUNKEN, BF_BOTTOM);
        }
        break;

    case WM_CTLCOLORSTATIC:
        switch(GetDlgCtrlID((HWND)lParam))
        {
        case IDC_ABT_TITLE_TEXT:
            /* set the title to a wine color */
            SetTextColor((HDC)wParam, 0x0000007F);
        case IDC_ABT_PANEL_TEXT:
        case IDC_ABT_LICENSE_TEXT:
        case IDC_ABT_WEB_LINK:
            return (INT_PTR)CreateSolidBrush(GetSysColor(COLOR_WINDOW));
        }
        break;
    }

    return FALSE;
}
Esempio n. 21
0
static void winFrameDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem)
{ 
  iupwinBitmapDC bmpDC;
  HDC hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, drawitem->rcItem.right-drawitem->rcItem.left, 
                                                            drawitem->rcItem.bottom-drawitem->rcItem.top);

  iupwinDrawParentBackground(ih, hDC, &drawitem->rcItem);

  if (iupAttribGet(ih, "_IUPFRAME_HAS_TITLE"))
  {
    int x, y;
    HFONT hOldFont, hFont = (HFONT)iupwinGetHFontAttrib(ih);
    int txt_height = iupFrameGetTitleHeight(ih);
    COLORREF fgcolor;
    SIZE size;

    char* title = iupdrvBaseGetTitleAttrib(ih);
    if (!title) title = "";

    x = drawitem->rcItem.left+7;
    y = drawitem->rcItem.top;

    hOldFont = SelectObject(hDC, hFont);
    GetTextExtentPoint32(hDC, title, strlen(title), &size);
    ExcludeClipRect(hDC, x-2, y, x+size.cx+2, y+size.cy);

    drawitem->rcItem.top += txt_height/2;
    if (iupwin_comctl32ver6)
      iupwinDrawThemeFrameBorder(ih->handle, hDC, &drawitem->rcItem, drawitem->itemState);
    else
      DrawEdge(hDC, &drawitem->rcItem, EDGE_ETCHED, BF_RECT);

    SelectClipRgn(hDC, NULL);

    if (drawitem->itemState & ODS_DISABLED)
      fgcolor = GetSysColor(COLOR_GRAYTEXT);
    else
    {
      unsigned char r, g, b;
      char* color = iupAttribGetInherit(ih, "FGCOLOR");
      if (!color)
      {
        if (!iupwinDrawGetThemeFrameFgColor(ih->handle, &fgcolor))
          fgcolor = 0;  /* black */
      }
      else
      {
        if (iupStrToRGB(color, &r, &g, &b))
          fgcolor = RGB(r,g,b);
        else
          fgcolor = 0;  /* black */
      }
    }

    winFrameDrawText(hDC, title, x, y, fgcolor);

    SelectObject(hDC, hOldFont);
  }
  else
  {
    char* value = iupAttribGetStr(ih, "SUNKEN");
    if (iupStrBoolean(value))
      DrawEdge(hDC, &drawitem->rcItem, EDGE_SUNKEN, BF_RECT);
    else
      DrawEdge(hDC, &drawitem->rcItem, EDGE_ETCHED, BF_RECT);
  }

  iupwinDrawDestroyBitmapDC(&bmpDC);
}
Esempio n. 22
0
static void PaintWorker(TBBUTTONDATA *bct, HDC hdcPaint, POINT *pOffset)
{
	if (!hdcPaint)
		return;  //early exit

	POINT offset;
	if (pOffset)
		offset = *pOffset;
	else
		offset.x = offset.y = 0;

	RECT rcClient;
	GetClientRect(bct->hwnd, &rcClient);
	int width = rcClient.right - rcClient.left;
	int height = rcClient.bottom - rcClient.top;

	HBITMAP hbmMem = NULL;
	HBITMAP hbmOld = NULL;
	HDC hdcMem = pOffset ? hdcPaint : CreateCompatibleDC(hdcPaint);
	HFONT hOldFont = (HFONT)SelectObject(hdcMem, bct->hFont);
	if (!pOffset) {
		hbmMem = ske_CreateDIB32(width, height);
		hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem);
	}
	else OffsetRect(&rcClient, offset.x, offset.y);

	if (!g_CluiData.fDisableSkinEngine) {
		char szRequest[128];
		/* painting */
		mir_snprintf(szRequest, "Button,ID=%s,Hovered=%s,Pressed=%s,Focused=%s",
			bct->szButtonID,				// ID		
			b2str(bct->stateId == PBS_HOT),	// Hovered
			b2str(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE),	// Pressed
			b2str(bct->bFocused));		// Focused

		SkinDrawGlyph(hdcMem, &rcClient, &rcClient, szRequest);
	}
	else if (xpt_IsThemed(bct->hThemeToolbar)) {
		RECT *rc = &rcClient;
		int state = IsWindowEnabled(bct->hwnd) ? /*(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE) ? PBS_PRESSED :*/ (bct->stateId == PBS_NORMAL && bct->bIsDefault ? PBS_DEFAULTED : bct->stateId) : PBS_DISABLED;
		xpt_DrawTheme(bct->hThemeToolbar, bct->hwnd, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rc, rc);
	}
	else {
		HBRUSH hbr = NULL;

		if (bct->stateId == PBS_PRESSED || bct->stateId == PBS_HOT)
			hbr = GetSysColorBrush(COLOR_3DLIGHT);
		else {
			RECT btnRect;
			POINT pt = { 0 };
			int ret;
			HWND hwndParent = GetParent(bct->hwnd);
			HDC dc = CreateCompatibleDC(NULL);
			HBITMAP memBM, oldBM;
			GetWindowRect(hwndParent, &btnRect);
			memBM = ske_CreateDIB32(btnRect.right - btnRect.left, btnRect.bottom - btnRect.top);
			oldBM = (HBITMAP)SelectObject(dc, memBM);
			ret = SendMessage(hwndParent, WM_ERASEBKGND, (WPARAM)dc, 0);
			GetWindowRect(bct->hwnd, &btnRect);
			ClientToScreen(hwndParent, &pt);
			OffsetRect(&btnRect, -pt.x, -pt.y);
			if (ret)
				BitBlt(hdcMem, 0, 0, btnRect.right - btnRect.left, btnRect.bottom - btnRect.top, dc, btnRect.left, btnRect.top, SRCCOPY);
			oldBM = (HBITMAP)SelectObject(dc, oldBM);
			DeleteObject(memBM);
			DeleteDC(dc);
			if (!ret) { //WM_ERASEBKG return false need to paint
				HDC pdc = GetDC(hwndParent);
				HBRUSH oldBrush = (HBRUSH)GetCurrentObject(pdc, OBJ_BRUSH);
				hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)pdc, (LPARAM)hwndParent);
				SelectObject(pdc, oldBrush);
				ReleaseDC(hwndParent, pdc);
			}
		}
		if (hbr) {
			FillRect(hdcMem, &rcClient, hbr);
			DeleteObject(hbr);
		}
		if (bct->stateId == PBS_HOT || bct->bFocused) {
			if (bct->bIsPushed)
				DrawEdge(hdcMem, &rcClient, EDGE_ETCHED, BF_RECT | BF_SOFT);
			else
				DrawEdge(hdcMem, &rcClient, BDR_RAISEDOUTER, BF_RECT | BF_SOFT | BF_FLAT);
		}
		else if (bct->stateId == PBS_PRESSED)
			DrawEdge(hdcMem, &rcClient, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
	}

	RECT  rcTemp = rcClient;  //content rect
	bool  bPressed = (bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE);
	bool  bHasText = (bct->szText[0] != '\0');

	/* formatter */
	if (!g_CluiData.fDisableSkinEngine) {
		/* correct rect according to rcMargins */

		rcTemp.left += bct->rcMargins.left;
		rcTemp.top += bct->rcMargins.top;
		rcTemp.bottom -= bct->rcMargins.bottom;
		rcTemp.right -= bct->rcMargins.right;
	}

	/* reposition button items */
	RECT rcIcon = rcTemp, rcText = rcTemp;
	if (bct->hIcon) {
		if (bHasText) {
			rcIcon.right = rcIcon.left + 16; /* CXSM_ICON */
			rcText.left = rcIcon.right + 2;
		}
		else {
			rcIcon.left += (rcIcon.right - rcIcon.left) / 2 - 8;
			rcIcon.right = rcIcon.left + 16;
		}
	}

	/*	Check sizes*/
	if (bct->hIcon && (rcIcon.right > rcTemp.right || rcIcon.bottom > rcTemp.bottom || rcIcon.left < rcTemp.left || rcIcon.top < rcTemp.top))
		bct->hIcon = NULL;

	if (bHasText && (rcText.right > rcTemp.right || rcText.bottom > rcTemp.bottom || rcText.left < rcTemp.left || rcText.top < rcTemp.top))
		bHasText = FALSE;

	if (bct->hIcon) {
		/* center icon vertically */
		rcIcon.top += (rcClient.bottom - rcClient.top) / 2 - 8; /* CYSM_ICON/2 */
		rcIcon.bottom = rcIcon.top + 16; /* CYSM_ICON */
		/* draw it */
		ske_DrawIconEx(hdcMem, rcIcon.left + bPressed, rcIcon.top + bPressed, bct->hIcon, 16, 16, 0, NULL, DI_NORMAL);
	}

	if (bHasText) {
		BOOL bCentered = TRUE;
		SetBkMode(hdcMem, TRANSPARENT);
		if (bct->nFontID >= 0)
			g_clcPainter.ChangeToFont(hdcMem, NULL, bct->nFontID, NULL);

		RECT TextRequiredRect = rcText;
		ske_DrawText(hdcMem, bct->szText, -1, &TextRequiredRect, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_SINGLELINE);
		if (TextRequiredRect.right - TextRequiredRect.left > rcText.right - rcText.left)
			bCentered = FALSE;

		ske_DrawText(hdcMem, bct->szText, -1, &rcText, (bCentered ? DT_CENTER : 0) | DT_VCENTER | DT_SINGLELINE);
		ske_ResetTextEffect(hdcMem);
	}
	if (!pOffset)
		BitBlt(hdcPaint, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);

	// better to use try/finally but looks like last one is Microsoft specific
	SelectObject(hdcMem, hOldFont);
	if (!pOffset) {
		SelectObject(hdcMem, hbmOld);
		DeleteObject(hbmMem);
		DeleteDC(hdcMem);
	}
}
Esempio n. 23
0
FX_BOOL CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) {
  switch (pParams->m_iPart) {
    case FWL_PART_EDT_Border: {
      DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
      break;
    }
    case FWL_PART_EDT_Edge: {
      DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(),
               &pParams->m_rtPart, &pParams->m_matrix);
      break;
    }
    case FWL_PART_EDT_Background: {
      if (pParams->m_pPath) {
        CFX_Graphics* pGraphics = pParams->m_pGraphics;
        pGraphics->SaveGraphState();
        CFX_Color crSelected(FWL_GetThemeColor(m_dwThemeID) == 0
                                 ? FWLTHEME_COLOR_BKSelected
                                 : FWLTHEME_COLOR_Green_BKSelected);
        pGraphics->SetFillColor(&crSelected);
        pGraphics->FillPath(pParams->m_pPath, FXFILL_WINDING,
                            &pParams->m_matrix);
        pGraphics->RestoreGraphState();
      } else {
        FX_BOOL bStatic =
            pParams->m_dwData == FWL_PARTDATA_EDT_StaticBackground;
        CFX_Path path;
        path.Create();
        path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top,
                          pParams->m_rtPart.width, pParams->m_rtPart.height);
        CFX_Color cr(FWLTHEME_COLOR_Background);
        if (!bStatic) {
          if ((pParams->m_dwStates & FWL_PARTSTATE_EDT_Disable) ==
              FWL_PARTSTATE_EDT_Disable) {
            cr.Set(FWLTHEME_COLOR_EDGERB1);
          } else if ((pParams->m_dwStates & FWL_PARTSTATE_EDT_ReadOnly) ==
                     FWL_PARTSTATE_EDT_ReadOnly) {
            cr.Set(ArgbEncode(255, 236, 233, 216));
          } else {
            cr.Set(0xFFFFFFFF);
          }
        }
        pParams->m_pGraphics->SaveGraphState();
        pParams->m_pGraphics->SetFillColor(&cr);
        pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING,
                                       &pParams->m_matrix);
        pParams->m_pGraphics->RestoreGraphState();
      }
      break;
    }
    case FWL_PART_EDT_CombTextLine: {
      FX_ARGB cr = 0xFF000000;
      FX_FLOAT fWidth = 1.0f;
      CFX_Color crLine(cr);
      pParams->m_pGraphics->SetStrokeColor(&crLine);
      pParams->m_pGraphics->SetLineWidth(fWidth);
      pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix);
      break;
    }
    default: { break; }
  }
  return TRUE;
}
Esempio n. 24
0
void PictureButton::DrawItem(LPDRAWITEMSTRUCT dis)
{
	UINT state = DFCS_BUTTONPUSH;
	int style = GetWindowStyle(_hwnd);

	if (dis->itemState & ODS_DISABLED)
		state |= DFCS_INACTIVE;

	POINT imagePos;
	RECT textRect;
	int dt_flags;

	if (style & BS_BOTTOM) {
		 // align horizontal centered, vertical floating
		imagePos.x = (dis->rcItem.left + dis->rcItem.right - _cx) / 2;
		imagePos.y = dis->rcItem.top + 3;

		textRect.left = dis->rcItem.left + 2;
		textRect.top = dis->rcItem.top + _cy + 4;
		textRect.right = dis->rcItem.right - 4;
		textRect.bottom = dis->rcItem.bottom - 4;

		dt_flags = DT_SINGLELINE|DT_CENTER|DT_VCENTER;
	} else {
		 // horizontal floating, vertical centered
		imagePos.x = dis->rcItem.left + 3;
		imagePos.y = (dis->rcItem.top + dis->rcItem.bottom - _cy)/2;

		textRect.left = dis->rcItem.left + _cx + 4;
		textRect.top = dis->rcItem.top + 2;
		textRect.right = dis->rcItem.right - 4;
		textRect.bottom = dis->rcItem.bottom - 4;

		dt_flags = DT_SINGLELINE|DT_VCENTER/*|DT_CENTER*/;
	}

	if (dis->itemState & ODS_SELECTED) {
		state |= DFCS_PUSHED;
		++imagePos.x;		++imagePos.y;
		++textRect.left;	++textRect.top;
		++textRect.right;	++textRect.bottom;
	}

	if (_flat) {
		FillRect(dis->hDC, &dis->rcItem, _hBrush);

		if (style & BS_FLAT)	// Only with BS_FLAT set, there will be drawn a frame without highlight.
			DrawEdge(dis->hDC, &dis->rcItem, EDGE_RAISED, BF_RECT|BF_FLAT);
	} else
		DrawFrameControl(dis->hDC, &dis->rcItem, DFC_BUTTON, state);

	if (_hIcon)
		DrawIconEx(dis->hDC, imagePos.x, imagePos.y, _hIcon, _cx, _cy, 0, _hBrush, DI_NORMAL);
	else {
		MemCanvas mem_dc;
		BitmapSelection sel(mem_dc, _hBmp);
		BitBlt(dis->hDC, imagePos.x, imagePos.y, _cx, _cy, mem_dc, 0, 0, SRCCOPY);
	}

	TCHAR title[BUFFER_LEN];
	GetWindowText(_hwnd, title, BUFFER_LEN);

	BkMode bk_mode(dis->hDC, TRANSPARENT);

	if (dis->itemState & (ODS_DISABLED|ODS_GRAYED))
		DrawGrayText(dis->hDC, &textRect, title, dt_flags);
	else {
		TextColor lcColor(dis->hDC, GetSysColor(COLOR_BTNTEXT));
		DrawText(dis->hDC, title, -1, &textRect, dt_flags);
	}

	if (dis->itemState & ODS_FOCUS) {
		RECT rect = {
			dis->rcItem.left+3, dis->rcItem.top+3,
			dis->rcItem.right-dis->rcItem.left-4, dis->rcItem.bottom-dis->rcItem.top-4
		};
		if (dis->itemState & ODS_SELECTED) {
			++rect.left;	++rect.top;
			++rect.right;	++rect.bottom;
		}
		DrawFocusRect(dis->hDC, &rect);
	}
}
void EdgeActor::TickRemote(const dtGame::Message &tickMessage)
{
    DrawEdge();
}
Esempio n. 26
0
void FlatButton::DrawItem(LPDRAWITEMSTRUCT dis)
{
	UINT style = DFCS_BUTTONPUSH;

	if (dis->itemState & ODS_DISABLED)
		style |= DFCS_INACTIVE;

	RECT textRect = {dis->rcItem.left+2, dis->rcItem.top+2, dis->rcItem.right-4, dis->rcItem.bottom-4};

	if (dis->itemState & ODS_SELECTED) {
		style |= DFCS_PUSHED;
		++textRect.left;	++textRect.top;
		++textRect.right;	++textRect.bottom;
	}

	FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_BTNFACE));

	 // highlight the button?
	if (_active)
		DrawEdge(dis->hDC, &dis->rcItem, EDGE_ETCHED, BF_RECT);
	else if (GetWindowStyle(_hwnd) & BS_FLAT)	// Only with BS_FLAT there will be drawn a frame to show highlighting.
		DrawEdge(dis->hDC, &dis->rcItem, EDGE_RAISED, BF_RECT|BF_FLAT);

	TCHAR txt[BUFFER_LEN];
	int txt_len = GetWindowText(_hwnd, txt, BUFFER_LEN);

	if (dis->itemState & (ODS_DISABLED|ODS_GRAYED)) {
		COLORREF gray = GetSysColor(COLOR_GRAYTEXT);

		if (gray) {
			{
			TextColor lcColor(dis->hDC, GetSysColor(COLOR_BTNHIGHLIGHT));
			RECT shadowRect = {textRect.left+1, textRect.top+1, textRect.right+1, textRect.bottom+1};
			DrawText(dis->hDC, txt, txt_len, &shadowRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
			}

			BkMode mode(dis->hDC, TRANSPARENT);
			TextColor lcColor(dis->hDC, gray);
			DrawText(dis->hDC, txt, txt_len, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
		} else {
			int old_r = textRect.right;
			int old_b = textRect.bottom;
			DrawText(dis->hDC, txt, txt_len, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER|DT_CALCRECT);
			int x = textRect.left + (old_r-textRect.right)/2;
			int y = textRect.top + (old_b-textRect.bottom)/2;
			int w = textRect.right-textRect.left;
			int h = textRect.bottom-textRect.top;
			s_MyDrawText_Rect.right = w;
			s_MyDrawText_Rect.bottom = h;
			GrayString(dis->hDC, GetSysColorBrush(COLOR_GRAYTEXT), MyDrawText, (LPARAM)txt, txt_len, x, y, w, h);
		}
	} else {
		TextColor lcColor(dis->hDC, _active? _activeColor: _textColor);
		DrawText(dis->hDC, txt, txt_len, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
	}

	if (dis->itemState & ODS_FOCUS) {
		RECT rect = {
			dis->rcItem.left+3, dis->rcItem.top+3,
			dis->rcItem.right-dis->rcItem.left-4, dis->rcItem.bottom-dis->rcItem.top-4
		};
		if (dis->itemState & ODS_SELECTED) {
			++rect.left;	++rect.top;
			++rect.right;	++rect.bottom;
		}
		DrawFocusRect(dis->hDC, &rect);
	}
}
Esempio n. 27
0
/**
 * name:	PaintThemeButton
 * desc:	Draws the none themed button
 * param:	ctl			- BTNCTRL structure for the button
 *			hdcMem		- device context to draw to
 *			rcClient	- rectangle of the whole button
 * return:	nothing
 **/
static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient)
{
	RECT rcText = { 0, 0, 0, 0 };
	TCHAR szText[MAX_PATH] = { 0 };
	WORD ccText;

	// Draw the flat button
	if (ctl->dwStyle & MBS_FLAT) {
		HBRUSH hbr = NULL;
		
		if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
			hbr = GetSysColorBrush(COLOR_3DLIGHT);
		else {
			HDC dc;
			HWND hwndParent;

			hwndParent = GetParent(ctl->hwnd);
			if (dc = GetDC(hwndParent)) {
				hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
				ReleaseDC(hwndParent, dc);
			}
		}
		if (hbr) {
			FillRect(hdcMem, rcClient, hbr);
			DeleteObject(hbr);
		}
		if (ctl->stateId == PBS_HOT || ctl->bFocus) {
			if (ctl->pbState) DrawEdge(hdcMem, rcClient, EDGE_ETCHED, BF_RECT|BF_SOFT);
			else DrawEdge(hdcMem, rcClient, BDR_RAISEDOUTER, BF_RECT|BF_SOFT|BF_FLAT);
		}
		else
		if (ctl->stateId == PBS_PRESSED)
			DrawEdge(hdcMem, rcClient, BDR_SUNKENOUTER, BF_RECT|BF_SOFT);
	}
	else {
		UINT uState = DFCS_BUTTONPUSH|((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0)|((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
		if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON;
		DrawFrameControl(hdcMem, rcClient, DFC_BUTTON, uState);
		// Draw focus rectangle if button has focus
		if (ctl->bFocus) {
			RECT focusRect = *rcClient;
			InflateRect(&focusRect, -3, -3);
			DrawFocusRect(hdcMem, &focusRect);
		}
	}
	// calculate text rect
	{
		SIZE	sizeText;
		HFONT	hOldFont;

		ccText = GetWindowText(ctl->hwnd, szText, SIZEOF(szText));

		if (ccText > 0) {
			hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
			GetTextExtentPoint32(hdcMem, szText, ccText, &sizeText);
			if (ctl->cHot) {
				SIZE sizeHot;
				
				GetTextExtentPoint32A(hdcMem, "&", 1, &sizeHot);
				sizeText.cx -= sizeHot.cx;
			}
			SelectObject(hdcMem, hOldFont);

			rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - sizeText.cx) / 2;
			rcText.top = (rcClient->bottom - rcClient->top - sizeText.cy) / 2;
			rcText.right = rcText.left + sizeText.cx;
			rcText.bottom = rcText.top + sizeText.cy;
			if (ctl->stateId == PBS_PRESSED)
				OffsetRect(&rcText, 1, 1);
		}
	}
	PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText);

	// draw text
	if (ccText > 0) { 
		HFONT hOldFont;

		hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);

		SetBkMode(hdcMem, TRANSPARENT);
		SetTextColor(hdcMem, 
			IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton 
			? ctl->stateId == PBS_HOT
					? GetSysColor(COLOR_HOTLIGHT)
					: GetSysColor(COLOR_BTNTEXT) 
				: GetSysColor(COLOR_GRAYTEXT));

		DrawState(hdcMem, NULL, NULL, (LPARAM)szText, 0, 
			rcText.left, rcText.top, rcText.right - rcText.left, rcText.bottom - rcText.top,
			IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
		SelectObject(hdcMem, hOldFont);
	}
}
Esempio n. 28
0
static void
PAGER_DrawButton(HDC hdc, COLORREF clrBk, RECT arrowRect,
                 BOOL horz, BOOL topLeft, INT btnState)
{
    HBRUSH   hBrush, hOldBrush;
    RECT     rc = arrowRect;

    TRACE("arrowRect = %s, btnState = %d\n", wine_dbgstr_rect(&arrowRect), btnState);

    if (btnState == PGF_INVISIBLE)
        return;

    if ((rc.right - rc.left <= 0) || (rc.bottom - rc.top <= 0))
        return;

    hBrush = CreateSolidBrush(clrBk);
    hOldBrush = SelectObject(hdc, hBrush);

    FillRect(hdc, &rc, hBrush);

    if (btnState == PGF_HOT)
    {
       DrawEdge( hdc, &rc, BDR_RAISEDINNER, BF_RECT);
       if (horz)
           PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
       else
           PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
    }
    else if (btnState == PGF_NORMAL)
    {
       DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
       if (horz)
           PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
       else
           PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
    }
    else if (btnState == PGF_DEPRESSED)
    {
       DrawEdge( hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
       if (horz)
           PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
       else
           PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
    }
    else if (btnState == PGF_GRAYED)
    {
       DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
       if (horz)
       {
           PAGER_DrawHorzArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
           rc.left++, rc.top++; rc.right++, rc.bottom++;
           PAGER_DrawHorzArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
       }
       else
       {
           PAGER_DrawVertArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
           rc.left++, rc.top++; rc.right++, rc.bottom++;
           PAGER_DrawVertArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
       }
    }

    SelectObject( hdc, hOldBrush );
    DeleteObject(hBrush);
}
Esempio n. 29
0
LRESULT CDebugView::OnCaptrueTreeOpened(){


	OPENFILENAME ofn ;

	ofn.lStructSize 				= sizeof (OPENFILENAME) ;
	ofn.hwndOwner					= NULL ;
	ofn.hInstance					= NULL ;
	ofn.lpstrFilter 				= _T("bmp");
	ofn.lpstrCustomFilter	= NULL ;
	ofn.nMaxCustFilter		= 0 ;
	ofn.nFilterIndex		= 0 ;
	ofn.nMaxFile				= MAX_PATH ;
	ofn.nMaxFileTitle			= MAX_PATH ;
	ofn.lpstrInitialDir 		= NULL ;
	ofn.lpstrTitle				= NULL ;
	ofn.nFileOffset 			= 0 ;
	ofn.nFileExtension			= 0 ;
	ofn.lpstrDefExt 			= 0;
	ofn.lCustData				= 0L ;
	ofn.lpfnHook				= NULL ;
	ofn.lpTemplateName			= NULL ;

	TCHAR   szFileName[MAX_PATH], szFileTitle[MAX_PATH];
	*szFileTitle = 0;
	*szFileName  = 0;

	//strcpy(szFileName,".bmp");
	ofn.hwndOwner               = GetGUI()->GetHwnd();
	ofn.lpstrFile         		= szFileName ;
	ofn.lpstrFileTitle    		= szFileTitle ;
	ofn.Flags             		= OFN_OVERWRITEPROMPT ;

	if(!::GetSaveFileName (&ofn)){
		int ret = ::GetLastError();
		return 0;
	}
	tstring FileName = szFileName;
	FileName+=_T(".bmp");

	OpenAllTree();
	Layout(FALSE);

	RECT rcOld;
	::GetClientRect(GetHwnd(),&rcOld);

	::SetWindowPos(GetHwnd(),HWND_TOP,0,0,m_SizeX,m_SizeY,SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW);

	RECT rc;
	::GetClientRect(GetHwnd(),&rc);


	HDC hDC = ::GetDC(GetHwnd());
	HBITMAP hBmpCapture = CreateCompatibleBitmap(hDC,m_SizeX,m_SizeY); 

	HDC DCMem = ::CreateCompatibleDC(hDC);

	HBITMAP OldBitmap = (HBITMAP)::SelectObject(DCMem, hBmpCapture);


	if(m_State & SPACE_SHOWBKG){
		FillRect(DCMem,rc,m_crViewBkg);
	}

	UINT	OldMode	= ::SetBkMode(DCMem,TRANSPARENT);

	Draw(DCMem);

	if(m_UseSystemScrollbar == false){
		DrawScrollbar(DCMem);
	};
	::SetBkMode(DCMem, OldMode );


	if(m_State & SPACE_SHOWWINBORDER){
		DrawEdge(DCMem,rc,m_crWinBorder);
	}


	::SelectObject(DCMem, OldBitmap);
	DeleteObject(DCMem);
	::ReleaseDC(GetHwnd(),hDC);


	::SetWindowPos(GetHwnd(),HWND_TOP,0,0,rcOld.right-rcOld.left,rcOld.bottom-rcOld.top,SWP_NOZORDER|SWP_NOMOVE);

	SaveBitmapToFile(hBmpCapture,FileName.c_str());
	DeleteObject(hBmpCapture);
	return 0;
}
Esempio n. 30
0
static void
IntDrawScrollInterior(HWND hWnd, HDC hDC, INT nBar, BOOL Vertical,
   PSCROLLBARINFO ScrollBarInfo)
{
   INT ThumbSize = ScrollBarInfo->xyThumbBottom - ScrollBarInfo->xyThumbTop;
   INT ThumbTop = ScrollBarInfo->xyThumbTop;
   RECT Rect;
   HBRUSH hSaveBrush, hBrush;
   BOOL TopSelected = FALSE, BottomSelected = FALSE;

   if (ScrollBarInfo->rgstate[SCROLL_TOP_RECT] & STATE_SYSTEM_PRESSED)
      TopSelected = TRUE;
   if (ScrollBarInfo->rgstate[SCROLL_BOTTOM_RECT] & STATE_SYSTEM_PRESSED)
      BottomSelected = TRUE;

   /*
    * Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
    * The window-owned scrollbars need to call DefWndControlColor
    * to correctly setup default scrollbar colors
    */
   if (nBar == SB_CTL)
   {
      hBrush = (HBRUSH)SendMessageW(GetParent(hWnd), WM_CTLCOLORSCROLLBAR, (WPARAM)hDC, (LPARAM)hWnd);
      if (!hBrush)
         hBrush = GetSysColorBrush(COLOR_SCROLLBAR);
   }
   else
   {
      hBrush = DefWndControlColor(hDC, CTLCOLOR_SCROLLBAR);
   }

   hSaveBrush = SelectObject(hDC, hBrush);

   /* Calculate the scroll rectangle */
   if (Vertical)
   {
      Rect.top = ScrollBarInfo->rcScrollBar.top + ScrollBarInfo->dxyLineButton;
      Rect.bottom = ScrollBarInfo->rcScrollBar.bottom - ScrollBarInfo->dxyLineButton;
      Rect.left = ScrollBarInfo->rcScrollBar.left;
      Rect.right = ScrollBarInfo->rcScrollBar.right;
   }
   else
   {
      Rect.top = ScrollBarInfo->rcScrollBar.top;
      Rect.bottom = ScrollBarInfo->rcScrollBar.bottom;
      Rect.left = ScrollBarInfo->rcScrollBar.left + ScrollBarInfo->dxyLineButton;
      Rect.right = ScrollBarInfo->rcScrollBar.right - ScrollBarInfo->dxyLineButton;
   }

   /* Draw the scroll rectangles and thumb */
   if (!ScrollBarInfo->xyThumbBottom)
   {
      PatBlt(hDC, Rect.left, Rect.top, Rect.right - Rect.left,
         Rect.bottom - Rect.top, PATCOPY);

      /* Cleanup and return */
      SelectObject(hDC, hSaveBrush);
      return;
   }

   ThumbTop -= ScrollBarInfo->dxyLineButton;

   if (ScrollBarInfo->dxyLineButton)
   {
      if (Vertical)
      {
         if (ThumbSize)
         {
            PatBlt(hDC, Rect.left, Rect.top, Rect.right - Rect.left,
                   ThumbTop, TopSelected ? BLACKNESS : PATCOPY);
            Rect.top += ThumbTop;
            PatBlt(hDC, Rect.left, Rect.top + ThumbSize, Rect.right - Rect.left,
               Rect.bottom - Rect.top - ThumbSize, BottomSelected ? BLACKNESS : PATCOPY);
            Rect.bottom = Rect.top + ThumbSize;
         }
         else
         {
            if (ThumbTop)
            {
               PatBlt(hDC, Rect.left, ScrollBarInfo->dxyLineButton,
                  Rect.right - Rect.left, Rect.bottom - Rect.top, PATCOPY);
            }
         }
      }
      else
      {
         if (ThumbSize)
         {
            PatBlt(hDC, Rect.left, Rect.top, ThumbTop,
               Rect.bottom - Rect.top, TopSelected ? BLACKNESS : PATCOPY);
            Rect.left += ThumbTop;
            PatBlt(hDC, Rect.left + ThumbSize, Rect.top,
               Rect.right - Rect.left - ThumbSize, Rect.bottom - Rect.top,
               BottomSelected ? BLACKNESS : PATCOPY);
            Rect.right = Rect.left + ThumbSize;
         }
         else
         {
            if (ThumbTop)
            {
               PatBlt(hDC, ScrollBarInfo->dxyLineButton, Rect.top,
                  Rect.right - Rect.left, Rect.bottom - Rect.top, PATCOPY);
            }
         }
      }
   }

   /* Draw the thumb */
   if (ThumbSize)
      DrawEdge(hDC, &Rect, EDGE_RAISED, BF_RECT | BF_MIDDLE);

   /* Cleanup */
   SelectObject(hDC, hSaveBrush);
}