| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 575 人关注过本帖
标题:给c初学者:对Win32常用参数模拟
只看楼主 加入收藏
stnlcd
Rank: 1
等 级:新手上路
帖 子:177
专家分:1
注 册:2004-11-21
收藏
 问题点数:0 回复次数:0 
给c初学者:对Win32常用参数模拟

我们知道在Win32程序中,大量使用如:WPARAM,LPARAM以及以H开头的各类句柄参数(HBRUSH,HPEN,HWND等)
这几个参数有时候可以作为int型使用,有时候可以用来传递大型的struct结构等,为什么这样多功能。下面用c语言对这几个参数进行简单的模拟,希望对c语言初学者有帮助。

/*Program By stn_lcd! Please run it in TC2.0*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

#define WPARAM long
#define LPARAM long
#define HWND long
#define DWORD int
#define OVERLAPPEDWINDOW 0x0c
#define WS_VISIBLE 0x02
#define WS_CAPTION 0x04
#define WS_BORDER 0x08
#define WS_MAXIMIZE 0x10

#define _MAKE(_pP) (WPARAM)(&_pP)
#define MAX_LENGTH 100

typedef struct demo{
int x;
int y;
}demo;
typedef struct demo2{
char a;
int x;
int xx;
}demo2;
typedef struct WNDCLASS {
int x;
int y;
int width;
int height;
DWORD dwtype;
char* title;
}WNDCLASS;

HWND CreateWindow(int x,int y,int width,int height,DWORD dwtype,char* title) {
WNDCLASS* wndclass;
wndclass=(WNDCLASS*)malloc(sizeof(WNDCLASS));
wndclass->x=x;
wndclass->y=y;
wndclass->width=width;
wndclass->height=height;
wndclass->dwtype=dwtype;
wndclass->title=(char*)malloc(MAX_LENGTH);
strcpy(wndclass->title,title);
return (HWND)wndclass;
}

void ShowWindow(HWND hWnd) {
WNDCLASS* win=(WNDCLASS*)hWnd;
printf("\nx:%d,y:%d,width:%d,height:%d,dwtype:0x%x,title:%s\n",
win->x,win->y,win->width,win->height,win->dwtype,win->title);

}

void DestroyWindow(HWND hWnd) {
WNDCLASS* win=(WNDCLASS*)hWnd;
free(win->title);
free(win);
}


void Disp(WPARAM wParam,LPARAM lParam) {
demo* dp1=(demo*)wParam;
demo2* dp2=(demo2*)wParam;
switch(lParam) {
case 0:
printf("\nx is:%d,y is:%d\n",dp1->x,dp1->y);
break;
case 1:
printf("\na is:%c,x is:%d,xx is:%d\n",dp2->a,dp2->x,dp2->xx);
break;

}
}

main() {
demo n;
demo2 n2;
demo* nx;
HWND hwnd;

clrscr();
n.x=13;
n.y=15;

n2.a='s';
n2.x=124;
n2.xx=127;


Disp(_MAKE(n),(LPARAM)0);
Disp(_MAKE(n2),(LPARAM)1);
nx=(demo*)malloc(sizeof(demo));
nx->x=24;
nx->y=222;
Disp((WPARAM)nx,(LPARAM)0);

hwnd=CreateWindow(10,20,100,300,WS_CAPTION|WS_BORDER|WS_VISIBLE,
"Hello Stn_Lcd!");
ShowWindow(hwnd);
DestroyWindow(hwnd);
getch();

}

搜索更多相关主题的帖子: 参数 模拟 
2005-11-10 12:39
快速回复:给c初学者:对Win32常用参数模拟
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027037 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved