Click here to Skip to main content
16,006,845 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Visual Studio Express Edition 2008 for Commercial Application Pin
CPallini4-Oct-08 0:47
mveCPallini4-Oct-08 0:47 
QuestionGradientFill in Moving Dialog.. Pin
gothic_coder3-Oct-08 21:27
gothic_coder3-Oct-08 21:27 
AnswerRe: GradientFill in Moving Dialog.. Pin
enhzflep3-Oct-08 21:58
enhzflep3-Oct-08 21:58 
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder3-Oct-08 22:53
gothic_coder3-Oct-08 22:53 
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder3-Oct-08 23:30
gothic_coder3-Oct-08 23:30 
GeneralRe: GradientFill in Moving Dialog.. Pin
enhzflep4-Oct-08 1:05
enhzflep4-Oct-08 1:05 
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder4-Oct-08 1:21
gothic_coder4-Oct-08 1:21 
GeneralRe: GradientFill in Moving Dialog.. Pin
enhzflep4-Oct-08 1:57
enhzflep4-Oct-08 1:57 
Beautiful!! Smile | :)

Glad it helped. Something else you can do is use a bitmap then create a patterned brush from that. If you create your own class like I did in that example, you can just set the background brush of your window class to the patterned brush that holds your bitmap. Windows will automatically tile your background image. So, if I have a window thats 100 x 600 pixels and I just want a left to right gradient, I'll just create a 100 x 1 bitmap and assign it to the background brush. Super light on code, super-light on resources.

This means that you don't even have to handle the WM_ERASEBKGND messages.

Here's an example:

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */

//    HBITMAP hbmp = (HBITMAP)LoadImage(NULL, "image.bmp", IMAGE_BITMAP, 0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
//    HBITMAP hbmp = readTGA("image2.tga");
//    HBITMAP hbmp = readRle24Tga("image2.tga");
    HBITMAP hbmp = loadTgaResource(GetModuleHandle(NULL), MAKEINTRESOURCE(1001));

    hbr = CreatePatternBrush(hbmp);
    DeleteObject(hbmp);


    if (!hbmp)
    {
        MessageBox(NULL, "Couldn't load image file", "ERROR", MB_ICONEXCLAMATION);
        return 0;
    }

//    hbr = CreateSolidBrush(RGB(0xd4,0xd0,0xc8));
    wincl.hbrBackground = hbr;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;


You find a bunch of gems like this trick in any of the books by Charles Petzold. I think this one came from the 10 year old "Programming Windows Fifth Edition" - I have it as a chm, there's I think there's also one available as a pdf

Oh, and thanks for the rose - the name's Simon.
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder4-Oct-08 2:50
gothic_coder4-Oct-08 2:50 
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder4-Oct-08 3:01
gothic_coder4-Oct-08 3:01 
GeneralRe: GradientFill in Moving Dialog.. Pin
enhzflep4-Oct-08 3:48
enhzflep4-Oct-08 3:48 
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder4-Oct-08 4:39
gothic_coder4-Oct-08 4:39 
GeneralRe: GradientFill in Moving Dialog.. Pin
gothic_coder6-Oct-08 0:10
gothic_coder6-Oct-08 0:10 
QuestionNew Stand-alone application Pin
Karmendra Suthar3-Oct-08 21:05
Karmendra Suthar3-Oct-08 21:05 
AnswerRe: New Stand-alone application Pin
Saurabh.Garg3-Oct-08 21:11
Saurabh.Garg3-Oct-08 21:11 
GeneralRe: New Stand-alone application Pin
Karmendra Suthar3-Oct-08 21:59
Karmendra Suthar3-Oct-08 21:59 
GeneralRe: New Stand-alone application Pin
Saurabh.Garg3-Oct-08 22:02
Saurabh.Garg3-Oct-08 22:02 
GeneralRe: New Stand-alone application Pin
CPallini4-Oct-08 0:45
mveCPallini4-Oct-08 0:45 
QuestionHow to test ActiveX control in VC++ 2008? Pin
followait3-Oct-08 19:15
followait3-Oct-08 19:15 
AnswerRe: How to test ActiveX control in VC++ 2008? Pin
Jaime Olivares3-Oct-08 19:57
Jaime Olivares3-Oct-08 19:57 
QuestionCString Array To LPCSTR Pin
MsmVc3-Oct-08 18:54
MsmVc3-Oct-08 18:54 
AnswerRe: CString Array To LPCSTR Pin
Jaime Olivares3-Oct-08 19:17
Jaime Olivares3-Oct-08 19:17 
GeneralRe: CString Array To LPCSTR Pin
MsmVc3-Oct-08 19:24
MsmVc3-Oct-08 19:24 
GeneralRe: CString Array To LPCSTR Pin
PJ Arends3-Oct-08 19:33
professionalPJ Arends3-Oct-08 19:33 
GeneralRe: CString Array To LPCSTR Pin
Jaime Olivares3-Oct-08 19:54
Jaime Olivares3-Oct-08 19:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.