#include <windows.h>
#include "resource.h"
COLORREF tempcolor[3]={RGB(120,45,128),RGB(0,135,189),RGB(200,120,123)};
static int color=0;//定义颜色
//定义对话框处理函数
BOOL CALLBACK DialogFun(HWND, UINT,WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if(100==DialogBox(hinstance,"mydialog",NULL,(DLGPROC)DialogFun))
{
PostQuitMessage(WM_QUIT);
}
while (GetMessage(&msg, (HWND) NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);
}
BOOL CALLBACK DialogFun(HWND dlghwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
switch(message)
{
RECT rect;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
HBRUSH brush,oldbrush;
hdc = BeginPaint(dlghwnd, &ps);
brush=CreateSolidBrush(tempcolor[color]);//创建画刷
GetClientRect(dlghwnd,&rect);//获得主窗口的面积
oldbrush=(HBRUSH)SelectObject(hdc,brush);
Rectangle(hdc,rect.left, rect.top, rect.right, rect.bottom);
SelectObject(hdc,oldbrush);
EndPaint(dlghwnd, &ps);
return FALSE;
case WM_INITDIALOG :
//ShowWindow(NULL,SW_SHOWNORMAL);
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(dlghwnd,100);//定义100来确定退出对话框
return TRUE;
case ID_CHANGECOLOR:
color=1;
InvalidateRect(dlghwnd,NULL,FALSE);
return TRUE;
case ID_CHANGECOLOR2:
color=2;
InvalidateRect(dlghwnd,NULL,FALSE);
return TRUE;
case ID_CHANGECOLOR3:
color=0;
InvalidateRect(dlghwnd,NULL,FALSE);
return TRUE;
case ID_PASTE:
//HWND pasteHwnd;
if(OpenClipboard(NULL))//打开剪贴板
{
if(IsClipboardFormatAvailable(CF_TEXT))
{
HANDLE hClip;
char* pBuffer;
hClip=GetClipboardData(CF_TEXT);
pBuffer=(char*)GlobalLock(hClip);
GlobalUnlock(hClip);
SetDlgItemText(dlghwnd,IDC_EDIT_PASTE,pBuffer);
}
else
{
MessageBox(dlghwnd,"您的剪贴板中不是文本文件","there no text",MB_OK);
}
CloseClipboard();//关闭剪贴板
}
}
default:
return FALSE;
}
}
本文地址:http://com.8s8s.com/it/it22286.htm