cambalinho 142 Practically a Posting Shark

i'm trying create a class for getting the child controls from it's parent, but without sucess :(

class ChildControls
{
private:
    vector<HWND> childcontrols;
    UINT childcontrolsindex;
    HWND windowparent;

public:
    ChildControls(const HWND parent)
    {
        windowparent=parent;
        //EnumChildWindows(parent, EnumChildProc, 0);
    }

    UINT childcontrolscount()
    {
        return childcontrolsindex;
    }

    HWND GetHWND(UINT index)
    {
        EnumChildWindows( windowparent,
                              [this]( HWND hwnd, LPARAM lParam )
                              {
                                    this->childcontrols.push_back(hwnd);
                                    this->childcontrolsindex = this->childcontrols.size(); // TODO:
                                    return TRUE;
                              },
                              0);


        if(index>=childcontrolsindex)
            index=childcontrolsindex-1;
        return childcontrols[index];
    }
}ChildControls;

EnumChildWindows() isn't correct with 3rd and 4th arguments :(
please can anyone advice me?

cambalinho 142 Practically a Posting Shark

seems that i found some problems... when i change the parent, i can lose somethings or the HWND is changed ;)
that's why, when i try change the hot key, i can get several problems.
but i need more information, please

cambalinho 142 Practically a Posting Shark

i belive that you call it Acelerator Keys(alt key + letter key for activate the button(for exemple) click. that function help me make the simulation, but when the caption\text is changed, the hot key must be changed too, but seems not correctly :(

cambalinho 142 Practically a Posting Shark

RegisterHotKey is for we use the combined keys and the WM_HOTKEY message. i use these function for use the alt combination... but i need ask: can i re-regist the combination keys?

cambalinho 142 Practically a Posting Shark

thank you. now i can draw the windows 98 theme and windows xp theme and another drawed button... very cool... thanks for all

cambalinho 142 Practically a Posting Shark

yes.. you have right... the SetWindowText() don't works with hButton when i use BS_OWNERDRAW style.
for finish these topic, let me ask anotherthing: when i draw the button face(the WM_DRAWITEM message), why i get the windows XP visual style instead windows 98\2000 visual style?
the OpenThemeData() function is the problem?

cambalinho 142 Practically a Posting Shark

heres the entire code. don't forget link the library: libuxtheme.a(i use the code blocks... see what libary is used with your IDE).

#include <windows.h>
#include <stdio.h>
#include <string>
#include <Uxtheme.h> //for use the theme functions
#include <Vsstyle.h> //for use the BP_PUSHBUTTON or others const's


using namespace std;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("RandRect") ;

HINSTANCE a;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{

    HWND hwnd ;
    MSG msg ;
    a=hInstance;
    WNDCLASS wndclass ;
    wndclass.style = 0 ;
    wndclass.lpfnWndProc = WndProc ;
    wndclass.cbClsExtra = 0 ;
    wndclass.cbWndExtra = 0 ;
    wndclass.hInstance = hInstance ;
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
    wndclass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(0,0,255)) ;
    wndclass.lpszMenuName = NULL ;
    wndclass.lpszClassName = szAppName ;

    if (!RegisterClass (&wndclass))
    {
        MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR) ;
        return 0 ;
    }

    hwnd = CreateWindowEx (0,szAppName, TEXT ("Random Rectangles"),
            WS_OVERLAPPEDWINDOW | WS_TABSTOP,
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            NULL, NULL, hInstance, NULL) ;

    ShowWindow (hwnd, iCmdShow) ;
    UpdateWindow (hwnd) ;

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

bool KeyPressed(int a)
{
    if(GetAsyncKeyState(a))
    {
        return true;
    }
    else
    {
        return false;
    }
}

char upper(char str1)                                           //2
{

 if(str1>96 && str1<123)                           //4
       str1= str1-32;                                      //5
                                                     //6
 return str1;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    static HWND hButton;
    static HINSTANCE hInstance = GetModuleHandle(NULL);
    static HICON HandleIcon;
    static string caption="hell&o"; …
cambalinho 142 Practically a Posting Shark

thanks for all..
anotherthing: when we do a draw Button, why the WM_COMMAND message is ignored?

cambalinho 142 Practically a Posting Shark

these code avoids the flickers, but i can't use it because can slow down the windows messages:

InvalidateRect(hButton, NULL, false); // TRUE to erase the background
            Sleep(100);
            UpdateWindow(hButton);

so what you advice more?

cambalinho 142 Practically a Posting Shark

i love your code ;)
but i get that function like a infinite loop, because of InvalidateRect() function. and i get flickers.

cambalinho 142 Practically a Posting Shark

i'm trying call the WM_DRAWITEM message from WM_KEYUP message without sucess :(

bool KeyPressed(int a)
{
    if(GetAsyncKeyState(a))
    {
        return true;
    }
    else
    {
        return false;
    }
}

//in WM_KEYUP message
if(KeyPressed(VK_MENU)==true) SendMessage(hButton, WM_DRAWITEM,NULL,NULL);

what i'm doing wrong with SendMessage?

cambalinho 142 Practically a Posting Shark

thanks for all

cambalinho 142 Practically a Posting Shark

thank you. now i need ask:
1 - can i change the icon position?
2 - can i use the windows 2000 button style and continue using the image?
3 - can i use the '\t' text format?

cambalinho 142 Practically a Posting Shark

but goind back to the question:
what i'm doing wrong for create the Bitmap, in memory?

cambalinho 142 Practically a Posting Shark

i never use that message with a button, but i don't want lose the button face :(

cambalinho 142 Practically a Posting Shark

now i know why these type of error: "crosses initialization of 'objecname'"
because i can't do something like these:

HDC memdc=GetDC(hwnd);

but i must do:

HDC memdc;
memdc=GetDC(hwnd);

(i did with HDC and GetDC(), but it's valid for very objects and functions)
now i must see why i can't show the bitmap :(

case WM_SHOWWINDOW:

            //create the button
            HandleButton=CreateWindowEx (0,"button", "hello\t\tHI",
            WS_CHILD | WS_VISIBLE |  BS_TEXT | BS_BOTTOM |BS_BITMAP,
            100, 100,500, 200,hwnd, (HMENU)4000,hInstance, 0) ;

            //create a dc and bitmap in memory
            BITMAP bm;
            HBITMAP g_hbmBall;
            g_hbmBall =(HBITMAP) LoadImage(hInstance, "C:\\coeurs-03.bmp",IMAGE_BITMAP,LR_DEFAULTSIZE,LR_DEFAULTSIZE,LR_LOADFROMFILE);
            HDC hdc;
            hdc=GetDC(hwnd);
            HDC hdcMem;
            hdcMem=CreateCompatibleDC(hdc);
            HBITMAP hbmOld;
            hbmOld =(HBITMAP) SelectObject(hdcMem, g_hbmBall);

            SendMessage(HandleButton, BM_SETIMAGE, IMAGE_BITMAP,(LPARAM)g_hbmBall );
            return 0;
cambalinho 142 Practically a Posting Shark

or did i forget add something to the project?
for test, i did a copy-paste of that code... but i continue with same errors.
maybe i need add 1 library or something... or select any option... i use the CodeBlocks IDE.

cambalinho 142 Practically a Posting Shark

sorry... i continues witht several errors :(
please tell what i'm doing wrong... please

cambalinho 142 Practically a Posting Shark

i'm trying building a BITMAP from memory, but isn't easy :(

            //create the button
            HandleButton=CreateWindowEx (0,"button", "hello\t\tHI",
            WS_CHILD | WS_VISIBLE |  BS_TEXT | BS_BOTTOM |BS_BITMAP,
            100, 100,500, 200,hwnd, (HMENU)4000,hInstance, 0) ;

            //create a dc and bitmap in memory
            HDC memoryDC =CreateCompatibleDC(GetDC(hwnd));
            HBITMAP bitmap=CreateCompatibleBitmap(GetDC(hwnd),500,200);
            SelectObject(memoryDC, bitmap);

            //get the icon
            HandleIcon=(HICON)LoadImage(hInstance,"C:\\acrobat.ico",IMAGE_ICON,SM_CXICON,SM_CYICON,LR_LOADFROMFILE | LR_DEFAULTCOLOR);
            DrawIcon(memoryDC,0,0,HandleIcon);
            TextOut(memoryDC,0,0,"hello world",11);

            //send the bitmap to button
            SendMessage(HandleButton, BM_SETIMAGE, IMAGE_BITMAP,(LPARAM)bitmap );
            return 0;

my problem is when i create the HDC and HBITMAP... i'm getting several errors:

error: "jump to case label [-fpermissive]"
error: "crosses initialization of 'HBITMAP__* bitmap'"
error: "crosses initialization of 'HDC__* memoryDC'"
error: "jump to case label [-fpermissive]"
error: "crosses initialization of 'HBITMAP__* bitmap'"
error: "crosses initialization of 'HDC__* memoryDC'"

what i'm doing wrong?

cambalinho 142 Practically a Posting Shark

i see what you mean. thanks
seems that i must do the BITMAP(you will see the next thread) for show the image and text in same time ;)

cambalinho 142 Practically a Posting Shark

i used that style, but the text isn't showed too :(

cambalinho 142 Practically a Posting Shark

using the WM_KEYUP message: how can i combine the keys?

if(wParam== VK_CONTROL & 'a') MessageBox(NULL,"hi", "hi",MB_OK);

if i click on control key, the message is showed.... but my combination key is ctrl+a.... so how can i combine the keys? :(

cambalinho 142 Practically a Posting Shark

i have 'Automatically Watch Articles I Post In?' selected.

heres the state:

if i'm login:

  • i can recive the PM mail notification;

  • i don't recive the post mail notification;

if i'm log off: i receive normaly the mail notification.

cambalinho 142 Practically a Posting Shark

i have that option selected... the problem is when i'm login in forum: i don't receive them(only about the PM) :(

cambalinho 142 Practically a Posting Shark

i'm reading these page: http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951%28v=vs.85%29.aspx
but see the Remarks section:

Remarks

For illustrations of the principal button styles such as BS_CHECKBOX and BS_GROUPBOX, see Button Types.

The appearance of text or an icon or both on a button control depends on the BS_ICON and BS_BITMAP styles, and whether the BM_SETIMAGE message is sent. The possible results are as follows.

BS_ICON or BS_BITMAP set?   BM_SETIMAGE called?     Result
Yes                                 Yes             Show icon only.
No                                  Yes             Show icon and text.
Yes                                 No              Show text only.
No                                  No              Show text only

(the green it's the table)
for we use the BM_SETIMAGE, we must use the the SendMessage() function. now see my code:

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    static HWND HandleButton;
    static HICON HandleIcon;

    switch (iMsg)
    {
        case WM_DESTROY:
            DestroyIcon(HandleIcon);
            PostQuitMessage (0) ;
            return 0 ;
        case WM_CREATE:

            HandleButton=CreateWindow (TEXT("button"), TEXT ("hello\t\tHI"),
            WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_LEFT,
            100, 100,500, 200,hwnd, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL) ;
            HandleIcon=(HICON)LoadImage(NULL,"c:\\acrobat.ico",IMAGE_ICON,LR_DEFAULTSIZE,LR_DEFAULTSIZE,LR_LOADFROMFILE);
            SendMessage(HandleButton, BM_SETIMAGE, IMAGE_ICON,(LPARAM)HandleIcon );
            return 0;
    }
    return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}

i have sure about the path, unless the 'C' letter is case sensitive.
please tell me what i'm doing wrong with that information\code

cambalinho 142 Practically a Posting Shark

when we create child controls, what is the style for accept text formats?
(i mean: '\t', '\n' and others)

cambalinho 142 Practically a Posting Shark

when i use the ownerdraw message, with button(for exemple), do i lose the button face or only the text?
(i need show a text and image, without lose the button face)

cambalinho 142 Practically a Posting Shark

;)
the problem isn't resolved, but i will use your tip: refresh the Watched Articles ;)
hey... thanks for all

cambalinho 142 Practically a Posting Shark

thanks for all... realy... thanks

cambalinho 142 Practically a Posting Shark

triumphost: please give me an example for test it(just with windows message not entire code) ;)
i know use the function(i think lol), but i don't know if i need 1st show the scrollbars or something.

cambalinho 142 Practically a Posting Shark

thanks to both for all information, maybe now i understand how can i get the 'DC size' ;)
thanks to both

cambalinho 142 Practically a Posting Shark

let me ask you 1 thing: almost microsoft programs use win32 functions(directly or indirectly, maybe not the with Visual Studio .NET or above):

  • so when we draw more than the image size(maybe the mouse position can help me), how they change the scrollbar values?

  • when we put a control after client size(even only the control size), how they change the scrollbar values?(unless theres the create control parent messages)

cambalinho 142 Practically a Posting Shark

hello Dani.
we have spoken about these problem before. and i continue with problem :(
if my english is confused, please tell me

cambalinho 142 Practically a Posting Shark

imagine the image is more big than the client size, so i can get the image size from the file or BITMAP structure. but if you edit the image and draw(with mouse, for example) something more big than the image size. doing these type of size, manualy will be very complex :(
and if i put a control with a position more big than that size???
these manualy will be very complex :(

cambalinho 142 Practically a Posting Shark
  • the GetWindowRect() give me the window size and position;
  • the GetClientRect() give me the window size without inclued the scrollbars\menus\borders\others;
    so when 1 image is more big than client size, what size i can use? DC size?
    and if a child window position is more big than client size??? what size do i need? the DC size do the job?
cambalinho 142 Practically a Posting Shark

so i'm loking for the DC size, right?
(help me with right terms)

cambalinho 142 Practically a Posting Shark

thank you very much. but i'm confused in anotherthing:

GetClientRect (hwnd, &rect) ;

give me the actual DC size or window size without scrollbars\menus\border\others?

cambalinho 142 Practically a Posting Shark

by the book, i read that with WM_SIZE message i can get the client size instead use the GetClientRect() function:

case WM_SIZE:
            GetClientRect (hwnd, &rect) ;
            VerticalScrollSize=rect.bottom;
            si.cbSize = sizeof(si);
            si.fMask  = SIF_ALL;
            GetScrollInfo (hwnd, SB_VERT, &si);
            si.nMin = 0;
            si.nPos = VerticalScroll;
            si.nMax = VerticalScrollSize-2;
            si.nPage=2;
            SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
            InvalidateRect(hwnd, NULL, TRUE);
            return 0;

but i continue confuse with nMax and nPage... and i belive the nMin is 0(zero).
can anyone explain better please?
because i'm getting wrong thumb size :(

cambalinho 142 Practically a Posting Shark

isn't that problem. the problem was that i didn't use the SB_THUMBTRACK scrollbar message.

case WM_VSCROLL:
            si.cbSize = sizeof(si);
            si.fMask  = SIF_ALL;
            GetScrollInfo (hwnd, SB_VERT, &si);
            switch (LOWORD (wParam))
            {
                case SB_TOP:
                    VerticalScroll=0;
                    return 0;
                case SB_BOTTOM:
                    VerticalScroll=VerticalScrollSize;
                    return 0;
                case SB_LINEUP:
                    VerticalScroll-=ScrollMove;
                    break;
                case SB_LINEDOWN:
                    VerticalScroll+=ScrollMove;
                    break;
                case SB_THUMBPOSITION:
                    VerticalScroll=HIWORD (wParam);
                    break;
                case SB_THUMBTRACK:
                    VerticalScroll=HIWORD (wParam);
                    break;
                case SB_PAGEDOWN:
                    VerticalScroll+=ScrollMove*10;
                    break;
                case SB_PAGEUP:
                    VerticalScroll-=ScrollMove*10;
                    break;
            }
            if (VerticalScroll<=0) VerticalScroll=0;
            if (VerticalScroll>=VerticalScrollSize) VerticalScroll=VerticalScrollSize;
            si.nMin = 0;
            si.nPos = VerticalScroll;
            si.nMax = VerticalScrollSize-2;
            si.nPage=2;
            SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
            InvalidateRect(hwnd, NULL, TRUE);
            return 0;

now works fine.. thanks
and yes i must use the ScrollInfo() functions with SCROLLINFO structure.
i hope these problem helps others ;)

cambalinho 142 Practically a Posting Shark

i'm testing the win32 scrollbars, but i'm with 1 problem: when i use the SB_THUMBPOSITION message, why the window isn't repainted( the WM_PAINT message isn't used)?

case WM_VSCROLL:
            switch (LOWORD (wParam))
            {
                case SB_LINEUP:
                    VerticalScroll-=1;
                    break;
                case SB_LINEDOWN:
                    VerticalScroll+=1;
                    break;
                case SB_THUMBPOSITION:
                    VerticalScroll=HIWORD (wParam);
                    break;
                case SB_PAGEDOWN:
                    VerticalScroll+=10;
                    break;
                case SB_PAGEUP:
                    VerticalScroll-=10;
                    break;
            }
            SetScrollPos (hwnd, SB_VERT, VerticalScroll, TRUE) ;
            InvalidateRect(hwnd,NULL,TRUE);
            return 0;
cambalinho 142 Practically a Posting Shark

thanks maybe i can thot in anotherthing ;)
sorry, if i take time to answer i have problems with mails notifications, on posts, when i'm log in...strange but true

cambalinho 142 Practically a Posting Shark

what means 'afx_msg'?
isn't a C++ commands\code

cambalinho 142 Practically a Posting Shark

i continue with 1 problem with emails notifications and i have the option selected :(

  • if i'm log out/off, i recive the mails notifications normaly(new posts and private message);
  • if i'm log in, i only recive the mails notifications about the private messages :(
    for see that someone aswer me, when i'm log in, i must refresh the page browser for see if someone answer me... it's very bored :(
    please Dani, tell me something
cambalinho 142 Practically a Posting Shark

so tell me, if you can:

how MFC do for use these 'events':

void classname::functionname(...)
????
(like i said, i'm less than bigginer with MFC. but i remember that i must create 1 class for use the windows messages, but i don't know how the code is regenerated :( )

cambalinho 142 Practically a Posting Shark

sorry, but when i said"without re-declare it inside of Cow class", i mean avoid these line:

class Cow : public Animal
{
    void Speak(); //i need avoid these line
};

void Cow::Speak()
{
    cout << "Moo!\n");
}
cambalinho 142 Practically a Posting Shark

but we can do something like that with MFC, right?
(i'm less than bigginer with MFC.. so sorry if i fail in something)
how can i validate the Speak() function without re-declare it inside of Cow class?

cambalinho 142 Practically a Posting Shark

i only see 1 'problem'(for my objective) in Cow and Cat. why? because i must re-declare the Speak() function.

class Cow : public Animal
{

};

void Cow::Speak()
{
    cout << "Moo!\n");
}

:( i can't do these code, because of these error:
Speak isn't a member of Cow :(

cambalinho 142 Practically a Posting Shark

sorry i understand that isn't the 1st time that i ask... and you always helped me... thanks for all.

but i continue thinking that something like these is possible with C++:

class test
{
    public:
        virtual void print(string message);
};

class a: public test
{
};

void a::print(string message)
{
    printf("hello %s",message);
}

but the problem is the print() not been re-declared in class 'a'... but MFC make these possible :(
so how can i resolve these problem?
(sorry, if i'm bored you with these problem. but i need do something like these)

cambalinho 142 Practically a Posting Shark

yes.. the line 11 was my mistake.. sorry.
i continue confuse on how can i resolve that problem :(
like we have seen in MFC, it's possible be done, but i need more information :(

cambalinho 142 Practically a Posting Shark
#include <iostream>

using namespace std;

class test
{
    public:
        void print(string message);
};

class a:test
{
};

void a::print(string message)
{
    printf("hello %s",message);
}

error message: "no 'void a::print(std::string)' member function declared in class 'a'"

how can i resolve these problem?
like you see in class 'a':
1 - is derived from class 'test';
2 - the function isn't redeclared;
3 - the function is changed outside of class 'test'.