SO you can see that the problem is in the str[i];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); }
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
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 callorCode:strcpy(temp, &str[i]);, don' know what's more readable.Code:strcpy(temp, str+i);
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
Guys i finished it, i can't believe how happy i am D:
my first GUI'D PROGRAM.
All i need to do is work out a dynamic rand ...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() % 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); }
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 /
heheheh thanks anyway mate![]()
Not doing my reputation any good...![]()
sudo rm -rf /
You must spread some Reputation around before giving it to dargueta again.
Don't worry i already repped you like 2 days ago![]()
Thanks!
sudo rm -rf /
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks