Thoughts from Dan Miser RSS 2.0
 Thursday, March 15, 2007
I needed to implement a dialog that could be used to stop from displaying over and over again. We've all seen countless variations on this theme. I also didn't want to go to the extent of using hooks to accomplish this.

I came across the SHMessageBoxCheck function, and it appears to give me what I need. Granted, it is far from perfect, but it works for me. I used the declaration from PInvoke.net, but I received a PInvokeStackImbalance exception from MDA. I modified the DllImport to use PreserveSig to true, and the error is gone. I did update the wiki to mention this finding, so hopefully others will be able to verify.

All in all, this function works well. But, by trying to be lazy and use a pre-existing solution, it definitely took longer than it would have had I written my own custom dialog. I'm sure that won't be the last time that happens. ;-)

Thursday, March 15, 2007 8:49:05 AM (Central Standard Time, UTC-06:00)  #    Comments [1] -
.NET
Tracked by:
http://9ns-information.info/80374876/tomy-thomas-2007-products.html [Pingback]
http://9nq-information.info/96301813/index.html [Pingback]
http://9nc-information.info/62084231/index.html [Pingback]
http://9nh-information.info/39782035/index.html [Pingback]
http://9nc-information.info/99850085/adl-security-melbourne.html [Pingback]
http://9nx-information.info/18568385/index.html [Pingback]
http://9nf-information.info/09971365/index.html [Pingback]
http://9nb-information.info/31570609/index.html [Pingback]
http://9ng-information.info/43879568/city-ofphiladelphia-school-district.html [Pingback]
http://9os-information.info/79840622/national-magazine-company-ltd.html [Pingback]
http://9ox-information.info/32890500/index.html [Pingback]
http://9oo-information.info/34318107/index.html [Pingback]
http://9qs-information.info/37538711/costo-legno.html [Pingback]
http://9qg-information.info/38912103/saima-ferrari.html [Pingback]
http://9os-information.info/93128492/index.html [Pingback]
http://9oa-information.info/20835991/index.html [Pingback]
http://9rg-information.info/37738216/queens-botanic-garden.html [Pingback]
http://9rc-information.info/11319616/lifted-chevy-photo-gallery.html [Pingback]
http://9ru-information.info/23817186/sportscraft-foosball-billiards-table.html [Pingback]
http://9rc-information.info/59361438/index.html [Pingback]
http://9rf-information.info/86356833/american-school-home-schooling.html [Pingback]
http://9sf-information.info/98478792/index.html [Pingback]
http://9rm-information.info/43125906/index.html [Pingback]
http://9sh-information.info/09167411/index.html [Pingback]
http://9rd-information.info/20677772/index.html [Pingback]
http://9se-information.info/64982788/index.html [Pingback]
http://9uafl-le-informazioni.info/94945969/index.html [Pingback]
http://9uael-le-informazioni.info/52583480/editor-pes-5.html [Pingback]
http://9uaef-le-informazioni.info/59026224/ospedale-san-leonardo-di-salerno.html [Pingback]
http://9uaep-le-informazioni.info/76669837/ace-brain.html [Pingback]
http://9uafb-le-informazioni.info/57106826/costo-produzione-girasole.html [Pingback]
http://9uaft-le-informazioni.info/32074308/a-gas-ferroli.html [Pingback]
http://9uafm-le-informazioni.info/10852233/scienza-comunicazione-savona.html [Pingback]
http://9uaee-le-informazioni.info/37893304/index.html [Pingback]
http://9uafg-le-informazioni.info/29828991/index.html [Pingback]
http://9uaep-le-informazioni.info/95555698/index.html [Pingback]
http://9uafm-le-informazioni.info/31308176/ferilli-completamente-nuda.html [Pingback]
http://9uagc-le-informazioni.info/54589949/index.html [Pingback]
http://9uagf-le-informazioni.info/19408252/costruzione-stampo-rifilatura-treviso... [Pingback]
http://9uagf-le-informazioni.info/75363155/offerte-disneyland-paris.html [Pingback]
http://9uahc-le-informazioni.info/76994318/index.html [Pingback]
http://9uaht-le-informazioni.info/74830853/index.html [Pingback]
http://9uahd-le-informazioni.info/77588785/index.html [Pingback]
http://9uahk-le-informazioni.info/80815348/index.html [Pingback]
http://9uahf-le-informazioni.info/00428949/index.html [Pingback]
http://sinuta.com/2007/06/03/ascend/ [Pingback]
http://gajipa.com/2007/06/03/kraut-raume-infiniti-beanstandung-update/ [Pingback]
http://gspsf-happyholidays.com/2007/03/08/new-reports-straight-lines-publishes/ [Pingback]
http://thepowerbox.com/2007/06/12/reinforcement-the-speak-scored/ [Pingback]
http://kemifa.com/2007/06/03/alternative-one-for-the-social-network-connectionbl... [Pingback]
http://pinemi.com/wp-login.php?redirect_to=http://pinemi.com/about/ [Pingback]
http://kigyga.com/2007/06/03/as-broadband-changed-the-world/ [Pingback]
http://thepowerbox.com/2007/06/12/small-change-large-change/ [Pingback]
http://stapita.com/2007/06/03/boom-rank-bay/ [Pingback]
http://executivefitnessmaa.com/2007/03/08/count-down-too-dolphin-carries/ [Pingback]
http://gspsf-happyholidays.com/2007/06/12/new-york-town-center-march-13/ [Pingback]
http://thecanabible.com/2007/02/04/librarians-picture-and-cognitive-dissonance/ [Pingback]
http://arnifa.com/2006/11/05/schauen-badly-in-the-eye/ [Pingback]
http://tanola.com/2007/06/03/amazing-agreements-of-the-life/ [Pingback]
http://thecanabible.com/2007/02/04/a-joint-virtual-it-world/ [Pingback]
http://nasroka.com/2007/06/03/as-much-in-so-little-time/ [Pingback]
http://cefana.com/2007/06/03/my-rings-liking-my-blankey/ [Pingback]
http://sakmara.com/2007/06/03/wikipedia-has-now-a-list-of-places-of-assembly-and... [Pingback]
http://chicopaddleheads.com/2007/06/12/filters-possibilities-of-reading-off-a-po... [Pingback]
http://kauai-honeymoon-specials.com/2007/03/08/so-thinking-it-that-it-results-da... [Pingback]
http://ernestcreations.com/2007/03/08/june-of-14-2005-appropriate-doubts/ [Pingback]
http://netsib-benelux.com/2007/03/08/colbert-low-is-new-publisher-for-itechtips/ [Pingback]
http://kigyga.com/2007/06/03/do-they-suffer-from-lowest-point-main-line-bus-driv... [Pingback]
http://zabity.com/2007/06/03/inclination-and-pragmatismus/ [Pingback]
http://azinna.com/2007/06/03/internee/ [Pingback]
http://disola.com/2007/06/03/bogdanovic-turns-down-davis-bowl-opportunity/ [Pingback]
http://gajipa.com/2006/11/05/google-scratch/ [Pingback]
http://stejala.com/2007/06/03/back-dissolution-of-the-ip-addresses-with-ajax/ [Pingback]
http://rojara.com/2007/06/03/tactics-fright-chers/ [Pingback]
http://gajipa.com/2007/06/03/school-loses-class-participants-literally/ [Pingback]
http://thecanabible.com/2007/02/04/worthwhile-work-property-settles-with-fun/ [Pingback]
http://nakrema.com/2007/06/03/excerpt-of-the-inadvertent-investment-banker/ [Pingback]
http://gajipa.com/2006/11/05/on-set-your-profit-hats-it-gave-a-cave-in-in-united... [Pingback]
http://oknama.com/2006/11/05/something-it-today-doing-having-assistance-chris-be... [Pingback]
http://nasroka.com/2007/06/03/internet-unfalplan/ [Pingback]
http://stejala.com/2007/06/03/find-to-nokia-mobile-telephone-microprogram-list-v... [Pingback]
http://chicopaddleheads.com/2007/03/08/dancing-graciousness/ [Pingback]
http://gajipa.com/2007/06/03/christmas-with-christina/ [Pingback]
http://gajipa.com/2007/06/03/an-unequal-playing-field/ [Pingback]
http://arnifa.com/2007/06/03/mono-harmful-applied/ [Pingback]
http://gspsf-happyholidays.com/2007/06/12/a-last-probability-on-the-budget/ [Pingback]
http://stapita.com/2007/06/03/ibm-complaint-could-damage-of-amazon-main-line-stu... [Pingback]
http://stejala.com/2007/06/03/more-sanctions/ [Pingback]
http://azinna.com/2007/06/03/bored-the-google-never-lies/ [Pingback]
http://disola.com/2007/06/03/marbury-v-madison-part-i/ [Pingback]
http://arnifa.com/2007/06/03/the-keystroke-which-logs-on-the-ascent-says-securit... [Pingback]
http://azinna.com/2007/06/03/if-it-is-not-a-thing-is-it-different/ [Pingback]
http://pinemi.com/2007/06/03/step-from-the-river/ [Pingback]
http://pimpasa.com/2007/06/03/bead-pilot-concert/ [Pingback]
http://bisena.com/2007/06/03/q-when-isnt-a-thoughtless-process-thoughtless-a-if-... [Pingback]
http://kovjara.com/2007/06/03/bitter-melon-with-chile-yogurt-and-peaches/ [Pingback]
http://chicopaddleheads.com/2007/06/12/coolly/ [Pingback]
http://avinnovators.com/2007/03/08/a-volume-aid-does-not-regulate-it/ [Pingback]
http://thecanabible.com/2007/02/04/okayzeit-to-really-disturb-blogging/ [Pingback]
http://cefana.com/2007/06/03/participant-inferno/ [Pingback]
http://gajipa.com/2007/06/03/creative-confusion-on-your-desk/ [Pingback]
http://nakrema.com/2007/06/03/natrecor-connected-with-increased-number-of-deaths... [Pingback]
http://gspsf-happyholidays.com/2007/06/12/bad-hair-day-with-opel-tigra/ [Pingback]
http://begagy.com/2007/06/03/wine-vintage-ferragamoesque-of-platform-wedge-shoes... [Pingback]
http://parjitta.com/2007/06/03/religion-and-spirituality/ [Pingback]
http://thecanabible.com/2007/02/04/an-opinion-in-world-mapes/ [Pingback]
http://senkara.com/2007/06/03/crescent-shaped-shower-rod/ [Pingback]
http://3rdcoaststudios.com/2007/03/08/cio-corner-1010-1126/ [Pingback]
http://kovjara.com/2007/06/03/trackbacks-and-pingbacks-wtf/ [Pingback]
http://thecanabible.com/2007/02/04/communicated-by-elise-on-august-28-2005/ [Pingback]
Wednesday, March 21, 2007 5:09:47 AM (Central Standard Time, UTC-06:00)
Why I always get the -1 as the return of SHMessageBoxCheck function? Is there somewhere explain this issue? I have found the reason on the MSDN website, but there is no infomration for that why it return -1 as result.

Here is the code I used:

function MessageBoxCheck(hWnd: THandle; Text: PChar; Title: PChar;
dwType: DWORD; Default: Integer; RegVal: PChar): Integer;
type
TSHMessageBoxCheck = function(hWnd: THandle; Text: PChar; Title: PChar;
dwType: DWORD; Default: Integer; RegVal: PChar): Integer; stdcall;
var
hLib: THandle;
SHMessageboxCheck: TSHMessageBoxCheck;
begin
hLib := LoadLibrary('shlwapi.dll');
if hLib <> 0 then
begin
@SHMessageboxCheck := GetProcAddress(hLib, PChar(185));
if Assigned(SHMessageboxCheck) then
begin
result := SHMessageboxCheck(hWnd, Text, Title, dwType, 0, RegVal);
end
else
result := GetLastError;
end
else
result := GetLastError;
FreeLibrary(hLib);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(MessageBoxCheck(Handle,
PAnsiChar('Do you want to exit without saving?'#0),
PAnsiChar('Warning'#0), MB_YESNO or MB_ICONQUESTION, IDNO,
PAnsiChar('{575191FE-2069-4713-98F4-E20D1FF5BCF5}'#0))));
end;
Comments are closed.
Navigation
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 306
This Year: 21
This Month: 0
This Week: 0
Comments: 603
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)