使用WNDCLASS结构/窗口的Extra Parameter. [英] Using Extra Parameter of WNDCLASS structure / window.

查看:142
本文介绍了使用WNDCLASS结构/窗口的Extra Parameter.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此功能的使用:我目前正在开发custom window control(a child window).它只是一个基本的典型按钮.

我做了什么:我只对所有相同类型的新窗口控件使用一个Window Procedure.我想为每个控件(相同类型的控件)存储一些信息.所有这些信息都存储在名为"BUTTONINFO"的type of a structure中.

Use of this : I am currently developing a custom window control (a child window). It''s just a basic typical button.

What I have done : I''m only using a one Window Procedure for all the same type of new window controls. I want to store some information for each of these controls (same type ones).All these information are in a type of a structure called "BUTTONINFO".

typedef struct tagBUTTONINFO{
    int xPos;
    int yPos;
    TCHAR * szText;
    int Lenght;
    int Width;
    int otherInfo;
}BUTTONINFO;



我在子窗口控件的Window Class中为此分配了一些内存,如下所示:



I have allocated some memory for this in the Window Class of my child window control as follows :

WNDCLASS wndclass;
wndclass.cbWndExtra    = sizeof(BUTTONINFO) ;



问题:要为上述额外字段分配值,我必须使用SetWindowLong 函数(据我所知).这是功能:



The Problem : For Assigning a Value for the above extra field I have to use SetWindowLong function (As I know). Here is the Function :

BUTTONINFO buttonInfo;
SetWindowLong(hwnd,0,buttonInfo);



SetWindowLong 的第三个参数是LONG的类型.那么如何分配或检索此信息?

请帮忙!



The 3rd Parameter to SetWindowLong is a type of a LONG. So how Do I Assign or Retrieve this Information ?

Please Help !

推荐答案

假设,您的结构(一个类会更好)
具有其构造函数(用于分配和设置szText指针)和析构函数(用于释放szText指针):):
Assumed, your structure (a class would be better)
has its constructor(to allocate and set the szText pointer) and destructor(to free the szText pointer) :) :
{
  // setting phase
  SetWindowLong(hwnd, 0, (LONG) new CYorButtonInfo(/*list of construtor's parameters*/);
}
{
  // destroying phase
  CYourButtonInfo* pcInfo = (CYourButtonInfo*) GetWindoLong(hwnd, 0);
  delete pcInfo;
}


这是我一直在寻找的答案:.

阅读以下链接中的文章;
http://www.catch22.net/tuts/custom-controls [
Here''s the answer that i''ve been looking for :.

Read the article in the following link;
http://www.catch22.net/tuts/custom-controls[^]


这篇关于使用WNDCLASS结构/窗口的Extra Parameter.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆