Closed Thread
Results 1 to 9 of 9

Thread: About to finish it just need a push ! (Win32 + C )

  1. #1
    Moudi's Avatar
    Moudi is offline Programmer
    Join Date
    Jan 2010
    Posts
    166
    Blog Entries
    1
    Rep Power
    9

    About to finish it just need a push ! (Win32 + C )

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <string.h>
    #define ID_EDIT 1
    #define ID_BUTTON 2
    #define ID_TEXT 3
    #define ARRAY_SIZE 10000;
    static int len;
    char str[900];
    int i;
    char temp[1000000];
    char Arry[20];
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                LPSTR lpCmdLine, int nCmdShow )
    {
      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 | 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 | 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, (LPWSTR)str, len);
                for(i=0; i<len; i++)
                {
     strcpy(temp, "[color=blue");
                    strcpy(temp, "]");
                    strcpy(temp, (const char *)str[i]);
                    strcpy(temp, "[ / color]");
                }
                SetWindowText(hwndEdit2, (LPCWSTR)temp);
            }
                    break;
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
      }
      return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    SO you can see that the problem is in the str[i];

    i wonder why ! I've tried to cast it to (const char *) but it didn't work. so any idea's ?

    Oh and i know i didn't use ARRAY_SIZE i'm using it later

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    bobdark's Avatar
    bobdark is offline Programmer
    Join Date
    Jan 2010
    Location
    Haifa, Israel
    Posts
    164
    Rep Power
    9

    Re: About to finish it just need a push ! (Win32 + C )

    Thats because str[i] is a character. What exactly are you trying to do there? Im asking because I didn't really read your code, its a type problem. If you want to pass the part of the string starting at index i - you should call
    Code:
    strcpy(temp, &str[i]);
    or
    Code:
    strcpy(temp, str+i);
    , don' know what's more readable.

  4. #3
    Moudi's Avatar
    Moudi is offline Programmer
    Join Date
    Jan 2010
    Posts
    166
    Blog Entries
    1
    Rep Power
    9

    Re: About to finish it just need a push ! (Win32 + C )

    The point of this program is to :
    1 Read the input from first texbox
    2- pass it to a string and take every character and colorize it with BB codes and save every step in temp.
    3- print it in second texbox.

    Well with the code you supplied it doesn't crash anymore, but the output is chinese stuff

  5. #4
    Moudi's Avatar
    Moudi is offline Programmer
    Join Date
    Jan 2010
    Posts
    166
    Blog Entries
    1
    Rep Power
    9

    Re: About to finish it just need a push ! (Win32 + C )

    Guys i finished it, i can't believe how happy i am D:
    my first GUI'D PROGRAM.
    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
    #define ARRAY_SIZE 10000;
    static int len;
    char str[900];
    int i;
    char temp[10000000];
    char *Arry[20][20];
    int r;
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                LPSTR lpCmdLine, int nCmdShow )
    {
        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");
      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);
                for(i=0; i<len-1; i++)
                {
                    srand(time(NULL));
                    r= rand() &#37; 19;
                    strcat(temp,"[color=");
                    strcat(temp, Arry[r]);
                    strcat(temp, "]");
                    strncat(temp, &str[i],1);
                    strcat(temp, "[/color]");
                }
                    SetWindowText(hwndEdit2, temp);
    
            }
                    break;
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
      }
      return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    All i need to do is work out a dynamic rand ...

  6. #5
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: About to finish it just need a push ! (Win32 + C )

    Your problem probably comes from using a char array when you should be using a wchar_t array. If you notice, you typecast temp as a LPCWSTR which stands for Long Pointer to Constant Wide-character STRing.This means you need to declare str and temp as arrays of wchar_t instead of char, and use the wide-character string functions wcscmp, wcscpy, and so on. Look here for more information about wide-character stuff.

    EDIT: Oops - wrong and late. Well, I tried. In any case, I do think you should be using the wchar_t stuff because-- I think--things could go wrong with a char array if you're not careful. Although, if you're using the TEXT() macro then you should be using the TCHAR functions instead. Technically more correct, but I guess it's not necessary? Just my two cents.
    sudo rm -rf /

  7. #6
    Moudi's Avatar
    Moudi is offline Programmer
    Join Date
    Jan 2010
    Posts
    166
    Blog Entries
    1
    Rep Power
    9

    Re: About to finish it just need a push ! (Win32 + C )

    heheheh thanks anyway mate

  8. #7
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: About to finish it just need a push ! (Win32 + C )

    Not doing my reputation any good...
    sudo rm -rf /

  9. #8
    Moudi's Avatar
    Moudi is offline Programmer
    Join Date
    Jan 2010
    Posts
    166
    Blog Entries
    1
    Rep Power
    9

    Re: About to finish it just need a push ! (Win32 + C )

    You must spread some Reputation around before giving it to dargueta again.

    Don't worry i already repped you like 2 days ago

  10. #9
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: About to finish it just need a push ! (Win32 + C )

    Thanks!
    sudo rm -rf /

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. To finish my project
    By xle_camry in forum Java Help
    Replies: 21
    Last Post: 07-01-2011, 01:29 PM
  2. Replies: 3
    Last Post: 05-25-2011, 04:02 PM
  3. Finish the Code!
    By Donovan in forum Games
    Replies: 6
    Last Post: 12-19-2008, 02:10 PM
  4. Finish the sentence:)
    By Donovan in forum Games
    Replies: 9
    Last Post: 10-29-2008, 11:32 AM
  5. Replies: 5
    Last Post: 12-03-2007, 08:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts