How can my program automatically colour a word???? For example, when I write the word "help", that word should be coloured with red! How can I do that?????
thanx and sorry, my english is bad!!!!![]()
This is a discussion on colours!!!! within the Windows Programming forums, part of the Platform Specific Boards category; How can my program automatically colour a word???? For example, when I write the word "help", that word should be ...
How can my program automatically colour a word???? For example, when I write the word "help", that word should be coloured with red! How can I do that?????
thanx and sorry, my english is bad!!!!![]()
It depends.....Originally posted by eAgle
How can my program automatically colour a word???? For example, when I write the word "help", that word should be coloured with red! How can I do that?????
thanx and sorry, my english is bad!!!!![]()
Is your application a fullblown GUI windows program or is it console based?
it's GUI
From MSDN
Code:SetTextColor The SetTextColor function sets the text color for the specified device context to the specified color. COLORREF SetTextColor( HDC hdc, // handle to device context COLORREF crColor // text color ); Parameters hdc Handle to the device context. crColor Specifies the color of the text. Return Values If the function succeeds, the return value is a color reference for the previous text color. If the function fails, the return value is CLR_INVALID. Windows NT: To get extended error information, callGetLastError. Remarks The text color is used to draw the face of each character written by the TextOut and ExtTextOut functions. The text color is also used in converting bitmaps from color to monochrome and vice versa.
can you give me an simple example, please???? I'm inexperienced in windows programming
As I am bored.......
Here's a brief example;
Here's an app that paints some txt on its window.....you click down the menu and you can change the colourCode:#include <windows.h> #include "resource.h" LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); char szClassName[] = "WindowsApp"; HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; g_hInst = hThisInstance; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProc; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof(WNDCLASSEX); wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); if(!RegisterClassEx(&wincl)) return 0; hwnd = CreateWindowEx(0,szClassName, "Windows App", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, HWND_DESKTOP,NULL, hThisInstance,NULL ); ShowWindow(hwnd, nFunsterStil); UpdateWindow(hwnd); while(GetMessage(&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; //handle to device context static enum {RED = 0,GREEN,BLUE};//enumerate possible colours static int nCol = 0;//Active colour COLORREF col;//RGB colour to use PAINTSTRUCT ps;//Paint structure switch (message) { case WM_COMMAND: switch(LOWORD(wParam)){//What col was selected in menu case ID_COLOUR_GREEN: nCol = GREEN; break; case ID_COLOUR_BLUE: nCol = BLUE; break; case ID_COLOUR_RED: nCol = RED; break; } InvalidateRect(hwnd,NULL,TRUE);//Make window repaint itself break; case WM_PAINT: switch(nCol){//What is the active colour case BLUE: col = RGB(0,0,255); break; case GREEN: col = RGB(0,255,0); break; case RED: col = RGB(255,0,0); break; } hdc = BeginPaint(hwnd, &ps);//Get DC and remove paint message SetTextColor(hdc,col);//Set the colour of test TextOut(hdc,100,100,"Hello World - in colour",23);//Some text to write EndPaint(hwnd,&ps);//Clear DC break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
I have enclosed the project files in case you want to run the program - they work on VC++
Doh...here are the files