Solved

Passing data to window on create

Posted on 2000-04-24
9
215 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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