Hi Pelles Forum
Can anyone answer two queries regarding WS_POPUP windows please.
Question 1. How do I obtain rect values for my WS_POPUP window (named hwnd_2)? GetDlgItem for hwnd_2 will not work due to hWndParent not
being set in CreateWindowEx.
Question 2. How do I send messages from my WS_POPUP window back to the main procedure. To demonstrate this as cleanly as possible, I have inserted a WM_APP message in Case WM_SIZE of the hwnd_2 procedure.
I have attached code that is as minimal as I can make it to demonstrate what I am attempting.
My goal is to popup a resizable window that contains an EDIT control. I intend that the EDIT control will automatically resize to fill the popup window as the popup window is manually resized.
I may be attempting something that is not possible with WS_POPUP windows.
Thank you for any help that you can offer.
Allan
Hi Alan,
I'm not following exactly what you are wanting to do but here are some suggestions.
For Q1: window size you can calculate from the left,right,top,bottom positions
RECT mwin;
GetWindowRect(gHWND,&mwin);
for Q2: there are several methods, perhaps the easiest might be
LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
as in SendMessage(ghToolBar, TB_SETSTATE, ID_MF_SAVEAS,LOWORD(TBSTATE_ENABLED));
BTW if you use the Project-Zip feature in PellesC you'll be able to post something that can be tried w/o helpers needing to guess the compile/link setting you are using. Makes it easier for others to just unzip and test.
John Z
I would answer like JohnZ, but would make some suggestions:
Rather than using GetDlgItem, use FindWindow
Move the two GetDlgItem at an other place, into a WM_xxx message, not at the beginning of the procedure.
Why don't you paint directly on the parent window when hwnd_2 processes WM_SIZE?
Why don't you modify the message loop to trap WM_SIZE on the windows?
Hi Alan,
In addition, a possible error in your declarations section:
Quote
//For variable displays using sprintf
char var_contents_1; // Variable to hold char, integer or float contents as CHAR
char* pvar_contents_1 = &var_contents_1;
This seems to be a mistake. A single char variable will only hold one integer, yet later there is
Quotesprintf(pvar_contents_1, "%s, %s= %d, %s= %d, %s= %d, %s= %d, %s= %d, %s= %d, %s= %d, %s= %d,",
"hwnd_3 ",
"wrect_2.left ", wrect_2.left,
"wrect_2.right ", wrect_2.right,
"wrect_2.top ", wrect_2.top,
"wrect_2.bottom ", wrect_2.bottom,
"crect_2.left ", crect_2.left,
"crect_2.right ", crect_2.right,
"crect_2.top ", crect_2.top,
"crect_2.bottom ", crect_2.bottom);
SetWindowTextA(hwnd_3,pvar_contents_1);
Seems the single char variable is being stuffed with a whole lota stuff.....
The type char is a single 'integer value' as such the above would not be correct, although it
may appear to work ..... for a while.
IMO
char var-contents_1[300]; // might be better or malloc some string space.
John Z
snprintf is more secure.
int snprintf( char *buffer, size_t count, const char *format [, argument] ... );
snprintf (https://www.geeksforgeeks.org/snprintf-c-library/)
:)
You don't like:
int snprintf_s(char * restrict dst, rsize_t max, const char * restrict format, ...);
the 'safest'? :) :)
Just kidding,
John Z
In fact I always use sqlite3_snprintf. :P
Hi All
Thank you for your suggestions.
I was already aware that the HWND structure for the WS_POPUP window could not be retrieved from within the WS_POPUP window's procedure. This is because
hWndParent cannot be set in CreateWindowEx for a WS_POPUP window.
I have now discovered that no HWND structures can be retrieved from within the WS_POPUP window procedure. For this reason conventional C code that relies on having hwnd will not work. The limitations are probably too great to continue with this.
I have been experimenting with transferring HWND structures to the WS_POPUP window procedure using global variables. The results are only partially successful.
I am very much a beginner at C with much to learn. I will drop this investigation and focus on code that the manual says is supposed to work.
Thank you again for the suggestions.
Allan
Use
SetWindowLongPtr(hMainWindow,GWLP_USERDATA,(long long int) _lpImageInfos) ;
and
_lpImageInfos = (LPIMAGEINFOS) GetWindowLongPtr(hMainWindow,GWLP_USERDATA) ;
Retrieve the source code of my program, you will get informations
https://forum.pellesc.de/index.php?topic=10037.0 (https://forum.pellesc.de/index.php?topic=10037.0)
Hi Allen,
Well don't take this the wrong way but you give up too easily, and need to take the suggestions.
I'll post your basically same code but working, in a few moments (done, attached), after I clean it up, but here is a screen shot.
To learn windows I've found you need to be persistent, never give up.
John Z
P.S. Made minimum changes to get it working. This is but one method - there are others.
What is "the wrong way" I don't understand?
Means don't misunderstand....don't think I'm just being mean..... :)
John Z
See this article of Raymond Chen, that can be useful.
https://devblogs.microsoft.com/oldnewthing/20210104-00/?p=104656
Hi John
Thank you for your help. It has given me some good things to work with.
Thank you also Kenavo for the reference.
Cheers
Allan
Hi Alan,
You are very welcome.
BTW "Kenavo" actually means Goodbye ;) but I'm sure Grincheux appreciates the nod.
John Z
Who never make a mistake?
Only someone who never does anything.....
John Z