[RESOLVED] how use GetProp() and SetProp()?
i'm trying use the GetProp() and SetProp() by my own, but i don't get results :(
see these function:
Code:
void setParent(HWND parent=GetDesktopWindow())
{
if (hwnd==NULL)
{
WNDCLASSEX FormClass;
char classname[20]="Form";
sprintf(classname,"%s",strCaption.c_str());
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
FormClass.cbSize = sizeof(WNDCLASSEX);
FormClass.style = CS_DBLCLKS;
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)GetSysColor(COLOR_BACKGROUND);
FormClass.lpszMenuName = NULL;
FormClass.lpszClassName = classname;
FormClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// register the new window class
RegisterClassEx(&FormClass);
hwnd = CreateWindowEx(WS_EX_LAYERED,classname, strCaption.c_str(),WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN ,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
SetProp(parent, "parent", (HANDLE)parent);//creates? and sets property
}
else
{
SetProp(parent, "parent", (HANDLE)parent);//sets the property
SetParent(hwnd,parent);
}
ShowWindow(hwnd, SW_NORMAL);
InvalidateRect(hwnd,NULL,TRUE);//i add these line for fix that
UpdateWindow(hwnd);
clrBackColor =GetDCBrushColor(GetDC(hwnd));
clrTextColor = GetTextColor(GetDC(hwnd));
if(GetLastError()!=0)
MessageBox(NULL,to_string(GetLastError()).c_str(),"error", MB_OK);
}
and heres i use it:
Code:
form InputBox("hello",a);
the HWND of form a must go to "parent" property.
and heres how i get the value:
Code:
CenterInsideParent(InputBox,(HWND)GetProp(InputBox, "parent"));
i didn't test the return value, but i have sure that isn't the HWND of a.
what i'm doing wrong?
Re: how use GetProp() and SetProp()?
Quote:
Originally Posted by
Cambalinho
i didn't test the return value, but i have sure that isn't the HWND of a.
what i'm doing wrong?
Please, next time ask your questions after you have tested the return values of all API functions you use.
Re: how use GetProp() and SetProp()?
Quote:
Originally Posted by
VictorN
Please, next time ask your questions after you have tested the return values of all API functions you use.
but i did these test:
Code:
CenterInsideParent(InputBox,a);
and works fine.
i test these and the message box is showed:
Code:
if(SetProp(parent, "parent", (HANDLE)parent)==TRUE)
MessageBox(NULL,"done","done", MB_OK);
i tested these and the messagebox give me 0:
Code:
if(GetProp(InputBox, "parent")==NULL)
MessageBox(NULL,to_string(GetLastError()).c_str(),"done", MB_OK);
so what isn't wright?
Re: how use GetProp() and SetProp()?
Code:
SetProp(parent, "parent", (HANDLE)parent);//creates? and sets property
This doesn't seem to make sense. You are setting the value of property "parent" of a window to itself???????
Don't you mean
Code:
SetProp(hwnd, "parent", (HANDLE)parent);//creates? and sets property
Re: how use GetProp() and SetProp()?
Quote:
Originally Posted by
2kaud
Code:
SetProp(parent, "parent", (HANDLE)parent);//creates? and sets property
This doesn't seem to make sense. You are setting the value of property "parent" of a window to itself???????
Don't you mean
Code:
SetProp(hwnd, "parent", (HANDLE)parent);//creates? and sets property
thanks for all
sorry the question, but let me ask: how can i avoid these type of errors?(i don't mean only in programming... but in life too)
Re: how use GetProp() and SetProp()?
Quote:
Originally Posted by
Cambalinho
thanks for all
sorry the question, but let me ask: how can i avoid these type of errors?
You can avoid these types of errors by doing what Victor suggested and check the return codes for the api's you call.
And by checking the return codes, I mean really check the return codes.
Consider your code snippet.
Code:
hwnd = CreateWindowEx(WS_EX_LAYERED,classname, strCaption.c_str(),WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN ,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
SetProp(parent, "parent", (HANDLE)parent);//creates? and sets property
In the snippet above, if CreateWindowEx fails, you still call SetLayeredWindowAttibutes(), then display an error and continue calling SetProp().
Calling multiple functions after hitting an error isn't what I would consider a good error handling strategy.
Re: how use GetProp() and SetProp()?
Quote:
Originally Posted by
Arjay
You can avoid these types of errors by doing what Victor suggested and check the return codes for the api's you call.
And by checking the return codes, I mean really check the return codes.
Consider your code snippet.
Code:
hwnd = CreateWindowEx(WS_EX_LAYERED,classname, strCaption.c_str(),WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN ,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
SetProp(parent, "parent", (HANDLE)parent);//creates? and sets property
In the snippet above, if CreateWindowEx fails, you still call SetLayeredWindowAttibutes(), then display an error and continue calling SetProp().
Calling multiple functions after hitting an error isn't what I would consider a good error handling strategy.
sorry, but question was about miss between parent and hwnd. like you have seen, i error because i use the parent instead the hwnd, by mistake.
thanks for all