Solved

Passing data to window on create

Posted on 2000-04-24
9
216 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
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 is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

939 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now