LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I show a Standard windows Dialog using (DialogBox()) inside LabWindows?

Hi guys, I have an already created Dialog using Visual C++ Resource Kit.

Has anyone tried to show a standard Dialog window inside a Labwindows function CallBack?.

As far I know, the problem would be placed in the relation between the diferents window manager.

The scheme would be;
/* Labwindow Callback Function */
int CVICALLBACK ShowCallBack (int panel, int control, int event, void *callbackData, int eventData1,int eventData2)
{
DialogBox(GhInst,MAKEINTRESOURCE(IDD_OPEN),(HWND)panel,NULL);
^^^^^^^^^^^^

return 0;
}

To allow compiling I needed to cast panel parameter to (HWND) this is where the mistake migh be, due to the relation between 'panel' and 'pare
ntWindows' any idea?

NOTE: No problems using an external compiler (Visual C++ 6.0)

Thks in advanced.
Carlos
Carlossg@spainmail.com
0 Kudos
Message 1 of 2
(3,242 Views)
By using the SDK you can use the DialogBox
and retrieve the handle for the parent window using calls as shown below



(From SDK)
--
HWND hwndOwner;
RECT rc, rcDlg, rcOwner;

case WM_INITDIALOG:

// Get the owner window and dialog box rectangles.

if ((hwndOwner = GetParent(hwndDlg)) == NULL)
{
hwndOwner = GetDesktopWindow();
}

GetWindowRect(hwndOwner, &rcOwner);
GetWindowRect(hwndDlg, &rcDlg);
CopyRect(&rc, &rcOwner);

// Offset the owner and dialog box rectangles so that
// right and bottom values represent the width and
// height, and then offset the owner again to discard
// space taken up by the dialog box.

OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
OffsetRect(&rc, -rc.left, -rc.top);
OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);

// The new position is the sum of half the remaining
// space and the owner's original position.

SetWindowPos(hwndDlg,
HWND_TOP,
rcOwner.left + (rc.right / 2),
rcOwner.top + (rc.bottom / 2),
0, 0, // ignores size arguments
SWP_NOSIZE);

if (GetDlgCtrlID((HWND) wParam) != ID_ITEMNAME)
{
SetFocus(GetDlgItem(hwndDlg, ID_ITEMNAME));
return FALSE;
}
return TRUE;

In the preceding statements, the procedure uses the GetParent function to retrieve the owner window handle for a dialog box. The function returns the owner window handle for dialog boxes, and the parent window handle for child windows. Because an application can create a dialog box that has no owner, the procedure checks the returned handle and uses the GetDesktopWindow function to retrieve the desktop window handle, if necessary. After calculating the new position, the procedure uses the SetWindowPos function to move the dialog box, specifying the HWND_TOP value to ensure that the dialog box remains on top of the owner window.

Before setting the input focus, the procedure checks the control identifier of the default input focus. The system passes the window handle of the default input focus in the wParam parameter. The GetDlgCtrlID function returns the identifier for the control identified by the window handle. If the identifier does not match the correct identifier, the procedure uses the SetFocus function to set the input focus. The GetDlgItem function is required to retrieve the window handle of the desired control.
Message 2 of 2
(3,242 Views)