Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Failed at creating ListView in C++.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Apr 10, 2017 12:39 pm    Post subject: Failed at creating ListView in C++. Reply with quote

I copied the following code from Microsoft website to create a ListView. I made some minor changes to fix compiling errors. It can be successfully compiled now, but the problem is that nothing is created, not to mention a ListView.....

PS: I did pass the handle of the main window.

Code:

HWND CreateListView(HWND hwndParent)
{
   INITCOMMONCONTROLSEX icex;           // Structure for control initialization.
   icex.dwICC = ICC_LISTVIEW_CLASSES;
   InitCommonControlsEx(&icex);

   RECT rcClient;                       // The parent window's client area.

   GetClientRect(hwndParent, &rcClient);

   // Create the list-view window in report view with label editing enabled.
   HWND hWndListView = CreateWindow(WC_LISTVIEW,
      "what",
      WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
      0, 0,
      rcClient.right - rcClient.left,
      rcClient.bottom - rcClient.top,
      hwndParent,
      NULL,
      NULL,
      NULL);

   return (hWndListView);
}


And in the WinMain function, I called this:
Code:

HWND myLV = CreateListView(hwnd);  //hwnd is not NULL



But, nothing happens.

So, what did I do wrong? Sad

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Mon Apr 10, 2017 2:26 pm    Post subject: Reply with quote

Try added WS_VISIBLE to the list of flags passed to the creation.

The HMENU should have a valid ID as well and not NULL (0) since you are using WS_CHILD.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Apr 10, 2017 3:29 pm    Post subject: Reply with quote

atom0s wrote:
Try added WS_VISIBLE to the list of flags passed to the creation.

The HMENU should have a valid ID as well and not NULL (0) since you are using WS_CHILD.


Thank you as always, atom0s. I added WS_VISIBLE, and it worked! Very Happy

With regard to "HMENU" parameter, I don't quite understand it. Is it a menu that can be defined in .rc file? I tried adding a menu and set it as the parameter, but nothing changed. Also, a menu in a ListView doesn't make sense to me neither. Can you explain a little bit?

Edit:
Actually I have two questions in the example provided by Microsoft:
Code:

HWND hWndListView = CreateWindow(WC_LISTVIEW,
                                     L"",
                                     WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
                                     0, 0,
                                     rcClient.right - rcClient.left,
                                     rcClient.bottom - rcClient.top,
                                     hwndParent,
                                     (HMENU)IDM_CODE_SAMPLES,
                                     g_hInst,
                                     NULL);


The code above is used to create a ListView, I don't understand the following two parameters:
1. (HMENU)IDM_CODE_SAMPLES. I have mentioned this above.
2. g_hInst. What is this used for? "A handle to the instance of the module to be associated with the window", this explanation from MS doesn't help much. What module is it talking about?

Thanks in advance.

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Wed Apr 12, 2017 1:31 pm    Post subject: Reply with quote

With the menu HMENU param, when you use WS_CHILD that parameter becomes an identifier for the child. Not a menu id (unless specifically used as one for a child menu.)

As stated by MSDN for CreateWindow:

Code:

hMenu [in, optional]
Type: HMENU

A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.


The important part here is:
' or specifies a child-window identifier depending on the window style'
and
'For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.'

Identifiers are simply a number that is used when that child has submesssages being invoked and needs to be determined what child caused the message. For example if you have two button controls on a window, both buttons will have their own ID, such as 1000 and 10001. When you click one of the buttons WM_COMMAND will be raised and the lower word of the wParam will contain the button id to let you determine which button was pressed.

If you decide to not use ids, you will then have to sub-class the button to obtain its messages based on its hWnd instead since you will have no other way to determine which button was pressed.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Thu Apr 13, 2017 11:04 am    Post subject: Reply with quote

atom0s wrote:
With the menu HMENU param, when you use WS_CHILD that parameter becomes an identifier for the child. Not a menu id (unless specifically used as one for a child menu.)

As stated by MSDN for CreateWindow:

Code:

hMenu [in, optional]
Type: HMENU

A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.


The important part here is:
' or specifies a child-window identifier depending on the window style'
and
'For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.'

Identifiers are simply a number that is used when that child has submesssages being invoked and needs to be determined what child caused the message. For example if you have two button controls on a window, both buttons will have their own ID, such as 1000 and 10001. When you click one of the buttons WM_COMMAND will be raised and the lower word of the wParam will contain the button id to let you determine which button was pressed.

If you decide to not use ids, you will then have to sub-class the button to obtain its messages based on its hWnd instead since you will have no other way to determine which button was pressed.


Thanks a lot, atom0s. Very very well explained. It's good to have you around, sincerely. Smile

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites