Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2012, 1:58 AM   #1
AName
Newbie
 
Join Date: Sep 2011
Posts: 3
Rep Power: 0 AName is on a distinguished road
Question Please help with Win32 Dialogs and Controls

Hello,

I'm using WinAsm Studio (which uses the MASM assembly language or something) to develop a Win32 x86 application. I'm having trouble adding a button to a dialog... I would like to be able to add, rename, move, hide, show, enable, disable, remove, connect/link, etc. the button dynamically - that's my end goal for now at least.

I'll post the code that I think is relevant to my problem:

.data
firstS db "BUTTON", 0
secondS db "Dont click me", 0

.data?
hInstance dword ?
dialogInstance HINSTANCE ?
styleParams DWORD ?

.code
start:
	invoke GetModuleHandle, NULL
	mov hInstance, eax
	invoke DialogBoxParam, hInstance, 101, 0, ADDR DlgProc, 0
	
	invoke ExitProcess, 0
	
	DlgProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
  .if uMsg == WM_INITDIALOG
  	invoke GetWindowLong, hWin, GWL_HINSTANCE
  	mov dialogInstance, eax
  	
  	mov eax, WS_CHILD
  	add eax, WS_TABSTOP
  	add eax, WS_VISIBLE
  	add eax, BS_DEFPUSHBUTTON
  	mov styleParams, eax
  	
  	invoke CreateWindowEx, NULL, firstS, secondS, styleParams, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWin, NULL, dialogInstance, NULL
  .elseif	uMsg == WM_COMMAND
  ;.if	wParam == 
        ;.elseif	wParam == 
  ;.endif
  .elseif	uMsg == WM_CLOSE
  	invoke EndDialog,hWin,0
  .endif
  
  xor eax, eax
  
  ret
	DlgProc endp
end start

The rest of the code is pretty much the same as the WinAsm Dialog Base template, minus the static controls and Dialog style... If I comment out everything in the ".if uMsg == WM_INITDIALOG" section (I bolded it above), the program runs successfully and I can see the Dialog as expected.

What am I doing wrong? I am new to assembly and Win32 programming, although I've used many different higher level languages and graphics libraries and such so I'm familiar with a few of the concepts.

If you could not only help me solve my problem but also help me solve future problems by telling me things like the following, you would be a tremendous help:
  • How do I know when to use HWND, HINSTANCE, DWORD, etc.? Should it always be 100% the same as the parameter type?
  • How do I know what registers and such to use? I've kind of just been assuming that all values returned are eax (or should I use stack, maybe?), because I don't know how else to know (I've been using this: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx). I've read up on assembly, registers, etc., but I don't know how they work with Windows commands, basically. Also, when I invoke (call) a Windows function and it returns a value, how do I access it - is it in eax, the stack, etc.? Is this kind of information in the Win32.hlp file, because Microsoft doesn't give me a way to view it on Windows 8 release preview.
  • How would I change the style of a dialog window at runtime? How do I know where to place code that modifies the dialog, adds controls, etc.? Should it go inside DlgProc or not?
  • Can I create local variables, and if so, how?
  • How would I output the value of a register (such as eax) in a Win32 application? I understand that usually people would output a register value using the C printf function, but I can't do that because I'm using Windows. I guess a MessageBox would work here, but I don't know how to convert the value to a string.

Also, there's one more thing that I'm interested in that doesn't relate much to any of my problems or questions above: how do you create custom windows in assembly language that aren't rectangular (e.g. make it resemble a smiley face or something)?


I know I've asked a lot of questions, but believe me: I have looked everywhere, read everything, and watched everything to try to find the answers to the questions above. If you don't know the answer to everything or don't feel like answering everything, that's ok. I'd rather at least get some information to help me than get no help at all.


Thanks for your help!

- Andrew
AName is offline   Reply With Quote
Old Jun 29th, 2012, 7:51 AM   #2
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: Please help with Win32 Dialogs and Controls

>>How do I know when to use HWND, HINSTANCE, DWORD, etc.? Should it always be 100% the same as the parameter type?

Look up the functions (e.g. use google) and the function description will tell you. Yes it should always be the same type.

It would be a lot easier for you to first write the program in a higher level language such as C so that you learn how win32 programs work.

>>How do I know what registers and such to use?
It uses the same registers that all other programs use. To help you see this just write a small snippet in C language then have your C compiler generate an assembly language file. I know vc++ will do it, don't know about others.

>>How would I change the style of a dialog window at runtime?

You need to read/study a win32 api tutorial. This one is excellent introduction.

>>Can I create local variables, and if so, how?

You mean to tell us that you are attempting to write a win32 api GUI program in assembly language but know absolutely nothing about assembly language??? Sort of like wanting to swim the English Channel but can't swim a stroke in a swimming pool.

>>How would I output the value of a register (such as eax) in a Win32 application?
The same way you output text in other languages, use win32 api text functions.

>>but I don't know how to convert the value to a string.
The same way that you would convert any integer to a string. I'd suggest you first learn how to do it in C language then do it in assembly the same way. That is probably a C Programming 101 assignment.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)

Last edited by Ancient Dragon; Jun 29th, 2012 at 8:04 AM.
Ancient Dragon is offline   Reply With Quote
Old Jun 29th, 2012, 3:00 PM   #3
AName
Newbie
 
Join Date: Sep 2011
Posts: 3
Rep Power: 0 AName is on a distinguished road
Re: Please help with Win32 Dialogs and Controls

Thank you. I think you've helped me more than you know.

- Andrew
AName is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VC++: Refreshing dialog controls titaniumdecoy C++ 7 Aug 8th, 2006 9:55 PM
Tab controls some1 C++ 0 Apr 17th, 2005 4:28 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC