NO

Author Topic: WS_POPUP windows - RECT values and messaging  (Read 911 times)

Offline aj666

  • Member
  • *
  • Posts: 6
WS_POPUP windows - RECT values and messaging
« on: April 17, 2021, 06:17:52 am »
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

Offline John Z

  • Member
  • *
  • Posts: 358
Re: WS_POPUP windows - RECT values and messaging
« Reply #1 on: April 17, 2021, 11:23:41 am »
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

Offline Grincheux

  • Member
  • *
  • Posts: 329
  • Never be pleased, always improve
    • Arachne
Re: WS_POPUP windows - RECT values and messaging
« Reply #2 on: April 17, 2021, 05:19:17 pm »
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?
« Last Edit: April 17, 2021, 05:36:19 pm by Grincheux »
-------------------------
Kenavo / Bye

Offline John Z

  • Member
  • *
  • Posts: 358
Re: WS_POPUP windows - RECT values and messaging
« Reply #3 on: April 18, 2021, 11:24:11 am »
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
Quote
sprintf(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

Offline Grincheux

  • Member
  • *
  • Posts: 329
  • Never be pleased, always improve
    • Arachne
Re: WS_POPUP windows - RECT values and messaging
« Reply #4 on: April 18, 2021, 11:32:01 am »
snprintf is more secure.

Code: [Select]
int snprintf(   char *buffer, size_t count, const char *format [, argument] ... );
snprintf
« Last Edit: April 18, 2021, 11:41:18 am by Grincheux »
-------------------------
Kenavo / Bye

Offline John Z

  • Member
  • *
  • Posts: 358
Re: WS_POPUP windows - RECT values and messaging
« Reply #5 on: April 18, 2021, 02:30:08 pm »
 :)

You don't like:
 int snprintf_s(char * restrict dst, rsize_t max, const char * restrict format, ...);

the 'safest'?   :) :)

Just kidding,

John Z

Offline Grincheux

  • Member
  • *
  • Posts: 329
  • Never be pleased, always improve
    • Arachne
Re: WS_POPUP windows - RECT values and messaging
« Reply #6 on: April 18, 2021, 02:32:16 pm »
In fact I always use sqlite3_snprintf. :P
-------------------------
Kenavo / Bye

Offline aj666

  • Member
  • *
  • Posts: 6
Re: WS_POPUP windows - RECT values and messaging
« Reply #7 on: April 20, 2021, 04:24:02 am »
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

Offline Grincheux

  • Member
  • *
  • Posts: 329
  • Never be pleased, always improve
    • Arachne
Re: WS_POPUP windows - RECT values and messaging
« Reply #8 on: April 20, 2021, 06:48:47 am »
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

« Last Edit: April 20, 2021, 06:52:23 am by Grincheux »
-------------------------
Kenavo / Bye

Offline John Z

  • Member
  • *
  • Posts: 358
Re: WS_POPUP windows - RECT values and messaging
« Reply #9 on: April 20, 2021, 12:33:58 pm »
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.
« Last Edit: April 20, 2021, 12:47:58 pm by John Z »

Offline Grincheux

  • Member
  • *
  • Posts: 329
  • Never be pleased, always improve
    • Arachne
Re: WS_POPUP windows - RECT values and messaging
« Reply #10 on: April 20, 2021, 12:37:10 pm »
What is "the wrong way" I don't understand?
-------------------------
Kenavo / Bye

Offline John Z

  • Member
  • *
  • Posts: 358
Re: WS_POPUP windows - RECT values and messaging
« Reply #11 on: April 20, 2021, 12:49:45 pm »
Means don't misunderstand....don't think I'm just being mean..... :)


John Z

Offline Grincheux

  • Member
  • *
  • Posts: 329
  • Never be pleased, always improve
    • Arachne
Re: WS_POPUP windows - RECT values and messaging
« Reply #12 on: April 20, 2021, 08:30:02 pm »
See this article of Raymond Chen, that can be useful.
https://devblogs.microsoft.com/oldnewthing/20210104-00/?p=104656

-------------------------
Kenavo / Bye

Offline aj666

  • Member
  • *
  • Posts: 6
Re: WS_POPUP windows - RECT values and messaging
« Reply #13 on: April 27, 2021, 12:59:41 am »
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

Offline John Z

  • Member
  • *
  • Posts: 358
Re: WS_POPUP windows - RECT values and messaging
« Reply #14 on: April 27, 2021, 05:35:18 pm »
Hi Alan,

You are very welcome.

BTW "Kenavo" actually means Goodbye  ;) but I'm sure Grincheux appreciates the nod.

John Z