Support Forums
Color Me , C pure code with GUI - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Color Me , C pure code with GUI (/showthread.php?tid=5296)



Color Me , C pure code with GUI - Moudi - 03-16-2010

Code:
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include<time.h>
#include<stdlib.h>
#define ID_EDIT 1
#define ID_BUTTON 2
#define ID_TEXT 3
static int len;
char str[900];
int i;
char temp[10000000];
char *Arry[38][20];
int r;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
            LPSTR lpCmdLine, int nCmdShow )
{
    strcpy(Arry[0], "Dodgerblue");
    strcpy(Arry[1], "Antiquewhite");
    strcpy(Arry[2], "Aqua");
    strcpy(Arry[3], "Aquamarine");
    strcpy(Arry[4], "Azure");
    strcpy(Arry[5], "Beige");
    strcpy(Arry[6], "Bisque");
    strcpy(Arry[7], "Black");
    strcpy(Arry[8], "Blanchedalmond");
    strcpy(Arry[9], "Blue");
    strcpy(Arry[10], "Blueviolet");
    strcpy(Arry[11], "Brown");
    strcpy(Arry[12], "Burlywood");
    strcpy(Arry[13], "Chartreuse");
    strcpy(Arry[14], "Chocolate");
    strcpy(Arry[15], "Coral");
    strcpy(Arry[16], "Cornflowerblue");
    strcpy(Arry[17], "Cornsilk");
    strcpy(Arry[18], "Crimson");
    strcpy(Arry[19], "Darkcyan");
    strcpy(Arry[20], "Darkgoldenrod");
    strcpy(Arry[21], "Darkgray");
    strcpy(Arry[22], "Darkgreen");
    strcpy(Arry[23], "Darkkhaki");
    strcpy(Arry[24], "Darkmagenta");
    strcpy(Arry[25], "Darkolivegreen");
    strcpy(Arry[26], "Darkorange");
    strcpy(Arry[27], "Darkorchid");
    strcpy(Arry[28], "Darkred");
    strcpy(Arry[29], "Darksalmon");
    strcpy(Arry[30], "Darkseagreen");
    strcpy(Arry[31], "Darkslateblue");
    strcpy(Arry[32], "Darkslategray");
    strcpy(Arry[33], "Darkturquoise");
    strcpy(Arry[34], "Darkviolet");
    strcpy(Arry[35], "Deeppink");
    strcpy(Arry[36], "Deepskyblue");
    strcpy(Arry[37], "Dimgray");
  MSG  msg ;
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "Static Control" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0,IDC_ARROW);


  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, TEXT("Change Text"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 500, 500, 0, 0, hInstance, 0);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
  static HWND hwndEdit;
  static HWND hwndEdit2;
  static HWND hwndButton;
  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,465,25,
            hwnd, (HMENU) ID_BUTTON, NULL, NULL);

        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);

        break;
    }
    case WM_COMMAND:
        if(HIWORD(wParam) == BN_CLICKED){
            len = GetWindowTextLength(hwndEdit) + 1;
            GetWindowText(hwndEdit, str, len);
            srand(time(NULL));
            for(i=0; i<len-1; i++)
            {
                r= rand() % 37;
                strcat(temp,"[color=");
                strcat(temp, Arry[r]);
                strcat(temp, "]");
                strncat(temp, &str[i],1);
                strcat(temp, "[/color]");

            }
                SetWindowText(hwndEdit2, temp);
                strcpy(temp, "\0");

        }
                break;
    case WM_DESTROY:
    {
        PostQuitMessage(0);
        return 0;
    }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

I made it from scratch. here's the bin

http://www.mediafire.com/?yrmdhxdcy2e

not gonna post virus scan, if you don't trust me just compile it.
Hello supportforums :)

This is my new app xDD

test run


RE: Color Me , C pure code with GUI - se7en - 03-27-2010

Really Nice dude!


RE: Color Me , C pure code with GUI - TomC - 06-15-2010

This is really nice, thanks for posting Smile.


RE: Color Me , C pure code with GUI - Fallenour - 06-15-2010

(03-16-2010, 02:14 AM)Moudi Wrote:
Code:
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include<time.h>
#include<stdlib.h>
#define ID_EDIT 1
#define ID_BUTTON 2
#define ID_TEXT 3
static int len;
char str[900];
int i;
char temp[10000000];
char *Arry[38][20];
int r;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
            LPSTR lpCmdLine, int nCmdShow )
{
    strcpy(Arry[0], "Dodgerblue");
    strcpy(Arry[1], "Antiquewhite");
    strcpy(Arry[2], "Aqua");
    strcpy(Arry[3], "Aquamarine");
    strcpy(Arry[4], "Azure");
    strcpy(Arry[5], "Beige");
    strcpy(Arry[6], "Bisque");
    strcpy(Arry[7], "Black");
    strcpy(Arry[8], "Blanchedalmond");
    strcpy(Arry[9], "Blue");
    strcpy(Arry[10], "Blueviolet");
    strcpy(Arry[11], "Brown");
    strcpy(Arry[12], "Burlywood");
    strcpy(Arry[13], "Chartreuse");
    strcpy(Arry[14], "Chocolate");
    strcpy(Arry[15], "Coral");
    strcpy(Arry[16], "Cornflowerblue");
    strcpy(Arry[17], "Cornsilk");
    strcpy(Arry[18], "Crimson");
    strcpy(Arry[19], "Darkcyan");
    strcpy(Arry[20], "Darkgoldenrod");
    strcpy(Arry[21], "Darkgray");
    strcpy(Arry[22], "Darkgreen");
    strcpy(Arry[23], "Darkkhaki");
    strcpy(Arry[24], "Darkmagenta");
    strcpy(Arry[25], "Darkolivegreen");
    strcpy(Arry[26], "Darkorange");
    strcpy(Arry[27], "Darkorchid");
    strcpy(Arry[28], "Darkred");
    strcpy(Arry[29], "Darksalmon");
    strcpy(Arry[30], "Darkseagreen");
    strcpy(Arry[31], "Darkslateblue");
    strcpy(Arry[32], "Darkslategray");
    strcpy(Arry[33], "Darkturquoise");
    strcpy(Arry[34], "Darkviolet");
    strcpy(Arry[35], "Deeppink");
    strcpy(Arry[36], "Deepskyblue");
    strcpy(Arry[37], "Dimgray");
  MSG  msg ;
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "Static Control" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0,IDC_ARROW);


  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, TEXT("Change Text"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 500, 500, 0, 0, hInstance, 0);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
  static HWND hwndEdit;
  static HWND hwndEdit2;
  static HWND hwndButton;
  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,465,25,
            hwnd, (HMENU) ID_BUTTON, NULL, NULL);

        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);

        break;
    }
    case WM_COMMAND:
        if(HIWORD(wParam) == BN_CLICKED){
            len = GetWindowTextLength(hwndEdit) + 1;
            GetWindowText(hwndEdit, str, len);
            srand(time(NULL));
            for(i=0; i<len-1; i++)
            {
                r= rand() % 37;
                strcat(temp,"[color=");
                strcat(temp, Arry[r]);
                strcat(temp, "]");
                strncat(temp, &str[i],1);
                strcat(temp, "[/color]");

            }
                SetWindowText(hwndEdit2, temp);
                strcpy(temp, "\0");

        }
                break;
    case WM_DESTROY:
    {
        PostQuitMessage(0);
        return 0;
    }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

I made it from scratch. here's the bin

http://www.mediafire.com/?yrmdhxdcy2e

not gonna post virus scan, if you don't trust me just compile it.
Hello supportforums :)

This is my new app xDD

test run

Im sorry, but if I ever see you use this again, ill have to kill you. This hurts my eyes really bad.