/**
* ColorPicker.cpp : Contains all fundamental espects of the application.
* Copyright (c) 2002, Li Zhaoming
*/
#include "stdafx.h"
#include "resource.h"
#define MAX_LOADSTRING 100
// Current instance
HINSTANCE hinstance;
// String buffers
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
// Foreground and background colors
DWORD g_fgColor = 0xff0000;
DWORD g_bgColor = 0x00ff00;
// Pre-defined font struct
LOGFONT g_logFont = {80, 0, 0, 0, 0, false, false, false,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, DEFAULT_PITCH, "Arial Black"};
// Basic colors in color dialogbox.
DWORD g_crItems[] = {
RGB( 0, 0, 0), RGB( 64, 0, 0), RGB(128, 0, 0), RGB(128, 64, 64), RGB(255, 0, 0), RGB(255, 128, 128),
RGB(255, 255, 128), RGB(255, 255, 0), RGB(255, 128, 64), RGB(255, 128, 0), RGB(128, 64, 0), RGB(128, 128, 0),
RGB(128, 128, 64), RGB( 0, 64, 0), RGB( 0, 128, 0), RGB( 0, 255, 0), RGB(128, 255, 0), RGB(128, 255, 128),
RGB( 0, 255, 128), RGB( 0, 255, 64), RGB( 0, 128, 128), RGB( 0, 128, 64), RGB( 0, 64, 64), RGB(128, 128, 128),
RGB( 64, 128, 128), RGB( 0, 0, 128), RGB( 0, 0, 255), RGB( 0, 64, 128), RGB( 0, 255, 255), RGB(128, 255, 255),
RGB( 0, 128, 255), RGB( 0, 128, 192), RGB(128, 128, 255), RGB( 0, 0, 160), RGB( 0, 0, 64), RGB(192, 192, 192),
RGB( 64, 0, 64), RGB( 64, 0, 64), RGB(128, 0, 128), RGB(128, 0, 64), RGB(128, 128, 192), RGB(255, 128, 192),
RGB(255, 128, 255), RGB(255, 0, 255), RGB(255, 0, 128), RGB(128, 0, 255), RGB( 64, 0, 128), RGB(255, 255, 255),
};
// Foward declarations of functions.
ATOM MyRegisterClass(HINSTANCE hinstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK foreground(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK background(HWND, UINT, WPARAM, LPARAM);
/**
* Entry point of the application.
*/
int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hinstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hinstance, IDC_COLORPICKER, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hinstance);
// Perform application initialization:
if (!InitInstance (hinstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hinstance, (LPCTSTR)IDC_COLORPICKER);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
/**
* FUNCTION: MyRegisterClass()
* PURPOSE: Registers the window class.
* COMMENTS:
* This function and its usage is only necessary if you want this code
* to be compatible with Win32 systems prior to the 'RegisterClassEx'
* function that was added to Windows 95. It is important to call this function
* so that the application will get 'well formed' small icons associated
* with it.
*/
ATOM MyRegisterClass(HINSTANCE hinstance)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(hinstance, (LPCTSTR)IDI_COLORPICKER);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = (LPCSTR)IDC_COLORPICKER;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
/**
* FUNCTION: InitInstance(HANDLE, int)
* PURPOSE: Saves instance handle and creates main window
* COMMENTS:
* In this function, we save the instance handle in a global variable and
* create and display the main program window.
*/
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
HWND hwnd;
hinstance = hinstance; // Store instance handle in our global variable
hwnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hinstance, NULL);
if (!hwnd)
{
return FALSE;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
/*
* 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;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hinstance, IDS_HELLO, szHello, MAX_LOADSTRING);
HFONT hfont;
HBRUSH hbrush;
HGDIOBJ hobject;
switch (message)
{
case WM_CREATE:
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_FOREGROUND:
DialogBox(hinstance, (LPCTSTR)IDD_FOREGROUND, hwnd, (DLGPROC) foreground);
break;
case IDM_BACKGROUND:
DialogBox(hinstance, (LPCTSTR)IDD_BACKGROUND, hwnd, (DLGPROC) background);
break;
case IDM_ABOUT:
DialogBox(hinstance, (LPCTSTR)IDD_ABOUTBOX, hwnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hwnd);
break;
default:
return DefWindowProc(hwnd, message, wParam, lparam);
}
break;
case WM_PAINT:
RECT rt;
GetClientRect(hwnd, &rt);
hdc = BeginPaint(hwnd, &ps);
hbrush = CreateSolidBrush(g_bgColor);
FillRect(hdc, &rt, hbrush);
hfont = CreateFontIndirect(&g_logFont);
hobject = SelectObject(hdc, hfont);
SetTextColor(hdc, g_fgColor);
SetBkMode(hdc,TRANSPARENT);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
SelectObject(hdc, hobject);
EndPaint(hwnd, &ps);
break;
case WM_GETMINMAXINFO:
LPMINMAXINFO lpinfo;
lpinfo = (LPMINMAXINFO) lparam;
lpinfo->ptMaxTrackSize.x = 500;
lpinfo->ptMaxTrackSize.y = 400;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lparam);
}
return 0;
}
/**
* Callback function of "Foreground color" dialog box.
*/
LRESULT CALLBACK foreground(HWND hdlg, UINT message, WPARAM wParam, LPARAM lparam)
{
switch (message)
{
case WM_INITDIALOG:
int nColor;
for (nColor = 0; nColor < sizeof(g_crItems)/sizeof(DWORD); nColor++)
{
SendDlgItemMessage(hdlg, IDC_FOREGROUND, CB_ADDSTRING, 0, (LPARAM) g_crItems[nColor]);
if (g_fgColor == g_crItems[nColor])
SendDlgItemMessage(hdlg, IDC_FOREGROUND, CB_SETCURSEL, nColor, 0);
}
return TRUE;
case WM_MEASUREITEM:
LPMEASUREITEMSTRUCT lpmis;
lpmis = (LPMEASUREITEMSTRUCT) lparam;
lpmis->itemWidth = 10;
lpmis->itemHeight = 22;
break;
case WM_DRAWITEM:
HDC hdc;
RECT rc;
COLORREF cr;
HBRUSH hbrush, hbrHighlight, hbrBackground;
DRAWITEMSTRUCT * pdis;
pdis = (DRAWITEMSTRUCT *)lparam;
hdc = pdis->hDC;
rc = pdis->rcItem;
// NULL object ?
if (pdis->itemData == -1) return 0;
// Brushes.
hbrHighlight = CreateSolidBrush(0xFFFFFF - g_bgColor);
hbrBackground = CreateSolidBrush(g_bgColor);
switch (pdis->itemAction)
{
case ODA_DRAWENTIRE:
switch (pdis->CtlID)
{
case IDC_FOREGROUND:
rc = pdis->rcItem;
cr = (COLORREF) pdis->itemData;
FillRect(hdc, &rc, hbrBackground);
InflateRect(&rc, -1, -1);
hbrush = CreateSolidBrush((COLORREF)cr);
FillRect(hdc, &rc, hbrush);
DeleteObject(hbrush);
FrameRect(hdc, &rc, (HBRUSH) GetStockObject(WHITE_BRUSH));
break;
}
// *** FALL THROUGH ***
case ODA_SELECT:
rc = pdis->rcItem;
if (pdis->itemState & ODS_SELECTED)
h
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Acolorpicker_src.zip (42个子文件)
colorpicker_src
.vs
ColorPicker
v15
Browse.VC.db 30.54MB
.suo 31KB
ipch
a61a5ab2ec0750af.ipch 320KB
ColorPicker.cpp 12KB
ColorPicker.plg 2KB
ColorPicker.ncb 65KB
ColorPicker.sln 1KB
ColorPicker.aps 6KB
ColorPicker.h 341B
ColorPicker.vcxproj.filters 2KB
ColorPicker.dsw 545B
StdAfx.cpp 298B
ColorPicker.dsp 4KB
resource.h 1KB
ColorPicker.ICO 1KB
StdAfx.h 934B
ColorPicker.vcxproj.user 165B
ColorPicker.vcxproj 8KB
Backup
ColorPicker.rc 5KB
UpgradeLog.htm 34KB
Debug
ColorPicker.log 327B
StdAfx.obj 136KB
ColorPicker.ilk 2.1MB
ColorPicker.obj 21KB
ColorPicker.tlog
CL.write.1.tlog 1KB
CL.read.1.tlog 15KB
rc.write.1.tlog 286B
rc.read.1.tlog 3KB
CL.command.1.tlog 2KB
link.write.1.tlog 878B
ColorPicker.lastbuildstate 225B
link.command.1.tlog 1KB
rc.command.1.tlog 440B
link.read.1.tlog 4KB
ColorPicker.res 2KB
vc141.idb 435KB
ColorPicker.pdb 5.86MB
ColorPicker.pch 7.44MB
vc141.pdb 492KB
ColorPicker.exe 790KB
ColorPicker.opt 76KB
ColorPicker.exe 44KB
共 42 条
- 1
资源评论
五一编程
- 粉丝: 1w+
- 资源: 882
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功