Passing data to window on create

Posted on 2000-04-24
Last Modified: 2013-12-03

      I have a WIN32 CONSOLE Application.

      I have to create a window and pass some user data so that the WM_CREATE message
      can use it. The data is a pointer to linked-list. Once passed, the window proc must
      be able to use it wherever and whenever.

      There may be many windows created of the same class but with different pointers passed
      (of the same type), so that each window can use the pointer it was given.
      Note that the application is a console app.

      How can I do this ? Code in C plz,

Thanx, Afzal.

Question by:afzalj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 22

Expert Comment

ID: 2743359
The last parameter to CreateWindow() (or CreateWindowEx()) is a 32 bit value that may be used for any purpose you want.  This value is passed with the WM_CREATE message.  You may use this to pass whatever you want.  So you can use it to pass a pointer to your linked list.

LVL 22

Accepted Solution

nietod earned 120 total points
ID: 2743361
opps that was to be an answer.  


Author Comment

ID: 2743365
I thought it was a parameter to CREATESTRUCT ? Does it matter what  I give it ?
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

ID: 2743369
And what about the HINSTANCE ? Is it NULL ? It's a console app so what do i use as HINSTANCE ?
LVL 22

Expert Comment

ID: 2743379
Itrs hard to give you much in the way of code, since we don't know any of the details of your case, but creating the window might look like

struct ListNode *ListHeadPtr;

HWND WndHnd = CreateWindow("CLASSNAME","WindowTitle", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100,150,400,300,NULL,NULL, GetModuleHandle(NULL), ListHeadPtr);

See how it passes the linke list head pointer in the last parameter.

Then to obtain the linked list in the WM_CREATE message, in the window procedure do

   struct ListNode *HeadPtr = (struct ListNode *) CrtPrmPtr->lpCreateParams;

Let me know if you have any questions.
LVL 22

Expert Comment

ID: 2743389
>> I thought it was a parameter to CREATESTRUCT ?
>> Does it matter what  I give it ?
You pass whatever 32 bit value you want to CreateWindow().  When WM_CREATE (also WM_NCCREATE) is sent, the long parameter points to a CREATESTRUCT and in the first member of the CREATESTRUCT (lpCreateParams) the 32 bit value you specificed will be found.

>> And what about the HINSTANCE ? Is it NULL
You can get the current HINSTANCE using "GetModuleHandle(NULL)".  I showed that above.  That is often what I do since it is a liuttle more reliable than storing the module handle in a global variable that could become corrupted.
LVL 22

Expert Comment

ID: 2743397
I've never created a regular window from a console application.  I don't know if you will experience any problems with that.  You may need to write a message loop for the window, but I'm not sure.  The console window itself has some sort of message loop, possibly running in a different thread.   If you write your own message loop, I'm not sure what will happen to the console.  So the answer I gave you was really on how to send parameters to the WM_CREATE message.  That works for any type of application.  The issue of how to create a window in a console application is seperate from that.  I don't know for sure how to do that, or even if it can be done.   However the reverse is easy and I've done that.  That is, you can create a GUI application that creates 1 or more console windows and (possibly) 1 or more GUI windows.  Your application can use AllocConsole() to create console windows.  

Author Comment

ID: 2743399
Thanx !!!

Author Comment

ID: 2743401
Thanx !!!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Messagebox for a Web Site Application 4 86
Is COM supported from Apache 1 77
Licensing Sharepoint 2016 for developers 11 90
Starting to use Git with Visual  Studio Online 1 65
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question