Solved

Passing data to window on create

Posted on 2000-04-24
9
218 Views
Last Modified: 2013-12-03
Experts,

      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.

0
Comment
Question by:afzalj
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:nietod
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.

continues
0
 
LVL 22

Accepted Solution

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

continues
0
 

Author Comment

by:afzalj
ID: 2743365
I thought it was a parameter to CREATESTRUCT ? Does it matter what  I give it ?
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

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

Expert Comment

by:nietod
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

case WM_CREATE:
{
   CREATESTRUCT *CrtPrmPtr = (CREATESTRUCT *) lParam;
   struct ListNode *HeadPtr = (struct ListNode *) CrtPrmPtr->lpCreateParams;
}

Let me know if you have any questions.
0
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 22

Expert Comment

by:nietod
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.  
0
 

Author Comment

by:afzalj
ID: 2743399
Thanx !!!
0
 

Author Comment

by:afzalj
ID: 2743401
Thanx !!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
Event ID 10010 3 69
How To Display a Conditional Image in a Microsoft Access Report 23 100
Need more details 5 168
Need a complete list of ASP.NET page load events 3 59
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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