#include
#include
# include
# include "resource. H"
# include "winres. H"
The static CHOOSECOLOR cc.
The static COLORREF CR [16].
The static COLORREF backResult;
The static COLORREF wordColor;
HBRUSH HBRUSH;
//function declaration
BOOL InitWindow (HINSTANCE HINSTANCE, int nCmdShow);
BOOL CALLBACK ColorProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM);
LRESULT a CALLBACK WinProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM);
Int WINAPI WinMain (HINSTANCE HINSTANCE,//handle to the current instance
HINSTANCE hPrevInstance,//handle to an instance before
PSTR szCmdLine,//command line characters
Int iCmdShow)//window display mode
{
MSG MSG.
Char * p;
//create the main window
if (! InitWindow (hInstance, iCmdShow))
return FALSE;
P=0;
//entering the message loop: pick up from the application's message queue messages,
//send message processing process, when you pick the WM_QUIT message, withdraw from the message loop,
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
Return MSG. WParam;
}
The static BOOL InitWindow (HINSTANCE HINSTANCE, int iCmdShow)
{
The static TCHAR szAppName []=TEXT (" EasyWin ");//application name
The HWND HWND;//window handle
WNDCLASS wcMainWnd;//window class structure
The ATOM a;
//fill the window class structure
WcMainWnd. Style=CS_VREDRAW | CS_HREDRAW;
WcMainWnd. LpfnWndProc=WinProc;
WcMainWnd. CbClsExtra=0;
WcMainWnd. CbWndExtra=0;
WcMainWnd. HInstance=hInstance;
WcMainWnd. HIcon=LoadIcon (hInstance, IDI_APPLICATION);
WcMainWnd. HCursor=LoadCursor (NULL, IDC_ARROW);
WcMainWnd. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
WcMainWnd. LpszMenuName=MAKEINTRESOURCE (IDR_MENU1);
WcMainWnd. LpszClassName=szAppName;
//registered window class
A=RegisterClass (& amp; WcMainWnd);
if (! A)
{
MessageBox (NULL, TEXT (" registered window class failed!" ), szAppName,
MB_ICONERROR);
return 0;
}
//create the main window
HWND=CreateWindow (szAppName,//the window class name
The TEXT (" Windows application basic framework "),//the window title
WS_OVERLAPPEDWINDOW,//the window style
100,//the window position of the x coordinate
100,//window position y
400,//window width
300,//the height of the window
NULL,//handle to the parent window
NULL,//the menu handle
HInstance,//the application instance handle
NULL);//window to create data pointer
if (! HWND) return FALSE.
//display and update window
ShowWindow (HWND, iCmdShow);
UpdateWindow (HWND);
return TRUE;
}
LRESULT a CALLBACK WinProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
HDC HDC.
PAINTSTRUCT ps;
The RECT the RECT.
The switch (the message)
{
Case WM_CREATE message handler:
Cc. The Flags=CC_RGBINIT | CC_FULLOPEN;
Cc. The hInstance=NULL;
Cc. HwndOwner=hWnd;
Cc. LCustData=https://bbs.csdn.net/topics/0;
Cc. LpCustColors=CR;
Cc. LpfnHook=NULL;
Cc. LpTemplateName=NULL;
Cc. LStructSize=sizeof (CHOOSECOLOR);
Cc. RgbResult=RGB (0, 0, 0);
return 0;
Case the WM_PAINT://client area redraw message
//handle to get equipment environment
HDC=BeginPaint (hWnd, & amp; Ps);
//window client area rectangle
GetClientRect (hWnd, & amp; The rect);
//set the text color
SetTextColor (HDC, wordColor);
//output text
SDFKGJFSK DrawText (HDC, TEXT (" "),
1, & amp; The rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
//release resources
If (wParam)
{
HBrush=CreateSolidBrush (backResult);
SetClassLong (hWnd GCL_HBRBACKGROUND, (LONG) backResult);
The InvalidateRect (hWnd, NULL, TRUE);
}
EndPaint (hWnd, & amp; Ps);
return 0;
Case WM_COMMAND:
The switch (LOWORD (wParam))
{
Case ID_40001:
ChooseColor (& amp; Cc);
WordColor=cc. RgbResult;
The InvalidateRect (hWnd, NULL, TRUE);
return 0;
Case ID_40002:
DialogBox (NULL,
MAKEINTRESOURCE (IDD_DIALOG1), hWnd ColorProc);
The InvalidateRect (hWnd, NULL, TRUE);
/* SendMessage (hWnd, WM_COMMAND wParam, lParam); */
}
Case WM_DESTROY:
The PostQuitMessage (0);
return 0;
}
Return DefWindowProc (hWnd, message, wParam, lParam);
}
BOOL CALLBACK ColorProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
BYTE bRed;
BYTE bGreen;
BYTE bBlue;
The static char copyResult0 [10], copyResult1 [10], copyResult2 [10].
Char Result [50].
The switch (the message)
{
Case WM_INITDIALOG:
return FALSE;
Case WM_COMMAND:
The switch (LOWORD (wParam))
{
Case IDC_BUTTON1:
ChooseColor (& amp; Cc);//call the common dialog
BackResult=cc. RgbResult;
BRed=GetRValue (backResult);
BGreen=GetGValue (backResult);
BBlue=GetBValue (backResult);
Sprintf (Result, "% d", bRed);
Memcpy (& amp; CopyResult0 [0], Result, sizeof (Result));
Memset (Result, 0, sizeof (Result);
Sprintf (Result, "% d", bGreen);
Memcpy (& amp; CopyResult1 [0], Result, sizeof (Result));
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull