Archive: Checking dialog checkboxes


Checking dialog checkboxes
  This is a checkbox control on an exe dialog (not InstallOptions)

Is there a WindowsMessage to do this, because I'd rather not have to use the System plugin with BM_SETCHECK (http://www.minigui.com/api_ref/group...__msgs.html#a1)

Cheers

-Stu


Did you forget SendMessage NSIS command? It does exactly the same thing as using SendMessage from System plugin (except it can't get parameters from "wparam" and "lparam", it just set).


Yeh SendMessage will do it. I'ved used it for working with checkboxes as follows...

SendMessage $R1${BM_SETCHECK} 1 0 

>
To set the checkbox state. I believe changing the 1 to 0 will turn the checkbox off.


SendMessage $R1 ${BM_GETSTATE} 0 0 $R2 

>
To get the checkbox state and $R2 will contain either 1 or 0 depending on if the checkbox is checked or not.

Yes, but wheres the BM_SETCHECK define? It's not in WinMessages.nsh (not the one that I have anyhow)

-Stu


No it isn't you have to add it. It's in some windows header file if you really want to look it up. Just type in BM_SETCHECK in any source file in visual studio and select "go to definition". That'll give you the value or just copy the following...

!define BM_GETSTATE 0x00F2
!define BM_SETCHECK 0x00F1


That's what I've been trying to find (must reinstall VB!)

Thanks

-Stu


Thanks rsegal.Now I have another question: how can I send message to change a droplist box state?A sample ini file like this


***93;

>NumFields=1

>***91;Field 1***93;
>Type=Droplist
Text
=Droplist
State=1
ListItems=1|2|3
Left=77
Right=174
Top=27
Bottom=119
>
Default state is "1",I want to send a message cause it change to "2".


define CB_FINDSTRINGEXACT          0x0158

>!define CB_SETCURSEL 0x014E

SendMessage $hCtrl${CB_FINDSTRINGEXACT} -1 "String to be selected" $0
SendMessage $hCtrl${CB_SETCURSEL} $0 ""

I test deguix's code,but not work.These is my code


Name                 "Test"

>OutFile ".\test.exe"
>Caption "Test"
>SetCompressor lzma
ShowInstDetails show
>!include MUI.nsh

Page custom SetCustom LeaveCustom

!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English

Section
SectionEnd

>Function SetCustom
InstallOptions
::initDialog /NOUNLOAD "$PLUGINSDIR\test2.ini"
Pop $9
InstallOptions::show
FunctionEnd

>; --------------------------------------
!define CB_FINDSTRINGEXACT 0x0158
>!define CB_SETCURSEL 0x014E

>Function LeaveCustom
ReadINIStr $R0"$PLUGINSDIR\test2.ini" Settings State
StrCmp $R0 0 validate
StrCmp $R0 2 droplist
Abort

droplist:
ReadINIStr $1 "$PLUGINSDIR\test2.ini" "Field 2" State
GetDlgItem $R1$9 1200
SendMessage $R1${CB_FINDSTRINGEXACT} -1 $1 $0
SendMessage $R1${CB_SETCURSEL} $0 ""
;EnableWindow $R1 0
Abort

validate:
>FunctionEnd

>Function .onInit
InitPluginsDir
File "/oname=$PLUGINSDIR\test2.ini" ".\test2.ini"
>FunctionEnd
>
And these is my ini file

.

***91;
Settings***93;
>NumFields=2

>***91;Field 1***93;
>Type=Droplist
Text=Droplist
State=1
ListItems=1|2|3
Left=61
Right=218
Top=6
Bottom=100

>***91;Field 2***93;
>Type=Droplist
Text=Droplist
Flags=NOTIFY
State=1
ListItems=1|2|3
Left=62
Right=220
Top=60
Bottom=151
>
I want droplist 2 control droplist 1.What wrong for me?

I thought it would not work because of that -1 I put for ${CB_FINDSTRINGEXACT}. MSDN says that if wparam is -1 it would search the whole list, but that doesn't happen. Put 0 on its place.


I replaceed -1 with 0,but still not work.


Hmmm... Aparently there is a problem with SendMessage from NSIS. Everytime I change the number in wparam and/or lparam it should return the correct index of the item (it now returns 0). This is the correct (tested this time):

!define CB_FINDSTRINGEXACT          0x0158 
!define CB_SETCURSEL 0x014E

System::Call 'user32::SendMessageA(i R1, i ${CB_FINDSTRINGEXACT}, i -1, t r1)i .r0'
System::Call 'user32::SendMessageA(i R1, i ${CB_SETCURSEL}, i r0,)'

I got a idear to do it


define CB_GETCURSEL                0x0147 

>!define CB_SETCURSEL 0x014E
GetDlgItem $R1 $HWND 1201
SendMessage $R1${CB_GETCURSEL} -1 0 $R2
GetDlgItem $R1 $HWND 1200
SendMessage $R1${CB_SETCURSEL} $R2 0
>