| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3485 人关注过本帖
标题:windowos 汇编的窗口程序,用 C console 程序翻译过来,不出现窗口,求解 ...
只看楼主 加入收藏
apiqqz
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:25
注 册:2011-9-2
结帖率:75%
收藏
 问题点数:0 回复次数:4 
windowos 汇编的窗口程序,用 C console 程序翻译过来,不出现窗口,求解答
用 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;
}
搜索更多相关主题的帖子: windows include warning 字符串 
2014-09-04 12:30
apiqqz
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:25
注 册:2011-9-2
收藏
得分:0 
非常抱歉,在汇编论坛发C的代码,但是真的很希望得到解答,如有人反感,在此表示歉意
2014-09-04 12:32
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 14:58
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:400
帖 子:11857
专家分:43421
注 册:2006-5-13
收藏
得分:0 
解决问题就好!

活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
2014-09-04 16:27
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
粗心导致

DO IT YOURSELF !
2014-09-04 16:29
快速回复:windowos 汇编的窗口程序,用 C console 程序翻译过来,不出现窗口, ...
数据加载中...
 
   



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

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