客户区贴图的问题
这一段玩起了汇编,看到有些注册机异型窗口,就想学一下,从网上找了几篇不过是C的,自己就拿汇编重复一下,可是总有问题,本人也是编程菜鸟,windows消息机制,也是一知半解,汇编也是新手,我把别人教程的C代码,和我写的汇编代码,附上,请高手指点一二程序代码:
/ 对话框位图背景 - WM_CTLCOLORDLG中使用StretchBlt贴图 //By MoreWindows-(http://blog.) #include <windows.h> #include "resource.h" const char szDlgTitle[] = "位图背景 使用StretchBlt贴图 MoreWindows-(http://blog.)"; // 对话框消息处理函数 BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc); return 0; } BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { RECT rcDialog; HBITMAP hBitmap; static BITMAP s_bm; static HDC s_hdcMem; switch (message) { case WM_INITDIALOG: // 设置对话框标题 SetWindowText(hDlg, szDlgTitle); // 设置对话框大小可调节 SetWindowLong(hDlg, GWL_STYLE, GetWindowLong(hDlg, GWL_STYLE) | WS_SIZEBOX); // 加载背影图片 hBitmap = (HBITMAP)LoadImage(NULL, "005.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hBitmap == NULL) { MessageBox(hDlg, "LoadImage failed", "Error", MB_ICONERROR); exit(0); } else { // 将背影图片放入HDC - s_hdcMem HDC hdc; hdc = GetDC(hDlg); s_hdcMem = CreateCompatibleDC(hdc); SelectObject(s_hdcMem, hBitmap); ReleaseDC(hDlg, hdc); // 得到位图信息 GetObject(hBitmap, sizeof(s_bm), &s_bm); } return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: DeleteDC(s_hdcMem); EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; case WM_SIZE: InvalidateRect(hDlg, NULL, TRUE); return TRUE; case WM_CTLCOLORDLG: GetClientRect(hDlg, &rcDialog); //通过SetStretchBltMode的设置能使StretchBlt在缩放图像更加清晰 SetStretchBltMode((HDC)wParam, COLORONCOLOR); StretchBlt((HDC)wParam, 0, 0, rcDialog.right, rcDialog.bottom, s_hdcMem, 0, 0, s_bm.bmWidth, s_bm.bmHeight, SRCCOPY); return (BOOL)((HBRUSH)GetStockObject(NULL_BRUSH)); } return FALSE; }接下来是我用汇编的代码,总是图片出不来
程序代码:
.386 .model flat, stdcall ;32 bit memory model option casemap :none ;case sensitive include test.inc .code start: invoke GetModuleHandle,NULL mov hInstance,eax invoke InitCommonControls invoke DialogBoxParam,hInstance,IDD_MAIN,NULL,addr DlgProc,NULL invoke ExitProcess,0 ;######################################################################## DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM LOCAL hdc:HDC LOCAL hdcSrc:HDC LOCAL PicH:DWORD LOCAL PicW:DWORD LOCAL rect:RECT LOCAL hRgn:HRGN LOCAL hbitmap:HBITMAP LOCAL sbmp:BITMAP LOCAL hpaint:PAINTSTRUCT mov eax,uMsg .if eax==WM_INITDIALOG invoke GetWindowLong,hWin, GWL_STYLE or eax,WS_SIZEBOX invoke SetWindowLong,hWin,GWL_STYLE,eax invoke LoadBitmap,hInstance,logo mov hbitmap,eax invoke GetDC,hWin mov hdc,eax invoke CreateCompatibleDC,hdc mov hdcSrc,eax invoke SelectObject,hdcSrc,hbitmap invoke GetObject,hbitmap,sizeof sbmp,addr sbmp invoke ReleaseDC,hWin,hdc ;initialization here .elseif eax==WM_CTLCOLORDLG invoke GetClientRect,hWin,addr rect invoke SetStretchBltMode,wParam,COLORONCOLOR invoke StretchBlt,wParam,0,0,rect.right,rect.bottom,hdcSrc,0,0,sbmp.bmWidth,sbmp.bmHeight,SRCCOPY invoke GetStockObject,NULL_BRUSH ; ret .elseif eax==WM_SIZE invoke InvalidateRect,hWin,NULL,TRUE ; mov eax,TRUE ; ret .elseif eax==WM_COMMAND mov edx,wParam movzx eax,dx shr edx,16 .if edx==BN_CLICKED .if eax==IDOK .elseif eax==IDCANCEL invoke SendMessage,hWin,WM_CLOSE,NULL,NULL .endif .endif .elseif eax==WM_CLOSE invoke EndDialog,hWin,0 .else mov eax,FALSE ret .endif mov eax,TRUE ret DlgProc endp end start我把教程中的LoadImage换成了LoadBitmap为了使加载资源中的为图方便经调试WM_CTLCOLORDLG消息总是不会触发,但是用C语言的就正常,难道是偶滴RPWT,……