-
July 28th, 2015, 12:35 PM
#1
[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?
-
July 28th, 2015, 12:40 PM
#2
Re: how use GetProp() and SetProp()?
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.
Victor Nijegorodov
-
July 28th, 2015, 12:57 PM
#3
Re: how use GetProp() and SetProp()?
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?
-
July 28th, 2015, 01:25 PM
#4
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
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 28th, 2015, 01:34 PM
#5
Re: how use GetProp() and SetProp()?
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)
-
July 28th, 2015, 03:32 PM
#6
Re: how use GetProp() and SetProp()?
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.
-
July 28th, 2015, 03:38 PM
#7
Re: how use GetProp() and SetProp()?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|