Using a very simple dialog box for a main window, and I'm unable to insert items into a combobox. After the SendMessage call, the combobox is still blank :( The res file includes:
0 DIALOG 0, 0, 249, 109
STYLE WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX |WS_CAPTION
CLASS "DWTDlgClass"
CAPTION "Additional DHS Workstation Tasks"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
CONTROL "",0,"STATIC",SS_BLACKFRAME |WS_CHILD |WS_VISIBLE ,10,5,65,34
CONTROL "",1,"COMBOBOX",CBS_HASSTRINGS |CBS_DROPDOWNLIST |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,8,58,237,50
CONTROL "Choose Task:",2,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,58,46,47,8
CONTROL "&Quit",3,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,10,90,50,14
CONTROL "&Next >>",4,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE |WS_DISABLED ,190,90,50,14
The code is (scroll to highlighted):
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\Strings.mac
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
buffer db 1024 dup(?)
.const
IDC_COMBOBOX equ 1
IDC_QUIT equ 3
IDC_NEXT equ 4
.code
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
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
LOCAL hDlg: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,DLGWINDOWEXTRA
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,$CTA0("DWTDlgClass")
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,0,NULL,NULL,NULL
mov hDlg,eax
invoke ShowWindow, hDlg,SW_SHOWNORMAL
invoke UpdateWindow, hDlg
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke IsDialogMessage, hDlg, ADDR msg
.IF eax ==FALSE
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hCOMBOBOX:HANDLE
mov eax,uMsg
.IF eax==WM_DESTROY
invoke CloseHandle, hCOMBOBOX
invoke PostQuitMessage, NULL
.ELSEIF eax==WM_CREATE
invoke GetDlgItem, hWnd, IDC_COMBOBOX
mov hCOMBOBOX, eax
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("1st")
.ELSEIF eax==WM_COMMAND
mov eax,wParam
.IF lParam==0
.ELSE
.IF ax==IDC_NEXT
shr eax,16
.IF ax==BN_CLICKED
; do next thing
.ENDIF
.ELSEIF ax==IDC_QUIT
shr eax,16
.IF ax==BN_CLICKED
invoke DestroyWindow, hWnd
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
It been a few hours, and I can't see what I'm missing! Any gurus see what's causing this to fail?
0 DIALOG 0, 0, 249, 109
STYLE WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX |WS_CAPTION
CLASS "DWTDlgClass"
CAPTION "Additional DHS Workstation Tasks"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
CONTROL "",0,"STATIC",SS_BLACKFRAME |WS_CHILD |WS_VISIBLE ,10,5,65,34
CONTROL "",1,"COMBOBOX",CBS_HASSTRINGS |CBS_DROPDOWNLIST |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,8,58,237,50
CONTROL "Choose Task:",2,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,58,46,47,8
CONTROL "&Quit",3,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,10,90,50,14
CONTROL "&Next >>",4,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE |WS_DISABLED ,190,90,50,14
The code is (scroll to highlighted):
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\Strings.mac
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
buffer db 1024 dup(?)
.const
IDC_COMBOBOX equ 1
IDC_QUIT equ 3
IDC_NEXT equ 4
.code
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
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
LOCAL hDlg: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,DLGWINDOWEXTRA
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,$CTA0("DWTDlgClass")
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,0,NULL,NULL,NULL
mov hDlg,eax
invoke ShowWindow, hDlg,SW_SHOWNORMAL
invoke UpdateWindow, hDlg
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke IsDialogMessage, hDlg, ADDR msg
.IF eax ==FALSE
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hCOMBOBOX:HANDLE
mov eax,uMsg
.IF eax==WM_DESTROY
invoke CloseHandle, hCOMBOBOX
invoke PostQuitMessage, NULL
.ELSEIF eax==WM_CREATE
invoke GetDlgItem, hWnd, IDC_COMBOBOX
mov hCOMBOBOX, eax
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("1st")
.ELSEIF eax==WM_COMMAND
mov eax,wParam
.IF lParam==0
.ELSE
.IF ax==IDC_NEXT
shr eax,16
.IF ax==BN_CLICKED
; do next thing
.ENDIF
.ELSEIF ax==IDC_QUIT
shr eax,16
.IF ax==BN_CLICKED
invoke DestroyWindow, hWnd
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
It been a few hours, and I can't see what I'm missing! Any gurus see what's causing this to fail?
at a guess, its because you've made it local within the wndproc, the wndproc doesnt quite work like that, its called each time a message is passed to it, so the local stuff wont work as the stack will most likely get trashed, try doing storing the combobox window handle in a dword in the data segment, it will probably work then
;============================
#include </masm32/include/resource.h>
2005 DIALOG 0, 0, 249, 109
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Additional DHS Workstation Tasks"
FONT 12, "Arial"
{
? CONTROL "",0,"STATIC",SS_BLACKFRAME |WS_CHILD |WS_VISIBLE ,10,5,65,34
? CONTROL "",1,"COMBOBOX",CBS_DROPDOWNLIST | WS_TABSTOP,8,58,237,50
? CONTROL "Choose Task:",1002,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,58,46,47,8
? CONTROL "&Quit",3,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,10,90,50,14
? CONTROL "&Next >>",4,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE |WS_DISABLED ,190,90,50,14
}
;==========================================================
start:
invoke GetModuleHandle, NULL
mov? ? hInstance,eax
invoke DialogBoxParam,hInstance,2005,NULL,addr WndProc,NULL
invoke ExitProcess,eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
Local hCOMBOBOX:HANDLE
mov? ?eax,uMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
invoke GetDlgItem, hWnd, IDC_COMBOBOX
mov hCOMBOBOX, eax
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("1st")
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("2st")
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("3st")
invoke SendMessage, hCOMBOBOX, CB_SETCURSEL,0,0
;invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX, CB_ADDSTRING, NULL,$CTA0("1st")
;invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX, CB_SETCURSEL,0,0
.ELSEIF eax==WM_COMMAND
mov eax,wParam
.IF lParam==0
.ELSE
.IF ax==IDC_NEXT
shr eax,16
.IF ax==BN_CLICKED
; do next thing
.ENDIF
.ELSEIF ax==IDC_QUIT
shr eax,16
.IF ax==BN_CLICKED
invoke DestroyWindow, hWnd
.ENDIF
.ENDIF
.ENDIF
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
WndProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
#include </masm32/include/resource.h>
2005 DIALOG 0, 0, 249, 109
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Additional DHS Workstation Tasks"
FONT 12, "Arial"
{
? CONTROL "",0,"STATIC",SS_BLACKFRAME |WS_CHILD |WS_VISIBLE ,10,5,65,34
? CONTROL "",1,"COMBOBOX",CBS_DROPDOWNLIST | WS_TABSTOP,8,58,237,50
? CONTROL "Choose Task:",1002,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,58,46,47,8
? CONTROL "&Quit",3,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,10,90,50,14
? CONTROL "&Next >>",4,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE |WS_DISABLED ,190,90,50,14
}
;==========================================================
start:
invoke GetModuleHandle, NULL
mov? ? hInstance,eax
invoke DialogBoxParam,hInstance,2005,NULL,addr WndProc,NULL
invoke ExitProcess,eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
Local hCOMBOBOX:HANDLE
mov? ?eax,uMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
invoke GetDlgItem, hWnd, IDC_COMBOBOX
mov hCOMBOBOX, eax
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("1st")
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("2st")
invoke SendMessage, hCOMBOBOX, CB_ADDSTRING, NULL, $CTA0("3st")
invoke SendMessage, hCOMBOBOX, CB_SETCURSEL,0,0
;invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX, CB_ADDSTRING, NULL,$CTA0("1st")
;invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX, CB_SETCURSEL,0,0
.ELSEIF eax==WM_COMMAND
mov eax,wParam
.IF lParam==0
.ELSE
.IF ax==IDC_NEXT
shr eax,16
.IF ax==BN_CLICKED
; do next thing
.ENDIF
.ELSEIF ax==IDC_QUIT
shr eax,16
.IF ax==BN_CLICKED
invoke DestroyWindow, hWnd
.ENDIF
.ENDIF
.ENDIF
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
WndProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
Thanks for the suggestions. I tried the code above, and moving the control handle globally, but neither worked. The comment on the stack got me thinking to look outside of that block though.
Now I don't know why, but it turned out that hWnd wasn't being passed the correct value when CreateDialogParam was called. If I moved the SendMessage outside of the WndProc to after the CreateDialogParam call, then called SendMessage with the dialog handle returned by CreateDialogParam, then the items would insert!
I would think that when CreateDialogParam is called, it passes the right handle to the WndProc. Apparently not!
Thanks for your help and suggestions!
Now I don't know why, but it turned out that hWnd wasn't being passed the correct value when CreateDialogParam was called. If I moved the SendMessage outside of the WndProc to after the CreateDialogParam call, then called SendMessage with the dialog handle returned by CreateDialogParam, then the items would insert!
I would think that when CreateDialogParam is called, it passes the right handle to the WndProc. Apparently not!
Thanks for your help and suggestions!