invoke SendDlgItemMessage,hWin,ID_CB,CB_GETCURSEL,0,0

is there possibility this not working correctly under win2k ??
Coz a friend of mine that made test of my prog on win2k got an error.
Posted on 2004-01-21 13:01:41 by AceEmbler
For me both SendMessage and SendDlgItemMessage works on my Win2k.

Regards
Posted on 2004-01-21 15:12:31 by minor28
thx i will not give him nothing to test anymore :tongue:
Posted on 2004-01-21 15:29:53 by AceEmbler
Is there an issue of stack corruption (or stack alignment) or that you never preserve the registers? What exactly is the error?
Posted on 2004-01-21 22:01:14 by roticv
.386
.model flat,stdcall
option casemap:none

include Combo.inc

.code

start:

invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG

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,DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,OFFSET MenuName
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 CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL
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 hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,uMsg
.if eax==WM_INITDIALOG
push hWin
pop hWnd
.elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDM_FILE_EXIT
invoke SendMessage,hWin,WM_CLOSE,0,0
.elseif eax==IDM_HELP_ABOUT
invoke ShellAbout,hWin,addr AppName,addr AboutMsg,NULL
.endif
.elseif eax==WM_CHAR
invoke SendDlgItemMessage,hWin,IDC_CBO1,CB_GETCURSEL,0,0
invoke HandleError
.elseif eax==WM_CLOSE
invoke DestroyWindow,hWin
.elseif uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret

WndProc endp
HandleError proc
LOCAL lpMsgBuffer:LPVOID
pushad
mov cx,SUBLANG_DEFAULT
shl ecx,10
push 0
push 0
lea eax,lpMsgBuffer
push eax
push ecx
invoke GetLastError
push eax
push 0
push FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM
call FormatMessage
invoke MessageBox,0,lpMsgBuffer,0,MB_OK or MB_ICONSTOP
invoke LocalFree,lpMsgBuffer
popad
ret
HandleError endp






SendDlgItemMessage (CB_GETCURSEL) is sent during WM_CHAR. This API returns an error (i dont remember it's number). I made this simple example for him.
Posted on 2004-01-22 04:48:58 by AceEmbler
I don't quite understand the meaning with the HandleError process. However if none of the dialog contols are in focus and you press a keyboard key a WM_CHAR message is sent to WndProc process which in turn calls the SendDlgItemMessage function. If one of the items from the list box of the combo is selected, the return value is a zerobased index. If no item is selected the return value is CB_ERR, i.e. -1. None of these values are actually errors. Independent of return value your code will cause an error message due to the call of HandleError process.
Posted on 2004-01-22 06:59:50 by minor28
You should call SetLastError before calling that function to verify that it is indeed the code that cause the error. Anyway it looks alright to me.
Posted on 2004-01-22 07:24:59 by roticv