///// LOUIS GUZIK (412) 341-2606 //// #include "BARCOLOR.h" #include #define PATORDEST 0x00FA0089L HBITMAP MakeColorBitmap(HWND); BOOL bl_border_color = FALSE; BOOL bool_text = FALSE; char str[256] = {'0'}; char buffer[64] = {'0'}; char Cmd[16] = "CIRC"; char strColor[16] = "RGB"; HBITMAP hMenuBitMap = 0; /* handle for bitmap */ HBRUSH hbColor; WORD tRed, tGreen, tBlue; HCURSOR hCurArrow, hCurHand, hCurSight, hCurLggIbeam; #include "select.h" BOOL bTrack = FALSE; RECT Rect; int Shape = SL_CIRCLE; /* Shape to use for rectangle */ BOOL RetainShape = TRUE; /* Retain or destroy shape */ int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { /***********************************************************************/ /* HANDLE hInstance; handle for this instance */ /* HANDLE hPrevInstance; handle for possible previous instances */ /* LPSTR lpszCmdLine; long pointer to exec command line */ /* int nCmdShow; Show code for main window display */ /***********************************************************************/ MSG msg; /* MSG structure to store your messages */ int nRc; /* return value from Register Classes */ strcpy(szAppName, "BARCOLOR"); hInst = hInstance; if(!hPrevInstance) { /* register window classes if first instance of application */ if ((nRc = nCwRegisterClasses()) == -1) { /* registering one of the windows failed */ LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString)); MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION); return nRc; } } else { ; /* MessageBox ( GetFocus () , "At this time ONLY one copy of the" " program runs properly at a time." " - LGG -" , "Execution Error - Bar Color" , MB_ICONHAND | MB_OK ); return(hPrevInstance); */ } /* create application's Main window */ hWndMain = CreateWindow( szAppName, /* Window class name */ "Bar Color", /* Window's title */ WS_CAPTION | /* Title and Min/Max */ WS_SYSMENU | /* Add system menu box */ WS_MINIMIZEBOX | /* Add minimize box */ WS_MAXIMIZEBOX | /* Add maximize box */ WS_THICKFRAME | /* thick sizeable frame */ WS_MAXIMIZE | /* create maximized window */ WS_CLIPCHILDREN | /* don't draw in child windows areas */ WS_OVERLAPPED, CW_USEDEFAULT, 0, /* Use default X, Y */ CW_USEDEFAULT, 0, /* Use default X, Y */ NULL, /* Parent window's handle */ NULL, /* Default to Class Menu */ hInst, /* Instance of window */ NULL); /* Create struct for WM_CREATE */ if(hWndMain == NULL) { LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString)); MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION); return IDS_ERR_CREATE_WINDOW; } ShowWindow(hWndMain, SW_SHOWMAXIMIZED); /* display main window */ MessageBox ( GetFocus () , "Use the Mouse Button in this Program for an Example of Graphics Selection. Use the Right Button after drawing the Polygon." , "Message - Bar Color" , MB_ICONHAND | MB_OK ); while(GetMessage(&msg, NULL, 0, 0)) /* Until WM_QUIT message */ { if(hDlgXY_POS && IsDialogMessage(hDlgXY_POS, &msg)) continue; TranslateMessage(&msg); DispatchMessage(&msg); } /* Do clean up before exiting from the application */ CwUnRegisterClasses(); return msg.wParam; } /* End of WinMain */ /************************************************************************/ /* */ /* Main Window Procedure */ /* */ /************************************************************************/ LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam, LONG lParam) { static RECT lpScrRect; static POINT ptClient, ptClientTL, ptClientBR; int i; DWORD ObjBorder; DWORD ObjCenter; HMENU hMenu=0; /* handle for the menu */ HDC hDC; /* handle for the display device */ static PAINTSTRUCT ps; /* holds PAINT information */ HBRUSH FillBrush; int nRc=0; /* return code */ static int Next; static POINT point, point1, point2, point3, pointmouse1, pointmouse2; static POINT pointS[64]; static BOOL Dot_Flag = FALSE; static BOOL XY_Pos_W = FALSE; static BYTE UnderLine = FALSE; static BYTE Italic = FALSE; static short int Char_Weight = 400; static int ChIndex = 0; static char unsigned ch, ChBuffer[128]; static HFONT hFontOld, hFontNew; switch (Message) { case WM_LBUTTONUP: switch( Cmd[0] ) { case 'D': // DOT // ClipCursor( NULL ); Dot_Flag = FALSE; Next = 0; break; case 'T': // text // SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case 'P': if( Next > 1 ) { MoveTo(hDC, pointS[Next-1].x, pointS[Next-1].y); LineTo(hDC, pointS[Next-2].x, pointS[Next-2].y); } EndSelection(pointS[Next], &Rect); StartSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape); break; case 'C': ClipCursor( NULL ); hDC = GetDC(hWnd); hPenOld = SelectObject(hDC,hPen); point1 =MAKEPOINT(lParam); Ellipse(hDC, point.x,point.y, point1.x,point1.y); EndSelection(point1, &Rect); bTrack = FALSE; hPen = SelectObject(hDC, hPenOld ); ReleaseDC( hWnd, hDC ); break; case 'L': ClipCursor( NULL ); hDC = GetDC(hWnd); hPenOld = SelectObject(hDC,hPen); point1 =MAKEPOINT(lParam); MoveTo(hDC, point.x, point.y); LineTo(hDC, point1.x, point1.y); EndSelection(point1, &Rect); bTrack = FALSE; hPen = SelectObject(hDC, hPenOld ); ReleaseDC( hWnd, hDC ); break; case 'R': ClipCursor( NULL ); EndSelection(MAKEPOINT(lParam), &Rect); bTrack = FALSE; DeleteObject( hPen ); point1 = MAKEPOINT(lParam); hDC = GetDC(hWnd); if( PenWidth == 1 ) { hPen = CreatePen(PS_SOLID, PenWidth, lColorPix ); if(point.x > point1.x ) { point.x+=1; // point1.x-=3; } else { // point.x-=3; point1.x+=1; } if(point.y < point1.y ) { // point.y-=4; point1.y+=1; } else { point.y+=1; // point1.y-=4; } } if( PenWidth == 3 ) { hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); if(point.x > point1.x ) { point.x+=3; point1.x-=3; } else { point.x-=3; point1.x+=3; } if(point.y < point1.y ) { point.y-=4; point1.y+=3; } else { point.y+=3; point1.y-=4; } } if( PenWidth == 5 ) { hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); if(point.x > point1.x ) { point.x+=3; point1.x-=3; } else { point.x-=3; point1.x+=3; } if(point.y < point1.y ) { point.y-=4; point1.y+=3; } else { point.y+=3; point1.y-=4; } } if( PenWidth == 9 ) { hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); if(point.x > point1.x ) { point.x+=4; point1.x-=5; } else { point.x-=5; point1.x+=4; } if(point.y < point1.y ) { point.y-=5; point1.y+=4; } else { point.y+=4; point1.y-=5; } } hPenOld = SelectObject(hDC,hPen); Rectangle(hDC, point1.x,point1.y, point.x,point.y); hPen = SelectObject(hDC, hPenOld); ReleaseDC( hWnd, hDC ); break; } break; case WM_RBUTTONDOWN: switch( Cmd[0] ) { case 'P': // POLYGON // if( bl_border_color ) { lColorPix = RGB(Red,Green,Blue); if(PenWidth == 1) { PenWidth = 3; hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_3DOTS, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_1DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_5DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_9DOTS, MF_UNCHECKED); strcpy(str,"D3"); DeleteMenu(hMenu, 9, MF_BYPOSITION ); InsertMenu(hMenu, 9, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); } } else { lColorPix = (long)0; } ClipCursor( NULL ); DeleteObject( hPen ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); bTrack = FALSE; EndSelection( pointS[Next-1], &Rect); hDC = GetDC( hWnd); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); hPenOld = SelectObject(hDC,hPen); Polygon(hDC, (LPPOINT) pointS, Next); hPen = SelectObject(hDC, hPenOld ); Next = 0; ReleaseDC(hWnd, hDC); break; default: break; } break; case WM_LBUTTONDOWN: hMenu = GetMenu(hWnd); if( bl_border_color ) { lColorPix = RGB(Red,Green,Blue); if(PenWidth == 1) { PenWidth = 3; hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_3DOTS, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_1DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_5DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_9DOTS, MF_UNCHECKED); strcpy(str,"D3"); DeleteMenu(hMenu, 9, MF_BYPOSITION ); InsertMenu(hMenu, 9, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); } } else lColorPix = (long)0; switch( Cmd[0] ) { case 'C': // CIRCLE // DeleteObject( hPen ); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); Shape = SL_CIRCLE; point = MAKEPOINT(lParam); bTrack = TRUE; /* user has pressed the left button */ /* If you don't want the shape cleared, you must clear the Rect * coordinates before calling StartSelection */ if (RetainShape) SetRectEmpty(&Rect); //StartSelection(hWnd, MAKEPOINT(lParam), &Rect, // (wParam & MK_SHIFT) ? SL_EXTEND | Shape : Shape); StartSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape); break; case 'R': // RECTANGLE // DeleteObject( hPen ); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); Shape = SL_BOX; point = MAKEPOINT(lParam); bTrack = TRUE; /* user has pressed the left button */ /* If you don't want the shape cleared, you must clear the Rect * coordinates before calling StartSelection */ if (RetainShape) SetRectEmpty(&Rect); //StartSelection(hWnd, MAKEPOINT(lParam), &Rect, // (wParam & MK_SHIFT) ? SL_EXTEND | Shape : Shape); StartSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape); break; case 'L': // LINE // DeleteObject( hPen ); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); Shape = SL_LINE; point = MAKEPOINT(lParam); bTrack = TRUE; /* user has pressed the left button */ /* If you don't want the shape cleared, you must clear the Rect * coordinates before calling StartSelection */ if (RetainShape) SetRectEmpty(&Rect); //StartSelection(hWnd, MAKEPOINT(lParam), &Rect, // (wParam & MK_SHIFT) ? SL_EXTEND | Shape : Shape); StartSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape); break; case 'D': // DOT // switch( Next ) { case 0: Dot_Flag = TRUE; pointmouse1 = MAKEPOINT(lParam); hDC = GetDC(hWnd); SetPixel(hDC, pointmouse1.x, pointmouse1.y, lColorPix); ReleaseDC(hWnd, hDC); Next = 0; break; } break; case 'A': // ARC // switch( Next ) { case 0: point = MAKEPOINT(lParam); hDC = GetDC(hWnd); SetPixel(hDC, point.x, point.y, 0L); strcpy(str, "P=1"); DeleteMenu(hMenu, 11, MF_BYPOSITION ); InsertMenu(hMenu, 11, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); ReleaseDC(hWnd, hDC); Next = 1; break; case 1: point1 = MAKEPOINT(lParam); hDC = GetDC(hWnd); SetPixel(hDC, point1.x, point1.y, 0L); strcpy(str, "P=2"); DeleteMenu(hMenu, 11, MF_BYPOSITION ); InsertMenu(hMenu, 11, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); ReleaseDC(hWnd, hDC); Next = 2; break; case 2: point2 = MAKEPOINT(lParam); hDC = GetDC(hWnd); SetPixel(hDC, point2.x, point2.y, 0L); strcpy(str, "P=3"); DeleteMenu(hMenu, 11, MF_BYPOSITION ); InsertMenu(hMenu, 11, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); ReleaseDC(hWnd, hDC); Next = 3; break; case 3: point3 = MAKEPOINT(lParam); hDC = GetDC(hWnd); SetPixel(hDC, point3.x, point3.y, 0L); Next = 0; hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); hPenOld = SelectObject(hDC,hPen); Arc(hDC, point.x,point.y, point1.x,point1.y, point2.x,point2.y, point3.x,point3.y ); Pie(hDC, point.x,point.y, point1.x,point1.y, point2.x,point2.y, point3.x,point3.y ); DeleteObject( SelectObject(hDC, hPenOld) ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); ReleaseDC(hWnd, hDC); break; } break; case 'P': // POLYGON // if( Next == 0 ) { //hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); } if( Next < 62 ) { pointS[Next++] = MAKEPOINT(lParam); wsprintf( str, "P=%d", Next-1 ); DeleteMenu(hMenu, 11, MF_BYPOSITION ); InsertMenu(hMenu, 11, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); DeleteObject( hPen ); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); if( Next > 1 ) { hDC = GetDC(hWnd); hPenOld = SelectObject (hDC, hPen ); MoveTo(hDC, pointS[Next-1].x, pointS[Next-1].y); LineTo(hDC, pointS[Next-2].x, pointS[Next-2].y); hPen = SelectObject (hDC, hPenOld ); ReleaseDC(hWnd, hDC); } Shape = SL_LINE; bTrack = TRUE; /* user has pressed the left button */ if (RetainShape) SetRectEmpty(&Rect); StartSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape); } else MessageBeep(0); break; case 'F': // FILL // point = MAKEPOINT(lParam); hDC = GetDC(hWnd); ObjCenter = GetPixel(hDC,point.x,point.y); i = point.y; ObjBorder = GetPixel(hDC,point.x,point.y); while( (ObjBorder == ObjCenter) && (i >= 1) ) { i--; ObjBorder = GetPixel(hDC, point.x, i); } if( ObjBorder == GetPixel(hDC, point.x + 1, i) && ObjBorder == GetPixel(hDC, point.x - 1, i) ) { hbColor = CreateSolidBrush(RGB(Red,Green,Blue)); FillBrush = SelectObject(hDC, hbColor); FloodFill(hDC, point.x, point.y, ObjBorder ); DeleteObject( SelectObject(hDC, FillBrush) ); ReleaseDC(hWnd, hDC); } else { MessageBeep(0); ReleaseDC(hWnd, hDC); } break; case 'T': // TEXT // ChIndex = 0; point = MAKEPOINT(lParam); strcpy(str, "START"); DeleteMenu(hMenu, 11, MF_BYPOSITION ); InsertMenu(hMenu, 11, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); break; } break; case WM_COMMAND: // DeleteObject( hPen ); switch (wParam) { case IDM_F_EXIT: { FARPROC lpfnBARC_EXTMsgProc; lpfnBARC_EXTMsgProc = MakeProcInstance((FARPROC)BARC_EXTMsgProc, hInst); nRc = DialogBox(hInst, (LPSTR)"IDM_BARC_EXIT_DLG", hWnd, lpfnBARC_EXTMsgProc); FreeProcInstance(lpfnBARC_EXTMsgProc); } break; case IDM_P_CIRCLE: bool_text = FALSE; hCur = hCurSight; Next = 0; strcpy( Cmd, "CIRC"); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_P_RECTANGLE: bool_text = FALSE; hCur = hCurSight; Next = 0; strcpy(Cmd, "RECT"); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_P_LINE: bool_text = FALSE; hCur = hCurSight; Next = 0; strcpy(Cmd, "LINE"); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_P_LINE, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_P_DOT: bool_text = FALSE; hCur = hCurSight; Next = 0; strcpy(Cmd, "DOT "); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_P_DOT, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_P_ARC: bool_text = FALSE; hCur = hCurSight; Next = 0; strcpy(Cmd, "ARC "); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_P_ARC, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_P_POLYGON: hCur = hCurSight; Next = 0; strcpy(Cmd, "POLY"); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_COLOR: tRed = Red; tGreen = Green; tBlue = Blue; hbColor = CreateSolidBrush( RGB( 0, 0, 0 )); { FARPROC lpfnBARC_CLRMsgProc; lpfnBARC_CLRMsgProc = MakeProcInstance((FARPROC)BARC_CLRMsgProc, hInst); nRc = DialogBox(hInst, (LPSTR)"IDM_CHANGE_BARC_DLG", hWnd, lpfnBARC_CLRMsgProc); FreeProcInstance(lpfnBARC_CLRMsgProc); } break; case IDM_REGION:/************ FILL ********************/ /* Menu Item Named "Fill" here. */ bool_text = FALSE; hCur = hCurSight; Next = 0; strcpy(Cmd, "FILL"); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_HILITE ); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_S_TEXT, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case XY_POS_MENU_UNCHECK: hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_XYPOSWINDOW, MF_UNCHECKED); XY_Pos_W = FALSE; break; case IDM_O_XYPOSWINDOW: /* Menu Item Named "&X-Y Pos Window" here. */ hMenu = GetMenu(hWnd); switch( GetMenuState( hMenu, IDM_O_XYPOSWINDOW, MF_BYCOMMAND )) { case MF_CHECKED: CheckMenuItem(hMenu, IDM_O_XYPOSWINDOW, MF_UNCHECKED); SendMessage( hDlgXY_POS, WM_COMMAND, IDCANCEL, 0L ); XY_Pos_W = FALSE; break; case MF_UNCHECKED: CheckMenuItem(hMenu, IDM_O_XYPOSWINDOW, MF_CHECKED); XY_Pos_W = TRUE; SetWindowText( hWnd, (LPSTR)"Bar Color" ); lpfnXY_POSMsgProc = MakeProcInstance((FARPROC)XY_POSMsgProc, hInst); if(!IsWindow(hDlgXY_POS)) hDlgXY_POS = CreateDialog(hInst, "IDM_XY_POS_WINDOW", hWnd, lpfnXY_POSMsgProc); else ; // SetFocus(hDlgXY_POS); break; } break; case IDM_O_1DOT: PenWidth = 1; hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_1DOT, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_3DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_5DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_9DOTS, MF_UNCHECKED); strcpy(str, "D1"); DeleteMenu(hMenu, 9, MF_BYPOSITION ); InsertMenu(hMenu, 9, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); break; case IDM_O_3DOTS: PenWidth = 3; hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_3DOTS, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_1DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_5DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_9DOTS, MF_UNCHECKED); strcpy(str,"D3"); DeleteMenu(hMenu, 9, MF_BYPOSITION ); InsertMenu(hMenu, 9, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); break; case IDM_O_5DOTS: PenWidth = 5; hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_5DOTS, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_1DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_3DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_9DOTS, MF_UNCHECKED); strcpy(str,"D5"); DeleteMenu(hMenu, 9, MF_BYPOSITION ); InsertMenu(hMenu, 9, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); break; case IDM_O_9DOTS: PenWidth = 9; hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_9DOTS, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_1DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_3DOTS, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_O_5DOTS, MF_UNCHECKED); strcpy(str,"D9"); DeleteMenu(hMenu, 9, MF_BYPOSITION ); InsertMenu(hMenu, 9, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); DrawMenuBar(hWnd); break; case IDM_O_BLACKBORDER: hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_BLACKBORDER, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_COLORBORDER, MF_UNCHECKED); bl_border_color = FALSE; strcpy( str, "BLK"); hMenu = GetMenu(hWnd); DeleteMenu(hMenu, 12, MF_BYPOSITION ); InsertMenu(hMenu, 12, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_O_COLORBORDER: hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, IDM_O_COLORBORDER, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_BLACKBORDER, MF_UNCHECKED); bl_border_color = TRUE; strcpy( str, "COL"); hMenu = GetMenu(hWnd); DeleteMenu(hMenu, 12, MF_BYPOSITION ); InsertMenu(hMenu, 12, MF_BYPOSITION|MF_STRING, 0, (LPSTR)str ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; case IDM_S_TEXT: bool_text = TRUE; hCur = hCurLggIbeam; strcpy( Cmd, "TEXT"); hMenu = GetMenu(hWnd); HiliteMenuItem (hWnd, hMenu, IDM_REGION, MF_BYCOMMAND | MF_UNHILITE ); CheckMenuItem(hMenu, IDM_S_TEXT, MF_CHECKED); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_RECTANGLE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_LINE, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_DOT, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_ARC, MF_UNCHECKED); CheckMenuItem(hMenu, IDM_P_POLYGON, MF_UNCHECKED); DeleteMenu(hMenu, 10, MF_BYPOSITION ); InsertMenu(hMenu, 10, MF_BYPOSITION|MF_STRING, 0, (LPSTR)Cmd ); SendMessage( hWnd, LGG_COLOR, 0, 0L ); point.x = 0; point.y = 0; ChIndex = 0; break; case IDM_B_BOLD: hMenu = GetMenu(hWnd); switch( GetMenuState( hMenu, IDM_B_BOLD, MF_BYCOMMAND )) { case MF_CHECKED: CheckMenuItem(hMenu, IDM_B_BOLD, MF_UNCHECKED); Char_Weight = 400; break; case MF_UNCHECKED: CheckMenuItem(hMenu, IDM_B_BOLD, MF_CHECKED); Char_Weight = 600; break; } DeleteObject( hFontNew ); hFontNew = CreateFont( 16, // lfHeight 7, // lfWidth 0, // lfEscapement 0, // lfOrientation Char_Weight, // lfWeight Italic, // lfItalic UnderLine, // lfUnderline FALSE, // lfStrikeOut OEM_CHARSET, // lfCharset OUT_DEFAULT_PRECIS, // lfOutPrecision CLIP_DEFAULT_PRECIS, // lfClipPrecision DEFAULT_QUALITY, // lfQuality VARIABLE_PITCH | FF_ROMAN,// lfPitchAndFamily "Helv"); break; case IDM_T_ITALIC: hMenu = GetMenu(hWnd); switch( GetMenuState( hMenu, IDM_T_ITALIC, MF_BYCOMMAND )) { case MF_CHECKED: CheckMenuItem(hMenu, IDM_T_ITALIC, MF_UNCHECKED); Italic = FALSE; break; case MF_UNCHECKED: CheckMenuItem(hMenu, IDM_T_ITALIC, MF_CHECKED); Italic = TRUE; break; } DeleteObject( hFontNew ); hFontNew = CreateFont( 16, // lfHeight 7, // lfWidth 0, // lfEscapement 0, // lfOrientation Char_Weight, // lfWeight Italic, // lfItalic UnderLine, // lfUnderline FALSE, // lfStrikeOut OEM_CHARSET, // lfCharset OUT_DEFAULT_PRECIS, // lfOutPrecision CLIP_DEFAULT_PRECIS, // lfClipPrecision DEFAULT_QUALITY, // lfQuality VARIABLE_PITCH | FF_ROMAN,// lfPitchAndFamily "Helv"); break; case IDM_T_UNDERLINE: hMenu = GetMenu(hWnd); switch( GetMenuState( hMenu, IDM_T_UNDERLINE, MF_BYCOMMAND )) { case MF_CHECKED: CheckMenuItem(hMenu, IDM_T_UNDERLINE, MF_UNCHECKED); UnderLine = FALSE; break; case MF_UNCHECKED: CheckMenuItem(hMenu, IDM_T_UNDERLINE, MF_CHECKED); UnderLine = TRUE; break; } DeleteObject( hFontNew ); hFontNew = CreateFont( 16, // lfHeight 7, // lfWidth 0, // lfEscapement 0, // lfOrientation Char_Weight, // lfWeight Italic, // lfItalic UnderLine, // lfUnderline FALSE, // lfStrikeOut OEM_CHARSET, // lfCharset OUT_DEFAULT_PRECIS, // lfOutPrecision CLIP_DEFAULT_PRECIS, // lfClipPrecision DEFAULT_QUALITY, // lfQuality VARIABLE_PITCH | FF_ROMAN,// lfPitchAndFamily "Helv"); break; case IDM_T_FONTS: break; case IDM_ABOUT: { FARPROC lpfnBARC_ABTMsgProc; lpfnBARC_ABTMsgProc = MakeProcInstance((FARPROC)BARC_ABTMsgProc, hInst); nRc = DialogBox(hInst, (LPSTR)"IDM_ABOUT_BARC_DLG", hWnd, lpfnBARC_ABTMsgProc); FreeProcInstance(lpfnBARC_ABTMsgProc); } break; case IDM_CLEAR: InvalidateRect(hWnd, NULL, TRUE); break; default: MessageBeep(0); /* WRONG CHAR RESPONCE TO SELECTION */ return DefWindowProc(hWnd, Message, wParam, lParam); } break; /* End of WM_COMMAND */ case WM_CHAR: if( bool_text ) { hDC = GetDC(hWnd); SetTextColor(hDC, lColorPix ); SetBkMode( hDC, TRANSPARENT ); ch = LOBYTE(wParam); if(isprint(ch) && ChIndex < 127) { hFontOld = SelectObject( hDC, hFontNew ); ChBuffer[ ChIndex++ ] = ch; TextOut( hDC, point.x+5, point.y+1, (LPSTR) &ChBuffer, ChIndex ); hFontNew = SelectObject( hDC, hFontOld ); } else MessageBeep(0); ReleaseDC( hWnd, hDC ); } break; case WM_CREATE: hFontNew = CreateFont( 16, // lfHeight 7, // lfWidth 0, // lfEscapement 0, // lfOrientation Char_Weight, // lfWeight Italic, // lfItalic UnderLine, // lfUnderline FALSE, // lfStrikeOut OEM_CHARSET, // lfCharset OUT_DEFAULT_PRECIS, // lfOutPrecision CLIP_DEFAULT_PRECIS, // lfClipPrecision DEFAULT_QUALITY, // lfQuality VARIABLE_PITCH | FF_ROMAN,// lfPitchAndFamily "Helv"); Red=219; Green=164; Blue=110; PenWidth = 1; lColorPix = RGB(Red,Green,Blue); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); hMenuBitMap = MakeColorBitmap(hWnd); hCurArrow = LoadCursor( NULL, IDC_ARROW ); hCurSight = LoadCursor( hInst, "PNTSIGHT"); hCurHand = LoadCursor( hInst, "PNTHAND" ); hCurLggIbeam = LoadCursor( hInst, "LGGIBEAM" ); hCur = hCurSight; hMenu = GetMenu(hWnd); EnableMenuItem( hMenu, IDM_T_FONTS, MF_BYCOMMAND | MF_GRAYED ); CheckMenuItem(hMenu, IDM_P_CIRCLE, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_1DOT, MF_CHECKED); CheckMenuItem(hMenu, IDM_O_BLACKBORDER, MF_CHECKED); SendMessage( hWnd, LGG_COLOR, 0, 0L ); break; /* End of WM_CREATE */ case WM_MOUSEMOVE: hDC = GetDC(hWnd); pointmouse2 = MAKEPOINT(lParam); if( XY_Pos_W == FALSE) { SetBkColor( hDC, RGB(0,255,255) ); wsprintf(str, " X=%d Y=%d ", pointmouse2.x, pointmouse2.y ); TextOut(hDC, 0, 0, (LPSTR)str, strlen(str) ); SetWindowText( hWnd, (LPSTR)str ); } else { SetDlgItemInt( hDlgXY_POS, IDM_X_POS, pointmouse2.x, FALSE ); SetDlgItemInt( hDlgXY_POS, IDM_Y_POS, pointmouse2.y, FALSE ); } if( Dot_Flag == TRUE ) { ClipCursor( &lpScrRect ); DeleteObject( hPen ); hPen = CreatePen(PS_INSIDEFRAME, PenWidth, lColorPix ); hPenOld = SelectObject(hDC,hPen); SetPixel(hDC, pointmouse2.x, pointmouse2.y, RGB(Red,Green,Blue)); MoveTo(hDC,pointmouse1.x,pointmouse1.y); LineTo(hDC,pointmouse2.x,pointmouse2.y); pointmouse1.x = pointmouse2.x; pointmouse1.y = pointmouse2.y; hPen = SelectObject(hDC, hPenOld ); } if (bTrack) { // wsprintf(str, " lpTop=%d lpLeft=%d lpBotm=%d lpRight=%d ", // lpScrRect.top, lpScrRect.left, lpScrRect.bottom, lpScrRect.right ); // TextOut(hDC, 0, 20, (LPSTR)str, strlen(str) ); ClipCursor( &lpScrRect ); UpdateSelection(hWnd, pointmouse2, &Rect, Shape); } ReleaseDC(hWnd, hDC); SetCursor(hCur); break; case WM_MOVE: /* code for moving the window */ ptClient.y = (int) (HIWORD (lParam) ); ptClient.x = (int) (LOWORD (lParam) ); if( ptClient.x > lpScrRect.left ) lpScrRect.right += ptClient.x - lpScrRect.left; if( ptClient.x < lpScrRect.left ) lpScrRect.right -= lpScrRect.left - ptClient.x; if( ptClient.y > lpScrRect.top ) lpScrRect.bottom += ptClient.y - lpScrRect.top; if( ptClient.y < lpScrRect.top ) lpScrRect.bottom -= lpScrRect.top - ptClient.y; lpScrRect.top = ptClient.y; lpScrRect.left = ptClient.x; break; case WM_SIZE: /* code for sizing client area */ ptClientBR.y = (int) HIWORD (lParam); ptClientBR.x = (int) LOWORD (lParam); ptClientTL.y = 0; ptClientTL.x = 0; ClientToScreen( hWnd, &ptClientBR ); ClientToScreen( hWnd, &ptClientTL ); lpScrRect.top = ptClientTL.y; lpScrRect.left = ptClientTL.x; lpScrRect.bottom = ptClientBR.y; lpScrRect.right = ptClientBR.x; break; /* End of WM_SIZE */ case WM_PAINT: /* code for the window's client area */ /* Obtain a handle to the device context */ /* BeginPaint will sends WM_ERASEBKGND if appropriate */ memset(&ps, 0x00, sizeof(PAINTSTRUCT)); hDC = BeginPaint(hWnd, &ps); /* Included in case the background is not a pure color */ SetBkMode(hDC, TRANSPARENT); /* Inform Windows painting is complete */ EndPaint(hWnd, &ps); break; /* End of WM_PAINT */ case LGG_COLOR: hMenu = GetMenu(hWnd); DeleteMenu(hMenu, 11, MF_BYPOSITION ); DeleteObject( hMenuBitMap ); hMenuBitMap = MakeColorBitmap(hWnd); InsertMenu(hMenu, 11, MF_BYPOSITION|MF_BITMAP, 0, (LPSTR)(LONG) hMenuBitMap ); // InsertMenu(hMenu, 11, MF_BYPOSITION|MF_STRING, 0, (LPSTR)strColor ); DrawMenuBar(hWnd); break; case WM_QUIT: /* LGG INSERTED */ /* Destroy child windows, modeless dialogs, then, this window */ DeleteObject( hPen ); DeleteObject( hFontNew ); DeleteObject( hMenuBitMap ); SetCursor(hCurArrow); DeleteObject( hCurArrow ); DestroyWindow(hWnd); PostQuitMessage(0); /* Quit the application */ break; case WM_CLOSE: { FARPROC lpfnBARC_EXTMsgProc; lpfnBARC_EXTMsgProc = MakeProcInstance((FARPROC)BARC_EXTMsgProc, hInst); nRc = DialogBox(hInst, (LPSTR)"IDM_BARC_EXIT_DLG", hWnd, lpfnBARC_EXTMsgProc); FreeProcInstance(lpfnBARC_EXTMsgProc); } break; case WM_SYSCOMMAND: // MessageBeep(0); SetWindowText( hWnd, (LPSTR)"Bar Color" ); // SendMessage( hWnd, LGG_COLOR, 0, 0L ); default: return DefWindowProc(hWnd, Message, wParam, lParam); } } /* End of WndProc */ /************************************************************************/ /* */ /* CHANGE COLOR */ /* */ /************************************************************************/ BOOL FAR PASCAL BARC_CLRMsgProc(HWND hWndDlg, WORD Message, WORD wParam, LONG lParam) { HWND hWndControl; POINT point; WORD cVPos; static WORD DlgWparam; point.x = 0; point.y = 0; // MessageBeep( 0 ); switch(Message) { case WM_SETCURSOR: // MessageBeep(0); switch( GetDlgCtrlID(wParam) ) { case IDM_RED_BAR: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_GREEN_BAR: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_BLUE_BAR: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_BLACK: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_WHITE: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_GRAY: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_RED: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_GREEN: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_BLUE: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_AQUA: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_PURPLE: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_YELLOW: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_DEFAULT: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_OK: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; case IDM_CANCEL: SetClassWord( wParam, GCW_HCURSOR, hCurHand ); // SetCursor(hCurHand); DlgWparam = wParam; return( FALSE ); break; default: SetClassWord( wParam, GCW_HCURSOR, hCurArrow ); // SetCursor( hCurArrow ); // SetCursor( IDC_ARROW ); DlgWparam = wParam; return( FALSE ); break; } break; case WM_INITDIALOG: cwCenter(hWndDlg, 0); //SetClassWord( hWndDlg, GCW_HCURSOR, hCurHand); //SetCursor(hCurHand); SetDlgItemInt( hWndDlg, IDM_RED_VALUE, tRed, FALSE ); SetDlgItemInt( hWndDlg, IDM_GREEN_VALUE, tGreen, FALSE ); SetDlgItemInt( hWndDlg, IDM_BLUE_VALUE, tBlue, FALSE ); hWndControl = GetDlgItem( hWndDlg, IDM_RED_BAR ); SetScrollRange( hWndControl, SB_CTL, 0, 255, FALSE ); SetScrollPos( hWndControl, SB_CTL, 255-tRed, TRUE ); hWndControl = GetDlgItem( hWndDlg, IDM_GREEN_BAR ); SetScrollRange( hWndControl, SB_CTL, 0, 255, FALSE ); SetScrollPos( hWndControl, SB_CTL, 255-tGreen, TRUE ); hWndControl = GetDlgItem( hWndDlg, IDM_BLUE_BAR ); SetScrollRange( hWndControl, SB_CTL, 0, 255, FALSE ); SetScrollPos( hWndControl, SB_CTL, 255-tBlue, TRUE ); DeleteObject( hbColor ); /* initialize working variables */ break; /* End of WM_INITDIALOG */ case WM_CTLCOLOR: switch( HIWORD(lParam) ) { case CTLCOLOR_SCROLLBAR: switch( GetDlgCtrlID( LOWORD(lParam)) ) { case IDM_RED_BAR: DeleteObject( hbColor ); ClientToScreen( hWndDlg, &point ); hbColor = CreateSolidBrush( RGB( tRed, 0, 0 )); UnrealizeObject( hbColor ); SetBrushOrg( wParam, point.x, point.y ); return( hbColor ); break; case IDM_GREEN_BAR: DeleteObject( hbColor ); ClientToScreen( hWndDlg, &point ); hbColor = CreateSolidBrush( RGB( 0, tGreen, 0 )); UnrealizeObject( hbColor ); SetBrushOrg( wParam, point.x, point.y ); return( hbColor ); break; case IDM_BLUE_BAR: DeleteObject( hbColor ); ClientToScreen( hWndDlg, &point ); hbColor = CreateSolidBrush( RGB( 0, 0, tBlue )); UnrealizeObject( hbColor ); SetBrushOrg( wParam, point.x, point.y ); return( hbColor ); break; } break; case CTLCOLOR_STATIC: switch( GetDlgCtrlID( LOWORD(lParam)) ) { case IDM_COLOR_BLOCK: DeleteObject( hbColor ); hbColor = CreateSolidBrush( RGB( tRed, tGreen, tBlue )); SetBkColor( wParam, hbColor); point.x = point.y = 0; ClientToScreen( hWndDlg, &point ); UnrealizeObject( hbColor ); SetBrushOrg( wParam, point.x, point.y ); return( hbColor ); case IDM_RED_TEXT: DeleteObject( hbColor ); hbColor = CreateSolidBrush( RGB( 255, 0, 0 )); SetTextColor( wParam, RGB( 255, 0, 0 )); point.x = point.y = 0; ClientToScreen( hWndDlg, &point ); UnrealizeObject( hbColor ); SetBrushOrg( wParam, point.x, point.y ); return( hbColor ); break; case IDM_GREEN_TEXT: DeleteObject( hbColor ); hbColor = CreateSolidBrush( RGB( 0,255,0 )); SetTextColor( wParam, RGB(0,255,0)); UnrealizeObject( hbColor ); return( hbColor ); break; case IDM_BLUE_TEXT: DeleteObject( hbColor ); hbColor = CreateSolidBrush( RGB( 0,0,255 )); SetTextColor( wParam, RGB(0,0,255)); UnrealizeObject( hbColor ); return( hbColor ); break; } break; } break; case WM_VSCROLL: switch( GetDlgCtrlID( HIWORD(lParam)) ) { case IDM_RED_BAR: cVPos = tRed; break; case IDM_GREEN_BAR: cVPos = tGreen; break; case IDM_BLUE_BAR: cVPos = tBlue; break; } switch(wParam) { case SB_LINEUP: cVPos = min(255, cVPos + 1); break; case SB_LINEDOWN: if( cVPos > 0) cVPos--; break; case SB_THUMBTRACK: cVPos = (255 - LOWORD(lParam)); switch( GetDlgCtrlID( HIWORD(lParam)) ) { case IDM_RED_BAR: tRed = cVPos; SetDlgItemInt( hWndDlg, IDM_RED_VALUE, tRed, FALSE ); break; case IDM_GREEN_BAR: tGreen = cVPos; SetDlgItemInt( hWndDlg, IDM_GREEN_VALUE, tGreen, FALSE ); break; case IDM_BLUE_BAR: tBlue = cVPos; SetDlgItemInt( hWndDlg, IDM_BLUE_VALUE, tBlue, FALSE ); } break; case SB_THUMBPOSITION: cVPos = (255 - LOWORD(lParam)); break; case SB_PAGEDOWN: if( cVPos >= 10) cVPos -= 10; else if( cVPos < 10 && cVPos > 0 ) cVPos = 0; break; case SB_PAGEUP: cVPos = min(255, cVPos + 10); break; default: return FALSE; } SetScrollPos( HIWORD(lParam), SB_CTL, 255 - cVPos, TRUE); switch( GetDlgCtrlID( HIWORD(lParam)) ) // Number Values Under Scrool Bars { case IDM_RED_BAR: tRed = cVPos; SetDlgItemInt( hWndDlg, IDM_RED_VALUE, tRed, FALSE ); break; case IDM_GREEN_BAR: tGreen = cVPos; SetDlgItemInt( hWndDlg, IDM_GREEN_VALUE, tGreen, FALSE ); break; case IDM_BLUE_BAR: tBlue = cVPos; SetDlgItemInt( hWndDlg, IDM_BLUE_VALUE, tBlue, FALSE ); break; } SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); break; case WM_CLOSE: /* Closing the Dialog behaves the same as Cancel */ PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L); break; /* End of WM_CLOSE */ case WM_COMMAND: DeleteObject( hbColor ); switch(wParam) { case IDM_BLACK: /* Button text: "&BLACK" */ tRed = 0; tGreen = 0; tBlue = 0; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_GRAY: /* Button text: "GR&AY" */ tRed = 127; tGreen = 128; tBlue = 129; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_WHITE: /* Button text: "&WHITE" */ tRed = 255; tGreen = 255; tBlue = 255; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_RED: /* Button text: "&RED" */ tRed = 255; tGreen = 0; tBlue = 0; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_GREEN: /* Button text: "&GREEN" */ tRed = 0; tGreen = 255; tBlue = 0; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_BLUE: tRed = 0; tGreen = 0; tBlue = 255; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_AQUA: tRed = 0; tGreen = 255; tBlue = 255; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_PURPLE: tRed = 255; tGreen = 0; tBlue = 255; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_YELLOW: tRed = 255; tGreen = 255; tBlue = 0; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_DEFAULT: tRed = 219; tGreen = 164; tBlue = 110; SetDlgItemText( hWndDlg, IDM_COLOR_BLOCK, (LPSTR)NULL ); SendMessage( hWndDlg, WM_INITDIALOG, 0, 0L ); break; case IDM_OK: Red = tRed; Green = tGreen; Blue = tBlue; wsprintf(strColor, "R%dG%dB%d", Red, Green, Blue ); SetClassWord( DlgWparam, GCW_HCURSOR, NULL); SetClassWord( hWndDlg, GCW_HCURSOR, NULL); SetCursor( hCurArrow ); EndDialog(hWndDlg, TRUE); PostMessage( hWndMain, LGG_COLOR, 0, 0L ); break; case IDM_CANCEL: SetClassWord( DlgWparam, GCW_HCURSOR, NULL); SetClassWord( hWndDlg, GCW_HCURSOR, NULL); SetCursor( hCurArrow ); EndDialog(hWndDlg, FALSE); break; case IDCANCEL: MessageBeep( 0 ); SetClassWord( DlgWparam, GCW_HCURSOR, NULL); SetClassWord( hWndDlg, GCW_HCURSOR, NULL); SetCursor( hCurArrow ); EndDialog(hWndDlg, FALSE); break; } break; /* End of WM_COMMAND */ default: //SetCursor(hCurHand); return FALSE; } return TRUE; } /* End of BARC_CLRMsgProc */ /************************************************************************/ /* */ /* ABOUT */ /* */ /************************************************************************/ BOOL FAR PASCAL BARC_ABTMsgProc(HWND hWndDlg, WORD Message, WORD wParam, LONG lParam) { static RECT rect; switch(Message) { case WM_INITDIALOG: /* initialize working variables */ cwCenter(hWndDlg, 0); rect.left = 14; rect.top = 11; rect.right = 64; rect.bottom = 64; break; /* End of WM_INITDIALOG */ case WM_CLOSE: /* Closing the Dialog behaves the same as Cancel */ // SendMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L); break; /* End of WM_CLOSE */ case WM_COMMAND: switch(wParam) { case IDM_OK: EndDialog(hWndDlg, TRUE); break; case IDCANCEL: EndDialog(hWndDlg, TRUE); break; case IDM_ABT_ICON_CLICK: MessageBeep(0); InvalidateRect(hWndDlg, &rect, FALSE); break; } break; /* End of WM_COMMAND */ default: return FALSE; } return TRUE; } /* End of BARC_ABTMsgProc */ /************************************************************************/ /* */ /* EXIT */ /* */ /************************************************************************/ BOOL FAR PASCAL BARC_EXTMsgProc(HWND hWndDlg, WORD Message, WORD wParam, LONG lParam) { switch(Message) { case WM_INITDIALOG: cwCenter(hWndDlg, 0); /* initialize working variables */ CheckRadioButton( hWndDlg, IDM_BAR_C_EXIT_YES, IDM_BAR_C_EXIT_NO, IDM_BAR_C_EXIT_YES ); break; /* End of WM_INITDIALOG */ case WM_CLOSE: /* Closing the Dialog behaves the same as Cancel */ SendMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L); break; /* End of WM_CLOSE */ case WM_COMMAND: switch(wParam) { case IDM_BAR_C_EXIT_YES: /* Radiobutton text: "&YES" */ break; case IDM_BAR_C_EXIT_NO: /* Radiobutton text: "&NO" */ break; case IDM_OK: EndDialog(hWndDlg, TRUE); if( IsDlgButtonChecked( hWndDlg, IDM_BAR_C_EXIT_YES) ) PostMessage( hWndMain, WM_QUIT, 0, 0L ); break; case IDM_CANCEL: EndDialog(hWndDlg, FALSE); break; } break; /* End of WM_COMMAND */ default: return FALSE; } return TRUE; } /* End of BARC_EXTMsgProc */ /************************************************************************/ /* */ /* X-Y POSTION WINDOW */ /* */ /************************************************************************/ BOOL FAR PASCAL XY_POSMsgProc(HWND hWndDlg, WORD Message, WORD wParam, LONG lParam) { switch(Message) { case WM_INITDIALOG: /* initialize working variables */ cwCenter(hWndDlg, 0); SetDlgItemInt( hWndDlg, IDM_X_POS, 199, FALSE ); break; /* End of WM_INITDIALOG */ case WM_CLOSE: /* Closing the Dialog behaves the same as Cancel */ SendMessage( hWndMain, WM_COMMAND, XY_POS_MENU_UNCHECK, 0L ); SendMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L); break; /* End of WM_CLOSE */ case WM_MOVE: //MessageBeep(0); break; case WM_COMMAND: switch(wParam) { case IDCANCEL: /* Ignore data values entered into the controls */ /* and dismiss the dialog window returning FALSE */ DestroyWindow(hWndDlg); hDlgXY_POS = 0; FreeProcInstance(lpfnXY_POSMsgProc); break; } break; /* End of WM_COMMAND */ default: return FALSE; } return TRUE; } /* End of XY_POSMsgProc */ /************************************************************************/ /* */ /* nCwRegisterClasses Function */ /* */ /* The following function registers all the classes of all the windows */ /* associated with this application. The function returns an error code */ /* if unsuccessful, otherwise it returns 0. */ /* */ /************************************************************************/ int nCwRegisterClasses(void) { WNDCLASS wndclass; /* struct to define a window class */ memset(&wndclass, 0x00, sizeof(WNDCLASS)); /* load WNDCLASS with window's characteristics */ wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW; wndclass.lpfnWndProc = WndProc; /* Extra storage for Class and Window objects */ wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInst; wndclass.hIcon = LoadIcon(hInst, "BARCOLOR"); wndclass.hCursor = NULL; /* so cursor may be changed */ /* Create brush for erasing background */ wndclass.hbrBackground = CreateSolidBrush(RGB(219, 164, 110)); // wndclass.hbrBackground = CreateSolidBrush(RGB(255, 255, 255)); wndclass.lpszMenuName = szAppName; /* Menu Name is App Name */ wndclass.lpszClassName = szAppName; /* Class Name is App Name */ if(!RegisterClass(&wndclass)) return -1; return(0); } /* End of nCwRegisterClasses */ /************************************************************************/ /* cwCenter Function */ /* */ /* centers a window based on the client area of its parent */ /* */ /************************************************************************/ void cwCenter(hWnd, top) HWND hWnd; int top; { POINT pt; RECT swp; RECT rParent; int iwidth; int iheight; /* get the rectangles for the parent and the child */ GetWindowRect(hWnd, &swp); GetClientRect(hWndMain, &rParent); /* calculate the height and width for MoveWindow */ iwidth = swp.right - swp.left; iheight = swp.bottom - swp.top; /* find the center point and convert to screen coordinates */ pt.x = (rParent.right - rParent.left) / 2; pt.y = (rParent.bottom - rParent.top) / 2; ClientToScreen(hWndMain, &pt); /* calculate the new x, y starting point */ pt.x = pt.x - (iwidth / 2); pt.y = pt.y - (iheight / 2); /* top will adjust the window position, up or down */ if(top) pt.y = pt.y + top; /* move the window */ MoveWindow(hWnd, pt.x, pt.y, iwidth, iheight, FALSE); } /************************************************************************/ /* CwUnRegisterClasses Function */ /* */ /* Deletes any refrences to windows resources created for this */ /* application, frees memory, deletes instance, handles and does */ /* clean up prior to exiting the window */ /* */ /************************************************************************/ void CwUnRegisterClasses(void) { WNDCLASS wndclass; /* struct to define a window class */ memset(&wndclass, 0x00, sizeof(WNDCLASS)); GetClassInfo(hInst, szAppName, &wndclass); DeleteObject(wndclass.hbrBackground); UnregisterClass(szAppName, hInst); } /* End of CwUnRegisterClasses */ /************************************************************************/ /* */ /* MAKE COLOR BITMAP */ /* */ /************************************************************************/ HBITMAP MakeColorBitmap(HWND hWnd) { HDC hDC; HDC hMemoryDC; HBITMAP hBitmap; HBITMAP hOldBitmap; HBRUSH hFillBrush; HBRUSH hOldBrush; hDC = GetDC(hWnd); hMemoryDC = CreateCompatibleDC(hDC); hBitmap = CreateCompatibleBitmap(hDC, 36, 18); hOldBitmap = SelectObject(hMemoryDC, hBitmap); hFillBrush = CreateSolidBrush(RGB( Red, Green, Blue )); PatBlt(hMemoryDC, 0, 0, 38, 18, BLACKNESS); hOldBrush = SelectObject(hMemoryDC, hFillBrush); PatBlt(hMemoryDC, 3, 3, 30, 13, PATORDEST); DeleteObject( SelectObject( hMemoryDC, hOldBrush) ); SelectObject( hMemoryDC, hOldBitmap); DeleteDC(hMemoryDC); ReleaseDC(hWnd, hDC); return (hBitmap); }