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;
}
搜