;Why My prog crashes.? Thanks. ;============================== .386 .model flat,stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\comctl32.inc includelib \masm32\lib\comctl32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib WinMain proto :DWORD,:DWORD,:DWORD,:DWORD HeaderGr PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD .data ClassName db "SimpleWinClass",0 AppName db "Programming Header Control",0 HeaderClassName db "SysHeader32",0 TheName db "Name",0 .data? hInstance HINSTANCE ? CommandLine LPSTR ? Hheader HWND ? .Const headerID equ 501 .code start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine mov CommandLine,eax invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax invoke InitCommonControls WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hwnd:HWND mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_WINDOW+1 mov wc.lpszMenuName,NULL mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\ hInst,NULL mov hwnd,eax invoke ShowWindow, hwnd,SW_SHOWNORMAL invoke UpdateWindow, hwnd .WHILE TRUE invoke GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL hdc:HDC .IF uMsg==WM_DESTROY invoke PostQuitMessage,NULL .ELSEIF uMsg==WM_CREATE invoke HeaderGr,NULL,hWnd,0,0,0,0,headerID .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp ; ######################################################################## ; ######################################################################## HeaderGr proc lpText:DWORD,hParent:DWORD,a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD LOCAL HDStruct:HD_LAYOUT LOCAL HDItem:HD_ITEM LOCAL WinPos:WINDOWPOS invoke CreateWindowEx,0, ADDR HeaderClassName,NULL, WS_CHILD or WS_BORDER or HDS_BUTTONS or HDS_HORZ , a,b,wd,ht,hParent,ID, hInstance,NULL mov Hheader,eax invoke SetRect,ADDR HDStruct.prc,100,100,200,150 invoke SendMessage,Hheader,HDM_LAYOUT, 0 ,ADDR HDStruct mov HDItem.imask,HDI_FORMAT or HDI_TEXT or HDI_WIDTH mov HDItem.lxy,60 mov HDItem.pszText,offset TheName mov HDItem.cchTextMax,sizeof TheName mov HDItem.fmt,HDF_CENTER or HDF_STRING invoke SendMessage,Hheader,HDM_INSERTITEM,0,ADDR HDItem ret HeaderGr endp ; ######################################################################## end start
Posted on 2001-05-01 22:44:00 by a nada
Don't know if this is the reason. But you're not calling InitCommonControls because of where the invoke is located. Your code:

    invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess,eax
    invoke InitCommonControls

    WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShowWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
Put it inside WinMain:

    WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShowWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    invoke InitCommonControls
Posted on 2001-05-01 23:27:00 by tank