cambalinho 142 Practically a Posting Shark

in form WM_COMMAND message i must do:

SendMessage((HWND)lParam , WM_COMMAND, wParam, lParam);

and now works fine ;)
thanks
readers: if some message don't works, see how you did the Message Loop.. yes i by experience, i lose some keys... but change for the normal Message Loop, works fine ;)

cambalinho 142 Practically a Posting Shark

heres the code more cool and working:

//test if a key\combination keys is pressed
bool AreAllKeysPressed(const std::vector<int> &keys)
{
    int state = 0x8000;
    for (int key : keys)
    {
        state &= GetAsyncKeyState(key);

    }
    return (state) != 0;
}

bool CombineKeys(std::vector<std::vector<int>> const &keys)
{
    static bool PreviousKeyPressed=false;
    static DWORD StartTimer = GetTickCount();
    static DWORD AllKeysTimer = 0;
    static int i=0;

        //test if the 1st key was pressed
        if((AreAllKeysPressed(keys[0])==true) && PreviousKeyPressed==false)
        {
            i=0;
            PreviousKeyPressed=true;
            StartTimer = GetTickCount();
            AllKeysTimer=0;
            i++;
        }
        //if the last combination have only 1 key
        else if((i==(int)keys.size()-1) && (AreAllKeysPressed(keys[(int)keys.size()-1])==true) && PreviousKeyPressed==true && keys[(int)keys.size()-1].size()==1)
        {
            PreviousKeyPressed=false;
                StartTimer = 0;
                AllKeysTimer=0;
                i=0;
                return true;
        }
        //testing if the keys are pressed in same time
        //but you only have 1 second for that
        else if(GetTickCount() - AllKeysTimer <= 500 && PreviousKeyPressed==true)
        {
            if(AreAllKeysPressed(keys[i])==true && i!=(int)keys.size()-1)
            {
                PreviousKeyPressed=true;
                StartTimer = GetTickCount();
                AllKeysTimer=0;
                i++;
            }
            else if(AreAllKeysPressed(keys[(int)keys.size()-1])==true && i==(int)keys.size()-1)
            {
                PreviousKeyPressed=false;
                StartTimer = 0;
                AllKeysTimer=0;
                i=0;
                return true;
            }
        }
        //test if the StartTimer have 2 seconds
        else if ((GetTickCount() - StartTimer >= 2000))//now i put the timer here ;)
        {
            StartTimer =0;
            AllKeysTimer=0;
            PreviousKeyPressed=false;
            i=0;
        }
        //test if the last key was pressed
        else if((i==(int)keys.size()-1) && (AreAllKeysPressed(keys[(int)keys.size()-1])==true) && PreviousKeyPressed==true)
        {
            StartTimer=0;
            AllKeysTimer=GetTickCount();
        }
        //test if the next key was pressed
        else if((AreAllKeysPressed(keys[i])==true) && PreviousKeyPressed==true)
        {
            PreviousKeyPressed=true;
            StartTimer = GetTickCount();
            AllKeysTimer=0;
            i++;
        }
        else if((AreAllKeysPressed(keys[i])==false) && PreviousKeyPressed==true)
        {
            AllKeysTimer=GetTickCount();
        }

        else
        {
            PreviousKeyPressed=false;
            StartTimer = GetTickCount();
            AllKeysTimer=0;
            i=0;
        }

    return false;
}

#define CombinationKeys(...) CombineKeys({__VA_ARGS__})

see the test samples:

if(CombinationKeys({'A','S'},{'W'},{'R','T'}, {'O'})==true) …
cambalinho 142 Practically a Posting Shark

i'm testing my property class for accept lambdas too:

/*properties

- how use create 1 property with macro:

      PROPERTY(TypeName,PropertyName,getfunction, setfunction)

- never forget to do 1 Copy Constructor inside of class's, that uses the property,
         for avoid copy the 'this' value\adress and use a diferent memory adress
*/
template <typename T>
class property
{
private:
    T PropertyValue;
    std::function<T(void)> getf;
    std::function<void(T)> setf;
public:

    property(const T value)
    {
        getf=nullptr;
        setf=nullptr;
        PropertyValue=value;
    };

    property(const property &value)  :  PropertyValue(value.PropertyValue) , getf(value.getf)
    {
    }

    property(std::function<T(void)> GetFunction=nullptr,std::function<void(T)> SetFunction=nullptr)
    {
        setf=SetFunction;
        getf=GetFunction;
    }

    property& operator=(const T &value)
    {
        PropertyValue=value;
        return *this;
    }

    property& operator=(const property &value)
    {
        PropertyValue = value.PropertyValue;
        getf = value.getf;

        return *this;
    }

    friend ostream& operator<<(ostream& os, property& dt)
    {
        if(dt.getf==nullptr && dt.setf==nullptr)
            os << dt.PropertyValue;
        else if (dt.getf!=nullptr)
            os << dt.getf();
        return os;
    }

    friend istream& operator>>(istream &input, property &dt)
    {
        input >> dt.PropertyValue;
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return input;
    }

    friend istream &getline(istream &in, property &dt)
    {
        getline(in, dt.PropertyValue);
        if (dt.setf!=nullptr)
            dt.setf(dt.PropertyValue);
        return in;
    }
};

template<typename T, typename Fnc1_t, typename Fnc2_t, typename classthis>
property<T> GetProperty(Fnc1_t Getter, Fnc2_t Setter, classthis clsthis)
{
    return property<T>(std::bind(Getter, clsthis), std::bind(Setter, clsthis, std::placeholders::_1));
}

#define PROPERTY(TypeName,PropertyName,getfunction, setfunction) \
property<TypeName> PropertyName{std::bind(&getfunction, *this),std::bind(&setfunction, *this, std::placeholders::_1)}

how i use it:

class k
{
private:
    string name;
public:
   property<string> Name([](){return name;}, [](string strname){name=strname;});

};

but i'm getting several 5 errors:
i belive that i mistake how build the lambda in 1 argument... please, anyone can tell me something?

cambalinho 142 Practically a Posting Shark

thanks for all my friend.... thanks

cambalinho 142 Practically a Posting Shark

thanks for correct me that. now i know that i can change my BL-5F to BL-6F without a problem ;)
because i use a diferent theme(needs more batery) and i use 3G mobile network(needs more batery too), and the original batery don't works 24h of capacity :(
thanks for all.. thanks

rubberman commented: Remember, when it comes to capacity (Amp Hours), more is better! +12
cambalinho 142 Practically a Posting Shark

i resolve the problem adding these line:

ShowWindow(hwnd, SW_NORMAL);
UpdateWindow(hwnd);
InvalidateRect(hwnd,NULL,true);//i add these line for fix that

after create the form.
thanks for all

cambalinho 142 Practically a Posting Shark

my mobile batery is BL-5F:
- 950mAh;
- 3,7V;
- 3,5Wh.

the BL-6F:
- 1200mAh;
- 3,7V;
- 4,4Wh.
the have the connection in same place. the 6F give me much more time with mobile.. and the Volts are the same. but i'm confused with Wh.
it's bad give more Wh to a mobile? it can damage the mobile?

cambalinho 142 Practically a Posting Shark

i, now, understand why don't works ;)
see my form window procedure:

static LRESULT CALLBACK WndProcForm(HWND HandleWindow, UINT msg, WPARAM wParam, LPARAM lParam)
        {
            static POINT PreviousLocation, Location;
            static bool Tracking = false;
            static MouseButtons MBButtons;
            static bool blControl = false;
            static bool blShift = false;
            static bool blResize = false;
            static int xPos = 0;
            static int yPos = 0;
            static UINT_PTR timerid;
            static bool blnDrag = false;
            static bool KeyPressed=false;
            static int KeyDownCount=0;
            form *inst = (form *)GetWindowLongPtr(HandleWindow, GWLP_USERDATA);

            if(inst!=NULL && inst->Create!=NULL && IsWindowVisible(inst->hWnd())==true)
            {
                static bool i=true;
                 if(i==true)
                 {
                    i=false;
                    inst->Create(inst->getLeft(), inst->getTop());
                    int a=GetLastError();
                    if (a!=0)
                        MessageBox(NULL,to_string(a).c_str(),"error",MB_OK);
                 }
            }

            if(inst!=NULL && inst->Paint!=NULL)
            {
                 static bool i=true;
                 if(i==true)
                 {
                     i=false;
                     SendMessage(inst->hwnd,WM_PAINT,wParam,lParam);
                 }
            }

            HBRUSH g_hbrBackground = NULL;

            //Working with messages
            switch(msg)
            {
                case WM_NCCREATE:
                {
                    CREATESTRUCT *p = (CREATESTRUCT *)lParam;
                    inst = (form *)p->lpCreateParams;
                    SetWindowLongPtr(HandleWindow, GWLP_USERDATA, (LONG_PTR)inst);
                    inst->hwnd = HandleWindow;
                }
                break;

the WM_PAINT message don't call my Paint() lambda, because, when i create the lambda, the Paint() is NULL. only works fine, because when we resize the form, the Paint() is called.
so i did that 2 'if': 1 for the Create() and another for the Paint()... but needs more work :(
anotherthing that i had tested too: if i do a constructor for recive the Paint(), it will works fine ;)

cambalinho 142 Practically a Posting Shark

in form class:

case WM_PAINT:
                {
                    if (inst->Paint==NULL) break;
                    PAINTSTRUCT  ps;
                    HDC hdc = BeginPaint(inst->hwnd, &ps);
                    inst->Paint(inst->hwnd,hdc);
                    EndPaint(inst->hwnd, &ps);
                }
                break;

(inst is the instance class pointer, but the problem is other)
the inst->Paint() is a lambda function.
heres the form instance code:

form a;
button c,g,b;

HBITMAP bmpSource = NULL;
HDC hdcSource = NULL;

int WinMain()
{


    a.Paint=[](HWND hwndWindow, HDC hdcWindow)
    {
        bmpSource = (HBITMAP)LoadImage(NULL, "C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        hdcSource = CreateCompatibleDC(GetDC(0));
        SelectObject(hdcSource, bmpSource);
        BitBlt(hdcWindow, 0, 0, 500, 500, hdcSource, 0, 0, SRCCOPY);

    };
//............

i can't see any problem with code...
but for see the paint image, i need resize(for exemple) the form... why?

cambalinho 142 Practically a Posting Shark

sorry triumphost, but i can show you a print screen about the button ;)
see these print screen: https://onedrive.live.com/?cid=C3EF456E15C8DEB6&id=C3EF456E15C8DEB6!1257&v=3
but i'm testing that function with a form

cambalinho 142 Practically a Posting Shark

heres a nice tutorial about regions: http://www.flipcode.com/archives/Win32_Window_Skinning.shtml
like you see, these tutorial is for forms.. so how we can do with child controls!?!
we can:
add the WS_CLIPCHILDREN or WS_CLIPSIBLINGS style, when we create a button\other control:

hwnd = CreateWindowEx(
                0,
                TEXT("CBUTTON"),
                strCaption.c_str(),
                WS_CHILD | WS_VISIBLE | BS_TEXT | WS_TABSTOP | BS_NOTIFY | WS_CLIPCHILDREN,
                intLeft, intTop, intWidth, intHeight,
                parent,
                NULL,
                mod,
                (LPVOID)this);

now i'm do anotherthing... instead normal shapes i want in image way: testing all pixels and 'avoid' 1 color:

HRGN HideBackcolor(HWND WindowHandle,color BackColor=-1)
{     
    HDC hdc=GetDC(WindowHandle);
    if(BackColor==-1)
        BackColor=GetPixel(hdc,0,0);
    HRGN regionold=NULL,regionnew=NULL;
    int x=0,y=0;
    RECT a;
    GetWindowRect(WindowHandle,&a);
    int width=a.right - a.left -1;
    int height=a.bottom - a.top -1;
    for (y=0; y<height; y++)
    {
        for(x=0; x<width; x++)
        {
            color b=GetPixel(hdc,x,y);
            if(b!=BackColor)
            {
                regionnew=CreateRectRgn(x,y,x+1,y+1);
                CombineRgn(regionold, regionold, regionnew, RGN_OR);
            }
        }
    }
    return regionold;
}

i belive that i have some problems with these code, maybe i'm confused with CombineRgn() function. because i get bad results(i mean what i see):(
the color isn't hide :(
so what i'm doing wrong?

cambalinho 142 Practically a Posting Shark

i put an image on form with WM_PAINT message.
but the image is, only, showed after resize(for example) the form. why is that? did i forget any style\extended style?

cambalinho 142 Practically a Posting Shark

now i must do another complex test ;)
maybe i can use several combinations of '&' and '|' ;)

cambalinho 142 Practically a Posting Shark

i found my problem:

int GetAllKeyPressed()
{
    int key=0;
    bool FirstKey=false;

    for(int i=0; i<256; i++)
    {
        if(GetAsyncKeyState(i) & 0x8000)
        {
            if(FirstKey==false)
            {
                key=i;
                FirstKey=true;
            }
            else
            {
                key=key&i;
            }
        }
    }
    return key;
}

thanks for all

cambalinho 142 Practically a Posting Shark

i'm working with a code for get all pressed keys inside of a variable:

int GetAllKeyPressed()
{
    int key=0;

    for(int i=0; i<256; i++)
    {
        if(GetAsyncKeyState(i) & 0x8000)
        {
            if(i==0)
                key=i;
            else
                key=key&i;
        }
    }
    return key;
}

if the key0 is pressed then put it in key variable. if key1 is pressed combine it with '&' with key.
so what i'm doing wrong?

cambalinho 142 Practically a Posting Shark

the problem was the 'if' order ;)

bool CombineKeys(std::vector<int> const keys)
{
    static bool PreviousKeyPressed=false;
    static DWORD StartTimer = GetTickCount();
    static int i=0;

        //test if the 1st key was pressed
        if((GetAsyncKeyState(keys[0]) & 0x8000) and PreviousKeyPressed==false)
        {
            i=0;
            PreviousKeyPressed=true;
            StartTimer = GetTickCount();
            i++;
        }
        //test if the StartTimer have 2 seconds
        else if (GetTickCount() - StartTimer >= 2000)//now i put the timer here ;)
        {
            SetWindowText(a,"hi");
            StartTimer =GetTickCount();
            PreviousKeyPressed=false;
            i=0;
        }
        //test if the last key was pressed
        else if((i==(int)keys.size()-1) && (GetAsyncKeyState(keys[(int)keys.size()-1]) & 0x8000) and PreviousKeyPressed==true)
        {
            PreviousKeyPressed=false;
            i=0;
            StartTimer=0;
            return true;

        }
        //test if the next key was pressed
        else if((GetAsyncKeyState(keys[i]) & 0x8000) and PreviousKeyPressed==true)
        {
            PreviousKeyPressed=true;
            StartTimer = GetTickCount();
            i++;
        }

        else
        {
            PreviousKeyPressed=false;
            StartTimer = GetTickCount();
            i=0;
        }

    return false;
}

//heres how we can use it:
if(CombineKeys({'A','B', VK_LEFT,'C'})
          MessageBox(NULL,"these combination keys activated","Combination Keys",MB_OK);

now i'm working with a diferent combination, for accept '&' and '|' ;)

cambalinho 142 Practically a Posting Shark
bool CombineKeys(std::vector<int> const keys)
{
    static bool PreviousKeyPressed=false;
    static DWORD StartTimer = 0;
    static int i=0;

        if((GetAsyncKeyState(keys[0]) & 0x8000) and PreviousKeyPressed==false)
        {
            i=0;
            SetWindowText(a,"hello");
            PreviousKeyPressed=true;
            StartTimer = GetTickCount();
            i++;
        }
        else if((i==(int)keys.size()-1) && (GetAsyncKeyState(keys[(int)keys.size()-1]) & 0x8000) and PreviousKeyPressed==true)
        {
            SetWindowText(a,"hihi");
            PreviousKeyPressed=false;
            i=0;
            return true;

        }
        else if((GetAsyncKeyState(keys[i]) & 0x8000) and PreviousKeyPressed==true)
        {

            SetWindowText(a,"hi");
            PreviousKeyPressed=true;
            StartTimer = GetTickCount();
            i++;
        }

        else if(GetTickCount() < (StartTimer + 2000))//2 seconds
        {
            StartTimer = GetTickCount();
            PreviousKeyPressed=false;
            i=0;
        }
        else
        {
            PreviousKeyPressed=false;
            StartTimer = GetTickCount();
            i=0;
        }

    return false;
}

almost corrected ;)
is these if corrected?

else if(GetTickCount() < (StartTimer + 2000))//2 seconds

seems not ok. because, after 2 seconds, the StartTimer isn't igual to GetTickCount():(

cambalinho 142 Practically a Posting Shark

i'm build a function for do the combination of keys(like the kombat games: we do some combination keys for do an actions):

bool CombineKeys(std::vector<int> const keys)
{
    static bool PreviousKeyPressed;
    static DWORD StartTimer = GetTickCount();
    static int i=0;

        if((GetAsyncKeyState(keys[0]) & 0x8000) and PreviousKeyPressed==false)
        {
            i=0;
            SetWindowText(a,"hello");
            PreviousKeyPressed=true;
            i++;
        }
        else if((i==(int)keys.size()-1) && (GetAsyncKeyState(i) & 0x8000) and PreviousKeyPressed==true)
        {
            SetWindowText(a,"hi");
            return true;
        }
        else if((GetAsyncKeyState(keys[i]) & 0x8000) and PreviousKeyPressed==true)
        {
            i++;
            PreviousKeyPressed=true;
        }

        else if(GetTickCount() < (StartTimer + 20000))//2 seconds
        {
            PreviousKeyPressed=false;
            i=0;
        }
        else
        {
            PreviousKeyPressed=false;
            i=0;
        }

    return false;
}

//heres how i use in keydown message
if(CombineKeys({'A','B'})==true)
            MessageBox(NULL,"hi","hi",MB_OK);

i see some problems with my function :(
seems the i not be plus 1, because only get the 1st if :(
if i press the next letter, don't do nothing :(
what i'm doing wrong?

cambalinho 142 Practically a Posting Shark

let me ask(i can be confused): the transparent(if i use an image on form) and the shaping forms aren't more or less the same?
or the transparent is only for see(just see and not use) what is behind the form?

cambalinho 142 Practically a Posting Shark

thanks for that info too ;)
i need ask anotherthing(sorry bored you): where the backcolor is hide, can i make a 'real' hole?(click on aplication that is on back?)
the backcolor is hide.. so why not click what is on form back?

cambalinho 142 Practically a Posting Shark

now i'm confused :(

"Apparently the problem is with Aero and hbrBackground being NULL as well as using Magenta"
what you bean?
and yes i tryied change for:

RGB(255,255,255)

and i get the same problem :(
(your sample color works fine)

cambalinho 142 Practically a Posting Shark

see what happens when i maximizate the form:
https://onedrive.live.com/?cid=C3EF456E15C8DEB6&id=C3EF456E15C8DEB6!1256&v=3
why i see an incomplete border of a form?

cambalinho 142 Practically a Posting Shark

now works.. but if i maximizate the form, i get the same problem. do i need repeat these when i change the form size?

cambalinho 142 Practically a Posting Shark

sorry.. i'm not good on design, but it's for show you the problem.
https://onedrive.live.com/?cid=C3EF456E15C8DEB6&id=C3EF456E15C8DEB6!1255&v=3
like you see the mouse icon is changed to text icon(see above the close form button). on back of my aplication theres the codeblocks ide(where i do the code).
like you see the form close button don't change for selection way(when the mouse icon is anbove of it). these is the problem.
the child buttons works normaly

cambalinho 142 Practically a Posting Shark

"My first solution works for fixing the focus. Other than that, I can't understand what it is you need fixing without seeing the code or a snippet of it or even a picture."
yes the child controls works normaly.
my form have the title bar: include the maxbox, minibox and closebox. if i click on them, the form loses the focus and the form\other aplication, that is on back, win the focus.
the form lose the backcolor(it's transparent) and loses more than that. the title bar is there, but it's same there isn't :(
sorry my english, but i'm trying :(
can i print the screen without lose the mouse icon?

cambalinho 142 Practically a Posting Shark

sorry.. the mouse isn't showed with PrintScreen.
the form is transparent, but, when i move the mouse above the 'X' button(for exemple).. the select effect don't happens and i can't click on it. if i click on that button, the form, on back, or even other application control, on back, recives the focus :(
is there another way for hide the backcolor?

cambalinho 142 Practically a Posting Shark

i have 1 problem with window procedure(i belive), the child controls have the BS_NOTIFY style, but the click or others(from BS_NOTIFY style) aren't working.. why?

//in button window procedure:
case WM_COMMAND:
            {
                switch(HIWORD(wParam))
                {
                    case BN_CLICKED:
                    {
                        inst->MouseClick();
                        MessageBox(NULL,"hi","hello",MB_OK);
                    }
                    break;
                }
                break;
            }
            break;

//in form window procedure:
case WM_COMMAND:
                {
                    return DefWindowProc(HandleWindow, WM_COMMAND, wParam, lParam);
                }
                break;

what i'm doing wrong?

cambalinho 142 Practically a Posting Shark

sorry.. not that. think in these way: the form is above the word(for exemple) and the mouse is above the form title bar. why the cursor is changed to text cursor icon?(the form title bar is above the word text)
if i click on form border, the word wins focus....
i just want hide the backcolor(or other color) on form, nothing more

cambalinho 142 Practically a Posting Shark

thanks for all.
but i need ask: the form that i use these function have the border and the close button... so why they aren't working?

cambalinho 142 Practically a Posting Shark

heres the code that i use for put the form transparent:

LONG style= GetWindowLong(hwnd, GWL_EXSTYLE);
                style=style |  WS_EX_LAYERED;
                SetWindowLong(hwnd, GWL_EXSTYLE, style);
                SetLayeredWindowAttributes(hwnd, clrBackColor, NULL, LWA_COLORKEY);

but i see problems :(
the form and the controls are showed, but the mouse events are ignored.
if i click on button or form, the form on back(even if it's from another aplication) wins the focus.... why these effect happens?

cambalinho 142 Practically a Posting Shark

true.. it's more complex, but i get the point ;)
i have several more errors on my class, but i can fix them easely(you fix the master error) ;)
i'm thinking, for more late, joing\combining the form with MDI and ChildMDI... why? because is more easy to use after that for MDI programs ;)
do you like the way i do the code? at least, using my code, it avoids hundreds of lines ;)

cambalinho 142 Practically a Posting Shark

i did these way:

static LRESULT CALLBACK WndProcForm(HWND HandleWindow, UINT msg, WPARAM wParam, LPARAM lParam)
        {
            static POINT PreviousLocation, Location;
            static bool Tracking = false;
            static MouseButtons MBButtons;
            static bool blControl = false;
            static bool blShift = false;
            static bool blResize = false;
            static int xPos = 0;
            static int yPos = 0;
            static UINT_PTR timerid;
            static bool blnDrag = false;
            form *inst = (form *)GetWindowLongPtr(HandleWindow, GWLP_USERDATA);

            if(inst!=NULL && inst->Create!=NULL)
            {
                 inst->Create(inst->intLeft, inst->intTop);
                 inst->Create=NULL;
            }

            //..................

but what you can tell me?

cambalinho 142 Practically a Posting Shark

now works fine... thanks for all ;)
i need 1 advice... just see these code:

#include "cambalinho.h"

form a;//these line creates and show the form

int WinMain()
{
    //here i change the create event... that is called from WM_CREATE message in window procedure
    a.Create=[](int x, int y)
    {
        a.setText("hello world");
    };

    a.MouseEnter=[]()
    {
        a.setText("enter");
    };

    a.MouseLeave=[]()
    {
        a.setText("exit");
    };

    return MessageLoop(a);
}

i need 1 advice, please :(
how can i, automatic, call the create event in a diferent way?(for be called, without use a construtor)
if these question is confused, please tell me

cambalinho 142 Practically a Posting Shark

i need show you something... but now i'm getting, again errors and i don't undertstand why :(
i just change the event create from static to normal variable and i delete these line...
see the entire code: http://pastie.org/9389129
sometimes i don't understand some errors :(
don't make sence to me :(
i just change the static Create event to normal event(delete the static).

cambalinho 142 Practically a Posting Shark

triumphost: sorry... but i was trying :(
thanks for correct me that ;)
i have more 1 question: these way can be used for child controls(for getting the pointer)?
i need 1 tip: when i create the variable, from form, button or other, the control is created and showed in moment.... but before i change the events (yah... inclued the create event). what you advice me?
put a variable static in window procedure for activate that event before others?(and not when the control is created)

cambalinho 142 Practically a Posting Shark

triumphost: thanks you very much, but i continue confuse: what i did wrong with my code?
(i'm trying see the diference code)

cambalinho 142 Practically a Posting Shark

see these inside of window procedure:

 form *inst = (form *)GetWindowLongPtr(HandleWindow, GWLP_USERDATA);//give me NULL(because the message box is showed), but no errors
        if (inst==NULL) MessageBox(NULL,"error", "error",MB_OK);

if i take of these message, the error(that image) isn't showed:

 //Working with messages
        switch(msg)
        {
            /* case WM_NCCREATE:
            {
                CREATESTRUCT *p = (CREATESTRUCT *)lParam;
                inst = (form *)p->lpCreateParams;
                SetWindowLongPtr(HandleWindow, GWLP_USERDATA, (LONG_PTR)inst);
                inst->hwnd = HandleWindow;
            }
            break;*/
            case WM_CREATE:
            {
                if(WindowMain==NULL)
                    WindowMain=HandleWindow;

               // inst->Create(inst->intLeft, inst->intTop);
            }
            break;

so, i belive, the error is from WM_NCCREATE message or passing the 'this' with CreateWindowEx() function.
what you can tell me?

cambalinho 142 Practically a Posting Shark

i'm getting problems, with your code, for get the pointer :(
i don't understand.... what i'm doing wrong?
tell me something for learn more please

cambalinho 142 Practically a Posting Shark

that main message loop is used in these way:

#include "cambalinho.h"
HWND WindowMain=NULL;//these is inside of cambalinho.h
//and it's value is added when the form is created

#define WinMain() WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE, LPSTR, int nCmdShow)
#define End() PostQuitMessage(0);

//Message Loop
WPARAM MessageLoop(HWND MainWindow)
{
    MSG messages;
    while(GetMessage(&messages,0,0,0)>0)
    {
        if(!IsDialogMessage(MainWindow,&messages))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
    }
    return messages.wParam;
}



form a;
form b;
button v(WindowMain);
button c(b);

//creating the window
int WinMain()
{

    c.MouseClick=[]()
    {
        v.setText("g&ood bye");
        Sleep(1000);
        End();
    };

    v.MouseClick=[]()
    {
        v.setText("hi");
    };

    return MessageLoop(a);
}

and now see the image: https://onedrive.live.com/?cid=C3EF456E15C8DEB6&id=C3EF456E15C8DEB6!1254&v=3

cambalinho 142 Practically a Posting Shark

sorry... i don't get errors, on code, but when i execute, i can't see the form and after some time i see the output message:
"Process terminated with status -1073741819"
what you think?

cambalinho 142 Practically a Posting Shark

heres my entire class: http://codepad.org/SrOIpP6t
my objective is trying get the form instance pointer in WndProcForm() callback function.
i use some static variables, because the WndProcForm() callback function is static(class member).

cambalinho 142 Practically a Posting Shark

triumphost: thanks... seen your code, i did:

void setParent(HWND parent=GetDesktopWindow())
    {
            WNDCLASSEX FormClass;
            char classname[]="form";
            HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);

            FormClass.cbSize        = sizeof(WNDCLASSEX);
            FormClass.style         = 0;
            FormClass.lpfnWndProc   = WndProcForm;
            FormClass.cbClsExtra    = 0;
            FormClass.cbWndExtra    = 0;
            FormClass.hInstance     = mod;
            FormClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
            FormClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
            FormClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
            FormClass.lpszMenuName  = NULL;
            FormClass.lpszClassName = classname;
            FormClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

            // register the new window class
            RegisterClassEx(&FormClass);

            hwnd = CreateWindowEx(WS_EX_TRANSPARENT , classname, strCaption.c_str(), WS_OVERLAPPEDWINDOW | WS_TABSTOP,
                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);

            if (hwnd == NULL)
                MessageBox(NULL, "Can't create the control", "error", MB_OK);

            ShowWindow(hwnd, SW_NORMAL);
            UpdateWindow(hwnd);

            clrBackColor= GetBkColor(GetDC(parent));
            clrTextColor = GetTextColor(GetDC(parent));


        RECT a;
        GetClientRect(hwnd,&a);
        intTop=a.top;
        intLeft=a.left;
        intWidth=a.right-a.left;
        intHeight=a.bottom-a.top;
    }


    //window procedure:
     static LRESULT CALLBACK WndProcForm(HWND HandleWindow, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        static POINT PreviousLocation, Location;
        static bool Tracking = false;
        static MouseButtons MBButtons;
        static bool blControl=false;
        static bool blShift=false;
        static bool blResize=false;
        static int xPos=0;
        static int yPos=0;
        static UINT_PTR timerid;
        static bool blnDrag=false;
        form *inst=NULL;


         HBRUSH g_hbrBackground = NULL;

        //Working with messages
        switch(msg)
        {
            case WM_NCCREATE:
            {
                CREATESTRUCT *p = (CREATESTRUCT *)lParam;
                inst = (form *)p->lpCreateParams;
                SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)form);
                inst->hwnd = hwnd;
                if (inst==NULL)
                     inst = (form *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
            }
            break;
            //....

but i'm getting several errors :(
error: "invalid use of member 'form::hwnd' in static member function"

cambalinho 142 Practically a Posting Shark

theres another way.. i have done with another code, but don't works with these code :(
let me ask in other way: when we use CreateWindowEx() function with 'this' class pointer. how can i get these pointer inside of a CALLBACK function?

cambalinho 142 Practically a Posting Shark

you have right. the problem was not the window procedure(i did new tests)... but the order of code ;)
i fix that in constructor and now my 'event' is activated on that message.
i continue with several problems :(
how can i get the instance of class for a pointer?

static LRESULT CALLBACK WndProcForm(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        static POINT PreviousLocation, Location;
        static bool Tracking = false;
        static MouseButtons MBButtons;
        static bool blControl=false;
        static bool blShift=false;
        static bool blResize=false;
        static int xPos=0;
        static int yPos=0;
        static UINT_PTR timerid;
        static bool blnDrag=false;

        if (WindowMain==NULL)
            WindowMain=hwnd;
        form *inst=(form*)lParam;

        //Working with messages
        switch(msg)
        {
            case WM_CREATE:
            {

                RECT a;
                GetWindowRect(hwnd,&a);
                inst->Create(a.left, a.top);
            }
            break;
//................
cambalinho 142 Practically a Posting Shark

in these sample, i only have 1 form.
see the setParent():

form()
    {
        ++FormCount;
        strCaption=strCaption + to_string(FormCount);
        setParent(HWND_DESKTOP);
    }

void setParent(HWND parent=GetDesktopWindow())
    {

            WNDCLASSEX FormClass;
            char classname[]="form";
            HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);

            FormClass.cbSize        = sizeof(WNDCLASSEX);
            FormClass.style         = 0;
            FormClass.lpfnWndProc   = WndProcForm;
            FormClass.cbClsExtra    = 0;
            FormClass.cbWndExtra    = 0;
            FormClass.hInstance     = mod;
            FormClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
            FormClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
            FormClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
            FormClass.lpszMenuName  = NULL;
            FormClass.lpszClassName = classname;
            FormClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

            // register the new window class"
            RegisterClassEx(&FormClass);
            SetProp(hwnd, formpropname, (HANDLE)FormClass.lpfnWndProc);

            hwnd = CreateWindowEx(0, classname, "The title of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, parent, NULL, mod, (LPVOID) this);

            if (hwnd == NULL)
                MessageBox(NULL, "Can't create the control", "error", MB_OK);
            SetProp(hwnd, formclassprop, (HANDLE)this);
            ShowWindow(hwnd, SW_NORMAL);
            UpdateWindow(hwnd);

            clrBackColor= GetBkColor(GetDC(parent));
            clrTextColor = GetTextColor(GetDC(parent));


        RECT a;
        GetClientRect(hwnd,&a);
        intTop=a.top;
        intLeft=a.left;
        intWidth=a.right-a.left;
        intHeight=a.bottom-a.top;
    }

until here seems fine... now see the window procedure:

static LRESULT CALLBACK WndProcForm(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        static POINT PreviousLocation, Location;
        static bool Tracking = false;
        static MouseButtons MBButtons;
        static bool blControl=false;
        static bool blShift=false;
        static bool blResize=false;
        static int xPos=0;
        static int yPos=0;
        static UINT_PTR timerid;
        static bool blnDrag=false;



        //Working with messages
        switch(msg)
        {
            case WM_CREATE:
            {
                RECT a;
                GetWindowRect(hwnd,&a);
                Create(a.left, a.top);
            }
            break;

the Create is a function lambda that only show us a message box. the WM_CREATE don't show me the message box... but, for test, i use it with WM_KEYUP and it's showed.
so some messages aren't call in these window procedure :(
what i'm doing …

cambalinho 142 Practically a Posting Shark

i'm creating the form class. the form us showed and the window procedure works. the problem is that some messages(like WM_CREATE) aren't working. so how can i connect, correctly the form to window procedure?

cambalinho 142 Practically a Posting Shark

can i declare functions private in header files?
imagine that you use a function declared outside the class and you only want be used only by that class... how can i private that function?

cambalinho 142 Practically a Posting Shark

SalmiSoft: you have right... thanks
heres the class updated:

BOOL CALLBACK EnumChildProc( HWND hwnd, LPARAM lParam );
class ChildControls
{
private:
    vector<HWND> childcontrols;
    HWND windowparent;
    friend BOOL EnumChildProc( HWND hwnd, LPARAM lParam );
public:

    ChildControls()
    {
        //nothing
    }

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

    UINT childcontrolscount()
    {
        return childcontrols.size();
    }

    HWND GetHWND(UINT index,HWND parent)
    {
        windowparent=parent;
        EnumChildWindows( windowparent,EnumChildProc,(LPARAM)this);


        if(index>=childcontrols.size())
            index=childcontrols.size()-1;
        if(index<0)
            index=0;
        return childcontrols[index];
    }
};

BOOL EnumChildProc( HWND hwnd, LPARAM lParam )
{
    ChildControls *cc=(ChildControls *)lParam;
    cc->childcontrols.push_back(hwnd);
    return TRUE;
}

but how can i avoid instances from these class? or continue use the class name without the instance?

cambalinho 142 Practically a Posting Shark

my problem was with HWND parent ;)
let me ask more:
1 - why i can't do these with class(when i close it)?

}ChildControls;

i need avoid instances of that class. how can i do that?

cambalinho 142 Practically a Posting Shark

i have that function ouside of class, but i don't get correct results :(

BOOL CALLBACK EnumChildProc( HWND hwnd, LPARAM lParam );
class ChildControls
{
private:
    vector<HWND> childcontrols;
    UINT childcontrolsindex;
    UINT controlscount=0;
    HWND windowparent;
    friend BOOL EnumChildProc( HWND hwnd, LPARAM lParam );
public:

    ChildControls()
    {
        //nothing
    }

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

    UINT childcontrolscount()
    {
        return controlscount;
    }

    HWND GetHWND(UINT index)
    {
        EnumChildWindows( windowparent,EnumChildProc,(LPARAM)this);


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

BOOL EnumChildProc( HWND hwnd, LPARAM lParam )
{
    static UINT i=0;
    ChildControls *cc=(ChildControls *)lParam;

    cc->childcontrols.push_back(hwnd);
    cc->childcontrolsindex = cc->childcontrols.size(); // TODO:
    cc->controlscount=i;
    i=i+1;
    return TRUE;
}