|
楼主 |
发表于 2007-8-11 19:01:07
|
显示全部楼层
源码
#include <windows.h>
#include <commdlg.h>
#include <stdlib.h>
#include <string.h>
#include "resource.h"
BOOL InitColorChoose(HWND hwnd);
static CHOOSECOLOR cc;
static COLORREF crCustColors[16];
static char pstrBuffer[1000];
static int iLength;
static int rgb;
static char rgbChar[6];
static HINSTANCE hInst;
static char temp[] = "|cFF";
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK EditTextWndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK StaticTextWndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK AboutBoxProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[] = TEXT("War3ColorerTest");
static HMENU hMenu;
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass (&wndclass))
{
MessageBox(NULL,TEXT("This program requires WindowsNY!"),szAppName,MB_ICONERROR);
return 0;
}
hMenu = LoadMenu(hInstance,MAKEINTRESOURCE(ID_MENU));
hwnd = CreateWindow(szAppName,
TEXT("War3Colorer"),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
200,
NULL,
hMenu,
hInstance,
NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message ,WPARAM wParam,LPARAM lParam)
{
static int j;
static HWND hwndButton;
static int cxClient,cyClient;
switch(message)
{
case WM_CREATE:
hwndButton = CreateWindow(TEXT("Button"),TEXT("开始"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,90,50,100,75,hwnd,(HMENU) 1,((LPCREATESTRUCT)lParam)->hInstance,NULL);
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
LoadIcon(hInst,MAKEINTRESOURCE(ID_ICON));
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case 1:
{
if (InitColorChoose(hwnd))
rgb = cc.rgbResult;
itoa(cc.rgbResult,rgbChar,16);
for (j = 0;j<=6;j++)
if (rgbChar[j] == NULL)
rgbChar[j] = '0';
DialogBox(hInst,TEXT("EditTextBox"),hwnd,EditTextWndProc);
break;
}
case 11:
DialogBox(hInst,TEXT("AboutBox"),hwnd,AboutBoxProc);
break;
}
return 0;
}
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
if (((cxClient > 300) || (cyClient > 200) || (cxClient <300 || cyClient < 200)))
{
MoveWindow(hwnd,GetSystemMetrics(SM_CXSCREEN)/2-200,GetSystemMetrics(SM_CYSCREEN)/2-200 ,300 ,200 ,TRUE);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
BOOL InitColorChoose(HWND hwnd)
{
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = hwnd;
cc.hInstance = NULL;
cc.rgbResult = RGB(0x80,0x80,0x80);
cc.lpCustColors = crCustColors;
cc.Flags = CC_RGBINIT | CC_FULLOPEN;
cc.lCustData = 0;
cc.lpfnHook = NULL;
cc.lpTemplateName = NULL;
return ChooseColor(&cc);
}
BOOL CALLBACK EditTextWndProc(HWND hDlgET,UINT message,WPARAM wParam,LPARAM lParam)
{
char tempstr[] = "|r";
static BOOL iCheck;
static int MB;
switch(message)
{
case WM_INITDIALOG:
{
SetFocus(GetDlgItem(hDlgET,ID_EDITTEXT));
return TRUE;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_OK:
iLength = GetWindowTextLength(GetDlgItem(hDlgET,ID_EDITTEXT));
GetWindowText(GetDlgItem(hDlgET,ID_EDITTEXT),pstrBuffer,iLength + 1);
strcat(temp,rgbChar);
strcat(temp,pstrBuffer);
strcat(temp,tempstr);
EndDialog(hDlgET,FALSE);
DialogBox(hInst,TEXT("StaticTextBox"),GetParent(hDlgET),StaticTextWndProc);
return TRUE;
case ID_CANCEL:
EndDialog(hDlgET,FALSE);
return TRUE;
}
break;
}
return FALSE;
}
BOOL CALLBACK StaticTextWndProc(HWND hDlgST,UINT message,WPARAM wParam,LPARAM lParam)
{
int b;
switch(message)
{
case WM_INITDIALOG:
SetWindowText(GetDlgItem(hDlgST,10),temp);
for(b=-1;b<=iLength+10;b++)
temp = NULL;
strcpy(temp,"|cFF");
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
SetWindowText(GetDlgItem(hDlgST,10)," ");
EndDialog(hDlgST,FALSE);
return TRUE;
}
break;
}
return FALSE;
}
BOOL CALLBACK AboutBoxProc(HWND hDlgA,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
{
EndDialog(hDlgA,FALSE);
return TRUE;
}
break;
}
return FALSE;
} |
|