The MASM Forum Archive 2004 to 2012

Project Support Forums => IDE Development and Support => RadAsm Support Forum => Topic started by: Shooter on December 05, 2010, 09:08:25 PM

Title: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: Shooter on December 05, 2010, 09:08:25 PM
Two more questions about RadASM (3.x):

1) How do I add an icon to a project?

I would've thought it would be in the "Resource | Add New >" area.

2) How do I set the new icon to a dialog box?


Thanks,
-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Gunner on December 05, 2010, 09:23:06 PM
Double click on your rc file to open in editor, then click (menu)Resource -> Resource Files click the  button add, Type = icon, name = whatever For the example it is named ICON_MAIN, Id = some#, and filename=self explanatory.. now in your code in WM_INITDIALOG:

invoke LoadImage, hInst, ICON_MAIN, IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR
invoke SendMessage, hWin, WM_SETICON,ICON_BIG, eax
invoke LoadImage, hInst, ICON_MAIN, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR
invoke SendMessage, hWin, WM_SETICON,ICON_SMALL, eax


Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 05, 2010, 10:04:56 PM
Thank you very much, Gunner. This is the actual code I used:

WMINITDIALOG:
      CMP EAX,WM_INITDIALOG
      JNE >WMCOMMAND
ADDICONS:
      INVOKE LoadImage, [hInst], 100, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR
      INVOKE SendMessage, [hwnd], WM_SETICON,ICON_SMALL, eax

Now I'm trying to add an image to the dialog that I added as an icon (same size as the one above, but different image) and set it's ID to 101. However, the location for the image (ID=1013) turns out blank when I run the dialog. I tried this code, but it didn't work:

      INVOKE LoadImage, [hInst], 101, IMAGE_BITMAP, 48, 48, LR_DEFAULTCOLOR
      MOV eax, 1013
      INVOKE SendMessage, [hwnd], WM_SETICON, ICON_BIG, eax


I didn't know if there was another WM_SET___ that I could try... nothing popped up that looked promising. Got any ideas?

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Gunner on December 05, 2010, 10:26:23 PM
WM_SETICON only sets the icon for the title bar and taskmenu/taskbar and whatever else shows the program info while running...  If you are trying to set the exe icon then just create an icon with 16x16, 32x32, 48x48 formats and add it to your resource file with the id of 1 then your 48x48 icon will show on the desktop

QuoteAn application sends the WM_SETICON message to associate a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: donkey on December 05, 2010, 10:31:42 PM
Adding an image to a dialog is not as simple as setting an icon. You will need a container for the image, usually a static or "picture box". And you will probably end up having to paint the image yourself if it is not static. Otherwise use a static control with the SS_BITMAP style.
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 05, 2010, 10:38:04 PM
Gunner,
Actually I've added an image to the dialog box that I eventually want to cycle some images through with a click of a button. I'm building a sample project that contains a variety of controls so I can use them later... this is just for training and education as I'm trying to get reacquainted with Assembly Language, but build programs for Windows.

(See Attached)

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: donkey on December 05, 2010, 10:48:08 PM
Assuming that the box where you want the image is a static control set the style to SS_BITMAP | SS_CENTERIMAGE then use the STM_SETIMAGE  (http://msdn.microsoft.com/en-us/library/bb760782%28VS.85%29.aspx) to assign an image to it.

EDIT: If you're using RadAsm's Image control set the alignment to "center" and the Type to "Bitmap", it's just a static control btw.
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 06, 2010, 03:17:03 AM
Quote from: donkey on December 05, 2010, 10:48:08 PM
Assuming that the box where you want the image is a static control set the style to SS_BITMAP | SS_CENTERIMAGE then use the STM_SETIMAGE  (http://msdn.microsoft.com/en-us/library/bb760782%28VS.85%29.aspx) to assign an image to it.

EDIT: If you're using RadAsm's Image control set the alignment to "center" and the Type to "Bitmap", it's just a static control btw.

Edgar,
Haha, I had already gone and made sure that the SS_BITMAP | SS_CENTERIMAGE were selected by the time you edited your post.

I did find that upon the 'image' creation to the RC file, the 'Visible' flag was set to false somehow. I changed it and now the image shows. I still want to know how to change the image now that it's showing, however, using STM_SETIMAGE is throwing me off (I'm not sure of it's syntax or usage, yet).

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: donkey on December 06, 2010, 03:38:10 AM
Hi Shooter,

Click on STM_SETIMAGE in my post above for syntax help.
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 06, 2010, 03:59:01 AM
Quote from: donkey on December 06, 2010, 03:38:10 AM
Hi Shooter,

Click on STM_SETIMAGE in my post above for syntax help.

Edgar,
My apologies, but perhaps what others see as syntax isn't what I see. STM_SETIMAGE may require 2 parameters, but do you call it, invoke it, SendMessage to it, SendDlgItemMessage to it (or reference it), say, "Hey Mr. STM_SETIMAGE, would you please change my image?" lol.

That link sent me to a page that, as far as I'm used to, does not contain any syntax or usage, just a description. I'm just a poor boy on the farm of knowledge and hadn't quite come across this path before. ;) Now, I ain't sayin' that I'm ignorant, just naive.  :bg

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Gunner on December 06, 2010, 04:14:15 AM
i usually say yo, set this image ;)   the page says an app SENDS this message, so use send message or senddlgitemmessage....  call it or invoke it...whatever you want off the top of my head, so i might be wrong...   invoke sendmessage, hctrl, stm_setimage, image_bitmap, hbitmap        and you have to free the image handle it returns if not 0 
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 06, 2010, 04:40:12 AM
Welp, this is they I've got it coded (shortened up for forum purposes), but it ain't doin' anything.


DlgProc FRAME hwnd,uMsg,wParam,lParam
   MOV EAX,[uMsg]
WMINITDIALOG:
      CMP EAX,WM_INITDIALOG
      JNE >WMCOMMAND
      INVOKE  LoadBitmap,[hInst], 101     ; 101 is the first bitmap IDC number
      MOV     [hBmp1], EAX
      INVOKE  LoadBitmap,[hInst], 102     ; 102 is the second bitmap IDC number
      MOV     [hBmp2], EAX
      JMP >EXIT
WMCOMMAND:
      CMP EAX,WM_COMMAND
      JNE >WMCLOSE
Button4_Click:                         
      MOV EAX,[wParam]           ; Load handle
      CMP EAX,1014                  ; Check to see if 'Swap Button' was clicked
      JNE >Quit                        ; Skip if not clicked
      INVOKE SendDlgItemMessage,[hwnd],1013,STM_SETIMAGE, IMAGE_BITMAP, OFFSET hBmp2 ; Change IDC 1013 (img)
      JMP >EXIT                       ; Get out of here
WMCLOSE:
      CMP EAX,WM_CLOSE
      JNE >DEFPROC
      INVOKE EndDialog,[hwnd],0
DEFPROC:
      mov EAX,FALSE
      RET
EXIT:

   MOV EAX, TRUE
   RET
DlgProc ENDF


I tried yellin' at the monitor a little, but it wasn't havin' any of that.  :eek

So, what am I doing wrong?

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: donkey on December 06, 2010, 05:03:09 AM
Hi Shooter,

You almost got it, you send the actual value of hBmp, not the offset:

INVOKE SendDlgItemMessage,[hwnd],1013,STM_SETIMAGE, IMAGE_BITMAP, [hBmp2]

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 06, 2010, 05:29:36 AM
Edgar,
I made that change, and it compiled just fine, but when I ran it the first time, my computer basically locked up. I rebooted and checked some things out and didn't find anything wrong. So I re-launched it, and this time the CPU usage is hanging around 98%. I was able to force it to shut down (task manager), and now I'm here.

I'm attaching the project for review, but I've got to get some sleep... got several hours of traveling for work tomorrow.

If you happen to try it out, please let me know if it hangs on you as well.

Again, many thanks,
-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: donkey on December 06, 2010, 05:38:39 AM
The project you attached is the old one with moduleproc and gfl.txt in it. But looking at the code above I would check the following line:

      JNE >Quit                        ; Skip if not clicked

Where is the Quit label ?

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project?
Post by: Shooter on December 06, 2010, 01:29:18 PM
Quote from: donkey on December 06, 2010, 05:38:39 AM
The project you attached is the old one with moduleproc and gfl.txt in it.
Edgar,
Hmmm, that was odd. I used the Zip file function of RadASM to make that package... I guess if a .zip file already exists it doesn't prompt to replace and doesn't let you know. I created a new one from WinRAR (see attached).

I did just now figure out that it wasn't the project that was locking up my computer, but RadASM itself. RadASM compiles the project without a problem, but if you click 'Run' the CPU usage goes through the roof. However, if you launch the project's .exe from Explorer, all works as it should.  :dazzled:

Also, I've tweaked a little here and there and got that section of my project to work.  :bg

One more question... what are the units in RadASM's RC editor for the height and width of an bitmap area/loaded image? I loaded two images approx 395x395 into a 400x400 'image frame', but there's a huge 'border' (gap) between the image and the edge of the bitmap area. I toyed around with it and reduced the bitmap area to 275x275... there's a thin 'border' (I'd guess maybe 10 pixels... about 1/3 the width of a scroll bar) on the left/right edges, but the top/bottom borders are nearly 5 times the left/right's. (Btw, I modified my project to these sizes AFTER making the .zip file.)

Thanks again,
-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Almost Solved)
Post by: fearless on December 09, 2010, 05:58:00 PM
END start

Might need that?
Title: Re: RadASM 3.x - How do I add Icons to Project? (Almost Solved)
Post by: donkey on December 09, 2010, 06:25:33 PM
Quote from: fearless on December 09, 2010, 05:58:00 PM
END start

Might need that?

Wrong assembler fearless, that's a MASM directive, its not necessary in GoAsm.

Shooter,

You didn't include the images in your zip.
Title: Re: RadASM 3.x - How do I add Icons to Project? (Almost Solved)
Post by: Shooter on December 09, 2010, 06:56:59 PM
The images are larger than allowed. I converted them to 256 color and zipped the heck out of 'em.

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Almost Solved)
Post by: donkey on December 09, 2010, 07:30:57 PM
The images seem to be displayed as expected. If you wish to have them always fit into the static you will have to subclass it and use StretchBlt to draw them.

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project? (Almost Solved)
Post by: Shooter on December 09, 2010, 08:32:59 PM
Edgar,
The part that doesn't make sense to me is I created the "Image" (control) and set it to just a few 'pixels??' larger than the bitmaps, but the gap between the bitmaps and the "Image" border were huge. That's why I asked what the 'units' RadASM uses to set the control... I assumed it was 'pixels'. Is that not the case? How much of a gap between the image and the border do you see?

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Almost Solved)
Post by: donkey on December 09, 2010, 08:42:06 PM
Hi Shooter,

RadAsm's resource editors units are in pixels and are translated to Dialog Units when written to an RC file via the customary formula (Pix*4)/BaseUnits for X and (Pix*8)/BaseUnits for Y. I'm afraid I deleted the files (I just keep them long enough to take a look) but the example you sent was a very small image control and very large images. The only thing showing were the standard border and the partial images.

I re-downloaded the project and ran it:

(http://img80.imageshack.us/img80/1421/imageforboard.jpg)

Note that the border is a 3D-Look border if you want a smaller one use Flat or Sunken.

(http://img84.imageshack.us/img84/672/borderi.jpg)

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: Shooter on December 09, 2010, 09:01:22 PM
Quote from: donkey on December 09, 2010, 08:42:06 PM
...translated to Dialog Units when written to an RC file via the customary formula (Pix*4)/BaseUnits for X and (Pix*8)/BaseUnits for Y.

Ahhhhhhh. That is INDEED a must to know. Thank you very much, and it fits, but I'm not sure I have a full grasp as to WHY the X vs. Y are so different, or even need to be 'translated' (calculated) like that, but cie la vie, non?

Btw, the "Image" was reset to a larger size in a latter version of the project than what I gave you, as was the entire dialog obviously.  :bg

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: donkey on December 09, 2010, 09:20:26 PM
Quote from: Shooter on December 09, 2010, 09:01:22 PM
Quote from: donkey on December 09, 2010, 08:42:06 PM
...translated to Dialog Units when written to an RC file via the customary formula (Pix*4)/BaseUnits for X and (Pix*8)/BaseUnits for Y.

Ahhhhhhh. That is INDEED a must to know. Thank you very much, and it fits, but I'm not sure I have a full grasp as to WHY the X vs. Y are so different, or even need to be 'translated' (calculated) like that, but cie la vie, non?

Btw, the "Image" was reset to a larger size in a latter version of the project than what I gave you, as was the entire dialog obviously.  :bg

-Shooter

Its actually a don't really need to know since it is exceedingly rare that you will ever need to directly edit an RC file. Dialog Units are the way they are because Windows needs to be able to proportionally adjust the size of a dialog based on the font that is being used and the DeviceCaps for the target DC. In a case like this size in pixels is pretty useless so the RC files use different units since they contain sizes are expected to adapt to different resolutions.

Note that this is not related to either GoAsm or RadAsm but is a requirement of Windows:

http://msdn.microsoft.com/en-us/library/ms645475%28VS.85%29.aspx

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: Shooter on December 09, 2010, 09:31:43 PM
Edgar,
Anyway I could get a copy of your brain?  :wink It sure would save some frustrations.  :toothy

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: donkey on December 09, 2010, 09:42:23 PM
Ah, you wouldn't want my brain. I was lucky when I started in assembler many years ago to have Iczelion, Hiroshimator, NaN and many others help me out, just returning the favor.  :U
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: Shooter on December 09, 2010, 09:45:48 PM
So, getting back to the practicality of it all... I'd have to make a call to identify what the base units are, then readjust the "Image" control to that size, or would I have to resize the bitmap to fit the control?

-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: donkey on December 09, 2010, 10:10:59 PM
Quote from: Shooter on December 09, 2010, 09:45:48 PM
So, getting back to the practicality of it all... I'd have to make a call to identify what the base units are, then readjust the "Image" control to that size, or would I have to resize the bitmap to fit the control?

-Shooter

No, you never have to use base units, as I said it is not something that many people are required to know unless they are writing a resource editor. You can use MoveWindow or SetWindowPos to resize the window to fit your images. They are documented at MSDN:

MoveWindow (http://msdn.microsoft.com/en-us/library/ms633534%28v=vs.85%29.aspx)
SetWindowPos (http://msdn.microsoft.com/en-us/library/ms633545%28VS.85%29.aspx)

Either that or set the size in the RadAsm resource editor but be aware that the size in pixels it gives includes the border area. The fourth option is to resize the image to fit your window, you can do that with StretchBlt.

StretchBlt (http://msdn.microsoft.com/en-us/library/dd145120%28v=vs.85%29.aspx)

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: donkey on December 09, 2010, 10:40:11 PM
This is an old example I wrote that covers how to read mp3 headers and tag information. It uses StretchBlt to fit the album art image to a static control. Its a pretty big application to show just the one feature and it uses GDI+ but you might find a few other things interesting as well...

Note that this was just a fairly quick example and its quite old so I won't be commenting on bugs or issues with it.

Edgar
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: Shooter on December 09, 2010, 11:14:54 PM
Quote from: donkey on December 09, 2010, 10:40:11 PM
Note that this was just a fairly quick example and its quite old so I won't be commenting on bugs or issues with it.

Seems to have assembled and ran just fine for me. Thanks.

One thing that led me away from the Visual Studio was that I was trying to build an MP3 player for windows, but I could not get past VBR. The song played just fine if it was constant rate, but VBR songs would skip all over the place. I'm a part time DJ and wanted to design my own playing DJ Console to MY liking, but gave up because of this. Your example just reminded me of that little issue when I saw "IsVBR". I'm going to have to keep that in mind as I develop my skills.

Thank you,
-Shooter
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: donkey on December 09, 2010, 11:21:02 PM
Yeah, to tell if a file is vbr encoded check 36 bytes into the audio header for "Xing"
Title: Re: RadASM 3.x - How do I add Icons to Project? (Solved)
Post by: Shooter on December 09, 2010, 11:45:23 PM
Edgar,
Knowing an MP3 file is VBR is one thing, playing it is another.  :wink

-Shooter