Solved

MODAL window/Buttons question?

Posted on 2000-03-20
5
257 Views
Last Modified: 2012-05-04
Hi,

I have two questions:

- How can I create/set a MODAL window?
- How can I create/set a button to look
  like a button on IE cool toolbar??

As for the first, I tried everything but could not figure out how to make the created window be a MODAL. Note that I created a window that has an icon and tried to make this window a MODAL?! I heard that MODAL windows should not have icons ????
As for the second, I could create a normal button, set its properties, but what I want exactly is a button that work and look like a button on IE toolbar, i.e. a button that looks initially like a normal label with no borders, and when the mouse is pointed over the button it should change its appearance to look like a button (i.e. the borders should appear).

Thank you for your help,

Wesam
0
Comment
Question by:_Wesam
5 Comments
 
LVL 5

Expert Comment

by:jamoville
ID: 2637383
Try taking a look at the CReBar class for the buttons you descibed.
0
 

Accepted Solution

by:
leff earned 20 total points
ID: 2637386
To Create a Modal Dialog in API, use
to create a dialog in API, use
Dialogbox(hinstance,nameId,parentID,dialog Procedure Name);

To Exit, use
Enddlg(hDlg,return-code);



Modal dialogs in MFC

class CMyDialog: public CDialog
{
public:
 CMyDialog::CMyDialog(int x,CWnd* pParentWnd=NULL) :
    CDialog (x,pParentWnd) {}
      ....
void CMainWindow:: OnDialog ( )
{
    CMyDialog dlg(IDD_MYDIALOG, this);
    fprintf(f,"do modal\f");fflush(f);
    dlg.DoModal ();
}

Modeless dialogs in MFC
void CMainWindow:: OnDialog ( )
{
    CMyDialog dlg(IDD_MYDIALOG, this);
    fprintf(f,"do modal\f");fflush(f);
    dlg.DoModal ();
}

See http://www.wiu.edu/users/mflll/CS412g
for more info on Windows programming.
0
 

Expert Comment

by:nicholso
ID: 2637395
(1) the first part is easy. For window classes descended from CDialog, just do the following.
example: the about dialog (CAboutDlg).

in your code:
      CAboutDlg aboutDlg;
      aboutDlg.DoModal();

this will launch the about dialog as modal.

(2) this is a bit more work. One thing you could do is define the function CWnd::OnMouseMove() for the dialog this button is in. This gets called everytime the mouse moves. Then every time the move moves you could check if the mouse is over your button. If it is, change the border style like you're talking about.

let me know if you need more clarification/code.
0
 

Author Comment

by:_Wesam
ID: 2639281
Hi,

 Oops .. I made a mistake, I had to say that I used pure API functions (not MFC) for both questions. So I create windows, controls by hand. As for the first idea (creating a dialog box) it has one drawback, I can't assign an icon to the dialog box!!!!!! I want to create a dialog box that has an icon (I could do this in VB - it does this automatically). I didn't use a resource file, because I couldn't change the default icon there either.
As for the second idea, I couldn't manage to have something like creating a label then changing the label properties to appear like a button and assign the other necessary properties when it is clicked PLUS this approach is a little bit complicated and probably there is another way to do the same thing.
Can you provide me with source code in your reply, it would be very helpful for me.

Thanks,

Wesam.

0
 
LVL 2

Expert Comment

by:DarrinE
ID: 2657399
Yu can assign an icon from a resource file to a dialog window using the following code :

/*------------------------------------------------------- Header Files      */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include "resource.h"

#include "define.h"

/*------------------------------------------------------- Local Defines      */

/*-------------------------------------------------- External Data Area      */
extern HINSTANCE                         hInstance;                  // The instance of this program
extern HWND                               MainHwnd ;                  // The handle of the Main Window
/*-------------------------------------------------- External Functions      */
/*---------------------------------------------- Local Data Allocations      */
/*--------------------------------------------- Public Data Allocations      */
/*----------------------------------------------------- Local Functions      */
/*---------------------------------------------------- Public Functions      */

BOOL WINAPI SetWindowIcon( HINSTANCE hInst, HWND hwnd, UINT uID );
/*****************************************************************
FUNCTION :      SetWindowIcon( HINSTANCE hInst, HWND hwnd, UINT uID );
Params :      hInst      = the instance of the program
                  hwnd      = the dialog window handle
                  uID            = the dialog icon resource identifier

Return Value = TRUE if successful or FALSE if not
*****************************************************************/
BOOL WINAPI SetWindowIcon( HINSTANCE hInst, HWND hwnd, UINT uID )
{
      BOOL bRetVal = FALSE;

      if( IsWindow( hwnd ) )
      {
            HINSTANCE hInst = (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE );
            HICON hIconSmall = (HICON)LoadImage( hInst, MAKEINTRESOURCE( uID ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR );
            HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE( uID ) );

            if( hIconSmall )
                  SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall );


            if( hIcon )
                  SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );

            bRetVal = TRUE;
      }

  return bRetVal;
}

This is a complete code snippet - you need to call this function in WM_INITDIALOG

As for your explorer type button - I cant help right now but I'll give it some thought

DarrinE
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now