#include <windows.h>
#include <stdio.h>
#include <string.h>
#include<time.h>
#include<stdlib.h>
/*************Defining ID's**********/
#define ID_EDIT 1
#define ID_BUTTON 2
#define ID_TEXT 3
#define ID_CLIP 4
/*************Defining ID's**********/
//
//
//
/*****************Vars***************/
static int len;
char str[900];
int i;
char temp[10000000];
char *Arry[38][20];
static HWND hwndEdit;
static HWND hwndEdit2;
static HWND hwndButton;
static HWND hwndButton2;
HWND hWnd;
int r;
/**************Vars****************/
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
strcpy(Arry[0], "#2B65EC");
strcpy(Arry[1], "#463E41");
strcpy(Arry[2], "#2B3856");
strcpy(Arry[3], "#151B54");
strcpy(Arry[4], "#2B60DE");//colored arrays and ****
strcpy(Arry[5], "#8D38C9");
strcpy(Arry[6], "#8467D7");
strcpy(Arry[7], "#488AC7");
strcpy(Arry[8], "#737CA1");
strcpy(Arry[9], "#F6358A");
strcpy(Arry[10], "#7D053F");
strcpy(Arry[11], "#C12283");
strcpy(Arry[12], "#F535AA");
strcpy(Arry[13], "#6A287E");
strcpy(Arry[14], "#6C2DC7");
strcpy(Arry[15], "#571B7e");
strcpy(Arry[16], "#7D1B7E");
strcpy(Arry[17], "#8B31C7");
strcpy(Arry[18], "#7E587E");
strcpy(Arry[19], "#B93B8F");
strcpy(Arry[20], "##F6358A");
strcpy(Arry[21], "#5E767E");
strcpy(Arry[22], "#5E7D7E");
strcpy(Arry[23], "#254117");
strcpy(Arry[24], "#667C26");
strcpy(Arry[25], "#E9AB17");
strcpy(Arry[26], "##00FFFF");
strcpy(Arry[27], "#F87431");
strcpy(Arry[28], "#E66C2C");
strcpy(Arry[29], "#FF00FF");
strcpy(Arry[30], "#7F462C");
strcpy(Arry[31], "#C85A17");
strcpy(Arry[32], "#F76541");
strcpy(Arry[33], "#7D2252");
strcpy(Arry[34], "#E41B17");
strcpy(Arry[35], "#C11B17");
strcpy(Arry[36], "#4E9258");
strcpy(Arry[37], "#00FF00");
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = TEXT( "Colorme" ); // Class name of window
wc.hInstance = hInstance ; // instance of window
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); // background bruch
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor(0,IDC_ARROW);
RegisterClass(&wc);
CreateWindow( wc.lpszClassName, TEXT("Color Me by MOUDI !"), // title, and window creation
WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
100, 100, 500, 500, 0, 0, hInstance, 0);
while( GetMessage(&msg, NULL, 0, 0)) { //message loop
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CREATE:
{
hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE |ES_MULTILINE|ES_AUTOHSCROLL|WS_HSCROLL|ES_AUTOHSCROLL|WS_BORDER,
10, 30, 465, 100, hwnd, (HMENU) ID_EDIT,
NULL, NULL);
hwndButton = CreateWindow( TEXT("button"), TEXT("Color Me !"),
WS_VISIBLE | WS_CHILD,
10,140,232,25,
hwnd, (HMENU) ID_BUTTON, NULL, NULL); // the ID_BUTTON is the ID of this button, to check if pressed
hwndEdit2 = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE |ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOHSCROLL|WS_HSCROLL|WS_BORDER,
10, 178,465, 270, hwnd, (HMENU) ID_TEXT,
NULL, NULL);
hwndButton2 = CreateWindow( TEXT("button"), TEXT("Clipboard"),
WS_VISIBLE | WS_CHILD,
250,140,232,25,
hwnd, (HMENU) ID_CLIP, NULL, NULL);//the ID_CLIP is the ID of this button, used to check if button pressed
EnableWindow(hwndEdit2, FALSE);
break;
}
case WM_COMMAND:
if(LOWORD(wParam) == 2){ // if button with ID 2 is pressed, aka ID_BUTTON, the colorme one
len = GetWindowTextLength(hwndEdit) + 1; // Get the length of text entered in textbox 1
GetWindowText(hwndEdit, str, len); // Get the text from textbox 1 and put it in the string "str"
srand(time(NULL)); // seed random according to time
for(i=0; i<len-1; i++)
{
srand(rand()); // Randomize the seed because our CPU processes at micro seconds and time don't change
r= rand() % strlen(Arry);
strcat(temp,"<font color=\"");// here i'm putting the colors in a temp string
strcat(temp, Arry[r]);
strcat(temp, "\">");
strncat(temp, &str[i],1);
strcat(temp, "</font>");
}
SetWindowText(hwndEdit2, temp); // displaying the temp string in textbox 2, the bottom one
strcpy(temp, "\0"); // emptying string
}
if(LOWORD(wParam) == 4){ // if button with ID 4 is clicked AKA ID_CLIP
strcpy(temp, "\0");
HLOCAL hMem = LocalAlloc( LHND, GetWindowTextLength(hwndEdit2)+1);
char* cptr = (char*) LocalLock(hMem);
GetWindowText(hwndEdit2, temp, GetWindowTextLength(hwndEdit2) + 1);
memcpy( cptr, temp, GetWindowTextLength(hwndEdit2)+1 );
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
LocalUnlock( hMem );
LocalFree( hMem );
CloseClipboard();
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
The snippet is a little commented. it can easily be converted to BB codes, enjoy !


Sign In
Create Account


Back to top









