| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 620 人关注过本帖
标题:用 console 程序翻译汇编的 "窗口”程序,调试看到 CreateWindowEX 返回的 ...
只看楼主 加入收藏
apiqqz
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:25
注 册:2011-9-2
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
用 console 程序翻译汇编的 "窗口”程序,调试看到 CreateWindowEX 返回的句柄为 0,程序运行更没有显示窗口
用console 程序翻译汇编的  "窗口”程序,因windows的指针实际是一个双字,因此用int类型代替,并#pragma ……指令消除这些 类型不 匹配 的警告
本屌新手,求解答,求罩

#include <windows.h>
#pragma warning (disable:4047 4027 4133 4024 )

int _procwinmain(int,int,int,int);
void mini();
//未初始化数据
int hinstance;
int hWinMain;
int *p1;
int *p2;
char *p;
//字符串
 char classname[] ="my class";
 char captionmain[] ="window powered by console program";
 char text[]="standard window of windows powered by console";

 //定义结构
 struct WNDCLASSEX{
     int cbsize;
     int style;
     int lpfnwndproc;
     int cbclsextra;
     int hinstance;
     int hicon;
     int hcursor;
     int hbrbackground;
     int lpszmenuname;
     int lpszclassname;
     int hiconsm;
        };

 struct POINT {
     double x;
     double y;
        };

 struct MSG{
     int hwnd;
     int message;
     int wparam;
     int lparam;
     int time;
     POINT pt;
            };

 struct RECT{
    LONG left;
    LONG top;
    LONG right;
    LONG bottom;
    };
 
 struct PAINTSTRUCT{
  int hdc ;         
  int fErase;        
  RECT  rcPaint;      
  int fRestore  ;   
  int fIncUpdate ;
  double RGB1;
  double RGB2;
        };

 int main( )
{mini();
 ExitProcess(NULL);
}



void mini()
{
//在栈中定义局部变量,获取模块句柄,初始化局部变量
 struct WNDCLASSEX stwindclass;
 struct MSG stmsg;
p=classname;
p1=(int*)p;
p=captionmain;
p2=(int*)p;

 hinstance= GetModuleHandle(NULL);
 RtlZeroMemory(&stwindclass,sizeof(WNDCLASSEX));
 //注册窗口类
 stwindclass.hcursor= LoadCursor(0,IDC_ARROW);
 stwindclass.hinstance=hinstance;
 stwindclass.cbsize=sizeof(WNDCLASSEX);
 stwindclass.style=(CS_HREDRAW|CS_VREDRAW);
 stwindclass.lpfnwndproc= &_procwinmain;
 stwindclass.hbrbackground= COLOR_WINDOW+1;
 stwindclass.lpszclassname= classname;
  RegisterClassEx(&stwindclass);
 //建立并显示窗口
 hWinMain= CreateWindowEx(WS_EX_CLIENTEDGE,p2,p1,WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hinstance,NULL);//调试发现函数返回的句柄为0
  ShowWindow(hWinMain,SW_SHOWNORMAL);
  UpdateWindow(hWinMain);
 //消息循环
 while(TRUE)
 {if (GetMessage(&stmsg,NULL,0,0)==0)
   break;
  else
       TranslateMessage(&stmsg);
       DispatchMessage(&stmsg);
 }

}



int  _procwinmain(int hwnd ,int umsg,int wparam, int lparam)
{  
   struct PAINTSTRUCT stps;
   struct RECT strect;
   int hDC;
   if (umsg== WM_PAINT)
        {hDC= BeginPaint(&stps,hwnd);
          DrawText(hDC,&text,-1,&strect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
         EndPaint(hwnd,&stps);
        }
    else
        if(umsg== WM_CLOSE)
        { DestroyWindow(hWinMain);
          PostQuitMessage(NULL);
        }
        else
             DefWindowProc(hwnd,umsg,wparam,lparam);
        return 0;
}
搜索更多相关主题的帖子: standard windows include warning 字符串 
2014-09-04 12:09
apiqqz
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:25
注 册:2011-9-2
收藏
得分:0 
调试出来了,多谢大家的关注,定义WNDCLASSEX时少写了一个数据项,导致错误,另外windows 的窗口过程处理的消息返回值不都是0。

#include <windows.h>
#pragma warning (disable:4047 4027 4133 4024 )
#include <stdio.h>

int _procwinmain(int,int,int,int);
void mini();
//未初始化数据
int hinstance;
int hWinMain;
int *p1;
int *p2;
char *p;
int m;
int(*pro)()=_procwinmain;
//字符串
char classname[] ="my class";
char captionmain[] ="window powered by console program";
char text[]="standard window of windows powered by console";
char* sz=classname;
//定义结构
struct WNDCLASSEX{
     int cbsize;
     int style;
     int lpfnwndproc;
     int cbclsextra;
     int cbwndextra;
     int hinstance;
     int hicon;
     int hcursor;
     int hbrbackground;
     int lpszmenuname;
     int lpszclassname;
     int hiconsm;
        };

struct POINT {
     double x;
     double y;
        };

struct MSG{
     int hwnd;
     int message;
     int wparam;
     int lparam;
     int time;
     POINT pt;
            };

struct RECT{
    LONG left;
    LONG top;
    LONG right;
    LONG bottom;
    };

struct PAINTSTRUCT{
  int hdc ;         
  int fErase;        
  RECT  rcPaint;      
  int fRestore  ;   
  int fIncUpdate ;
  double RGB1;
  double RGB2;
        };

int main( )
{mini();
ExitProcess(NULL);
}



void mini()
{
//在栈中定义局部变量,获取模块句柄,初始化局部变量
struct WNDCLASSEX stwindclass;
struct MSG stmsg;
p=classname;
p1=(int*)p;
p=captionmain;
p2=(int*)p;
hinstance= GetModuleHandle(NULL);
RtlZeroMemory(&stwindclass,sizeof(WNDCLASSEX));

//注册窗口类
stwindclass.hcursor= LoadCursor(0,IDC_ARROW);
stwindclass.hinstance=hinstance;
stwindclass.cbsize=sizeof(WNDCLASSEX);
stwindclass.style=(CS_HREDRAW|CS_VREDRAW);
stwindclass.lpfnwndproc= pro;
stwindclass.hbrbackground= COLOR_WINDOW+1;
stwindclass.lpszclassname= sz;
  RegisterClassEx(&stwindclass);
  m=GetLastError();




//建立并显示窗口
m=hWinMain= CreateWindowEx(WS_EX_CLIENTEDGE,p1,p2,WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hinstance,NULL);
  ShowWindow(hWinMain,SW_SHOWNORMAL);
  UpdateWindow(hWinMain);

//消息循环
while(TRUE)
{if (GetMessage(&stmsg,NULL,0,0)==0)
   break;
  else
  { TranslateMessage(&stmsg);
       DispatchMessage(&stmsg);
  }
}

}



int  _procwinmain(int hwnd ,int umsg,int wparam, int lparam)
{  
   struct PAINTSTRUCT stps;
   struct RECT strect;
   int hDC;
   if (umsg== WM_PAINT)
        {hDC= BeginPaint(&stps,hwnd);
        GetClientRect(hwnd,&strect);
          DrawText(hDC,&text,-1,&strect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
         EndPaint(hwnd,&stps);
        }
    else
        if(umsg== WM_CLOSE)
        { DestroyWindow(hWinMain);
          PostQuitMessage(NULL);
        }
        else
        {     DefWindowProc(hwnd,umsg,wparam,lparam);
            _asm mov m,eax
                printf("%d\n",m);//测试消息的数量,及返回值时多少
            return;
        }
        return 0;
}
2014-09-04 15:00
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:20 
windows 的api 错误一般都可以查看GetLastError()的,多多查查msdn

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2014-09-04 22:46
快速回复:用 console 程序翻译汇编的 "窗口”程序,调试看到 CreateWindowEX 返 ...
数据加载中...
 
   



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

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