int WINAPI DialogBoxIndirectParam(HINSTANCE hInst, HGLOBAL hDialog, HWND hWnd, DLGPROC lpFunc, LPARAM lParam) { HWND hDlg; LPDLGTEMPLATE lpDialog; lpDialog= (LPDLGTEMPLATE) LockResource(hDialog); /* modal dialogs are always visible */ lpDialog->style |= WS_VISIBLE; hDlg = CreateDialogIndirectParam(hInst,(LPCSTR)lpDialog, hWnd,lpFunc,lParam); if (!hDlg) return -1; if (hWnd) EnableWindow(hWnd,FALSE); UnlockResource(hDialog); return InternalDialog(hDlg); }
HWND WINAPI CreateDialogParam(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { PMWDLGTEMPLATE pDlg; HWND hRet; HGLOBAL hResDlg; HRSRC hRes = FindResource(hInstance, lpTemplate, RT_DIALOG); if (hRes == NULL) return NULL; hResDlg = LoadResource(hInstance, hRes); pDlg = (PMWDLGTEMPLATE) LockResource(hResDlg); if (pDlg == NULL) return NULL; hRet = CreateDialogIndirectParam(hInstance, (LPCDLGTEMPLATE)pDlg, hWndParent, lpDialogFunc, dwInitParam); UnlockResource(hResDlg); FreeResource(hResDlg); return hRet; }
void MsgBox::doModalless( HWND parent /* = NULL */, unsigned int timeOutTicks /*= INFINITE*/ ) { topmost_ = false; if( parent == NULL ) parent = getDefaultParent(); if( buttons_.empty() && timeOutTicks == INFINITE ) { result_ = TIME_OUT; return; } model_ = false; DLGTEMPLATE dlg[ 2 ] = { { 0 } }; dlg->style = DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_VISIBLE | WS_SYSMENU; dlg->dwExtendedStyle = WS_EX_TOPMOST; dlg->cdit = 0; dlg->x = 0; dlg->y = 0; dlg->cx = 100; dlg->cy = 100; timeOut_ = timeOutTicks; CreateDialogIndirectParam( GetModuleHandle( NULL ), dlg, parent, dialogProc, (LPARAM)this ); }
static HWND MakeModelessDialogBox(HINSTANCE hInstance, HWND hwndOwner, LPCSTR lpTemplateName, BOOL bEnableTemplate, BOOL bEnableTemplateHandle, LPCSTR lpRsc, void *lpCommDlgStruct, DLGPROC lpfnDlgProc) { HINSTANCE hInst; LPSTR lpDlg; void FAR *lpvDlgTmp; LastCommonDialogError = 0; if ( !(hInst = GetModuleHandle("COMMDLG")) ) hInst = LoadLibrary("COMMDLG"); if ( bEnableTemplateHandle ) { lpvDlgTmp = GlobalLock((HGLOBAL)hInstance); return CreateDialogIndirectParam(hInst, lpvDlgTmp, hwndOwner, lpfnDlgProc, (LPARAM)lpCommDlgStruct); } if ( bEnableTemplate ) { lpDlg = (LPSTR)lpTemplateName; hInst = hInstance; } else lpDlg = (LPSTR)lpRsc; return CreateDialogParam(hInst, lpDlg, hwndOwner, lpfnDlgProc, (LPARAM)lpCommDlgStruct); }
/** * name: CreateWnd * class: CPsTreeItem * desc: create the dialog for the propertysheet page * params: pPs - propertysheet's datastructure * hDlg - windowhandle of the propertysheet * return: windowhandle of the dialog if successful **/ HWND CPsTreeItem::CreateWnd(LPPS pPs) { if (pPs && !_hWnd && _pTemplate && _pfnDlgProc) { _hWnd = CreateDialogIndirectParam(_hInst, _pTemplate, pPs->hDlg, _pfnDlgProc, (LPARAM)_hContact); if (_hWnd != NULL) { PSHNOTIFY pshn; pshn.hdr.code = PSN_PARAMCHANGED; pshn.hdr.hwndFrom = _hWnd; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)_initParam; SendMessage(_hWnd, WM_NOTIFY, 0, (LPARAM)&pshn); // force child window (mainly for AIM property page) SetWindowLongPtr(_hWnd, GWL_STYLE, (GetWindowLongPtr(_hWnd, GWL_STYLE) & ~(WS_POPUP|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME)) | WS_CHILD); SetWindowLongPtr(_hWnd, GWL_EXSTYLE, GetWindowLongPtr(_hWnd, GWL_EXSTYLE) & ~(WS_EX_APPWINDOW|WS_EX_STATICEDGE|WS_EX_CLIENTEDGE)); SetParent(_hWnd, pPs->hDlg); // move dialog into the display area SetWindowPos(_hWnd, HWND_TOP, pPs->rcDisplay.left, pPs->rcDisplay.top, pPs->rcDisplay.right - pPs->rcDisplay.left, pPs->rcDisplay.bottom - pPs->rcDisplay.top, FALSE); // set bold titles if (_dwFlags & ODPF_BOLDGROUPS) EnumChildWindows(_hWnd, BoldGroupTitlesEnumChildren, (LPARAM)pPs->hBoldFont); // some initial notifications OnInfoChanged(); OnPageIconsChanged(); return _hWnd; } } return NULL; }
HWND ModelessDialogParam (int idd, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { HINSTANCE hInstFound; LPCDLGTEMPLATE pTemplate; if ((pTemplate = TaLocale_GetDialogResource (idd, &hInstFound)) == NULL) return NULL; return CreateDialogIndirectParam (hInstFound, pTemplate, hWndParent, lpDialogFunc, dwInitParam); }
HWND PhCreateDialogFromTemplate( _In_ HWND Parent, _In_ ULONG Style, _In_ PVOID Instance, _In_ PWSTR Template, _In_ DLGPROC DialogProc, _In_ PVOID Parameter ) { HRSRC resourceInfo; ULONG resourceSize; HGLOBAL resourceHandle; PDLGTEMPLATEEX dialog; PDLGTEMPLATEEX dialogCopy; HWND dialogHandle; resourceInfo = FindResource(Instance, Template, MAKEINTRESOURCE(RT_DIALOG)); if (!resourceInfo) return NULL; resourceSize = SizeofResource(Instance, resourceInfo); if (resourceSize == 0) return NULL; resourceHandle = LoadResource(Instance, resourceInfo); if (!resourceHandle) return NULL; dialog = LockResource(resourceHandle); if (!dialog) return NULL; dialogCopy = PhAllocateCopy(dialog, resourceSize); if (dialogCopy->signature == 0xffff) { dialogCopy->style = Style; } else { ((DLGTEMPLATE *)dialogCopy)->style = Style; } dialogHandle = CreateDialogIndirectParam(Instance, (DLGTEMPLATE *)dialogCopy, Parent, DialogProc, (LPARAM)Parameter); PhFree(dialogCopy); return dialogHandle; }
HWND OBSCreateDialog(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { if (!LocaleIsRTL()) return CreateDialogParam(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam); HRSRC dlg = FindResource(hInstance, lpTemplateName, RT_DIALOG); HGLOBAL rsc = LoadResource(hInstance, dlg); List<BYTE> tmpl; tmpl.InsertArray(0, (BYTE const*)LockResource(rsc), SizeofResource(hInstance, dlg)); *(DWORD*)&tmpl[sizeof WORD * 2 + sizeof DWORD] |= WS_EX_LAYOUTRTL; return CreateDialogIndirectParam(hInstance, (LPCDLGTEMPLATE)&tmpl[0], hWndParent, lpDialogFunc, dwInitParam); }
HWND CreateLocalizedDialogParam(const UINT dialogId, DLGPROC dialogFunc, const LPARAM param) { /* find dialog resource */ HRSRC res = FindResourceLang(RT_DIALOG, MAKEINTRESOURCE(dialogId), GetGUILanguage()); if (res == NULL) return NULL; HGLOBAL resInfo = LoadResource(o.hInstance, res); if (resInfo == NULL) return NULL; return CreateDialogIndirectParam(o.hInstance, resInfo, NULL, dialogFunc, param); }
MRPWindow::MRPWindow(HWND parent, std::string title) { #ifdef WIN32 MyDLGTEMPLATE t; t.style = DS_SETFONT | DS_FIXEDSYS | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME; t.cx = 200; t.cy = 100; t.dwExtendedStyle = WS_EX_TOOLWINDOW; m_hwnd = CreateDialogIndirectParam(g_hInst, &t, parent, (DLGPROC)dlgproc, (LPARAM)this); #else m_hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_EMPTYDIALOG), parent, dlgproc, (LPARAM)this); #endif //m_hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_EMPTYDIALOG), // parent, dlgproc, (LPARAM)this); g_mrpwindowsmap[m_hwnd] = this; SetWindowText(m_hwnd, title.c_str()); SetWindowPos(m_hwnd, NULL, 20, 60, 100, 100, SWP_NOACTIVATE | SWP_NOZORDER); ShowWindow(m_hwnd, SW_SHOW); m_is_closed = false; }
HWND TUnixDialogBox :: DoCreate ( void ) { char far * globalp ; // Récupération du pointeur vers le template globalp = ( char far * ) GlobalLock ( MemoryHandle ) ; // Création de la boiboite DialogHandle = CreateDialogIndirectParam ( * GetModule ( ), globalp, ( ParentWindow != NULL ) ? ParentWindow -> HWindow : NULL, ( DLGPROC ) ( FARPROC ) DialogProcInstance, Attr. Param ) ; // Déverrouillage du template GlobalUnlock ( MemoryHandle ) ; // C'est bon return ( DialogHandle ) ; }
HWND far pascal zCreateDialogIndirectParam( HANDLE pp1, LPSTR pp2, HWND pp3, FARPROC pp4, long pp5 ) { HWND r; FARPROC fp ; SaveRegs(); fp = pp4 ; if (fp) { pp4 = (FARPROC)HookAdd( (void far *)DlgMesgProc, (void far *)fp ); } /* ** Log IN Parameters (No Create/Destroy Checking Yet!) */ LogIn( (LPSTR)"APICALL:CreateDialogIndirectParam HANDLE+LPSTR+HWND+FARPROC+long+", pp1, pp2, pp3, pp4, pp5 ); /* ** Call the API! */ RestoreRegs(); GrovelDS(); r = CreateDialogIndirectParam(pp1,pp2,pp3,pp4,pp5); UnGrovelDS(); SaveRegs(); /* ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!) */ LogOut( (LPSTR)"APIRET:CreateDialogIndirectParam HWND++++++", r, (short)0, (short)0, (short)0, (short)0, (short)0 ); RestoreRegs(); return( r ); }
int wCreateSplash( char *appname, char *appver ) { HGLOBAL hgbl; LPDLGTEMPLATE lpdt; LPWORD lpw; LPDLGITEMTEMPLATE lpdit; int cxDlgUnit, cyDlgUnit; int cx, cy; char *pszBuf; HBITMAP hBmp; BITMAP bmp; char logoPath[MAX_PATH]; /* find the size of a dialog unit */ cxDlgUnit = LOWORD(GetDialogBaseUnits()); cyDlgUnit = HIWORD(GetDialogBaseUnits()); /* load the logo bitmap */ sprintf( logoPath, "%s\\logo.bmp", wGetAppLibDir()); hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE ); if( !hBmp ) return( 0 ); /* get info about the loaded logo file */ GetObject( hBmp, sizeof(BITMAP), (LPVOID)&bmp ); /* calculate the size of dialog box */ cx = (bmp.bmWidth * 4) / cxDlgUnit; /* start with the size of the bitmap */ cy = (bmp.bmHeight * 8) / cyDlgUnit + 20; /* 20 is enough for two lines of text and some room */ /* allocate memory block for dialog template */ hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024); if (!hgbl) return -1; lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl); /* Define a dialog box. */ lpdt->style = WS_POPUP | WS_BORDER | WS_VISIBLE | DS_MODALFRAME | DS_CENTER; lpdt->cdit = 3; // number of controls lpdt->x = 0; lpdt->y = 0; lpdt->cx = cx; lpdt->cy = cy; lpw = (LPWORD) (lpdt + 1); *lpw++ = 0; /* no menu */ *lpw++ = 0; /* predefined dialog box class (by default) */ *lpw++ = 0; /* add the static control for the logo bitmap */ lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw); lpdit->x = 0; lpdit->y = 0; lpdit->cx = (SHORT)((bmp.bmWidth * 4) / cxDlgUnit); lpdit->cy = (SHORT)((bmp.bmHeight * 8) / cyDlgUnit); lpdit->id = IDBITMAP; lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; lpw = (LPWORD) (lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0082; /* static class */ lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Logo should be here...", -1, (LPWSTR)lpw, 50); /* add the static control for the program title */ lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw); lpdit->x = 2; lpdit->y = (short)( 1 + (bmp.bmHeight * 8) / cyDlgUnit ); lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit; lpdit->id = IDAPPNAME; lpdit->style = WS_CHILD | WS_VISIBLE | SS_CENTER; lpw = (LPWORD) (lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0082; /* static class */ /* create the title string */ pszBuf = malloc( strlen( appname ) + strlen( appver ) + 2 ); if( !pszBuf ) return( 0 ); sprintf( pszBuf, "%s %s", appname, appver ); lpw += 1+MultiByteToWideChar (CP_ACP, 0, pszBuf, -1, (LPWSTR)lpw, 50); /* add the static control for the loading message */ lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw); lpdit->x = 2; lpdit->y = (short)(bmp.bmHeight * 8) / cyDlgUnit + 10; lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit; lpdit->id = IDMESSAGE; lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; lpw = (LPWORD) (lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0082; /* static class */ lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Starting Application...", -1, (LPWSTR)lpw, 50); /* create the dialog */ GlobalUnlock(hgbl); hSplash = CreateDialogIndirectParam( mswHInst, (LPDLGTEMPLATE) hgbl, mswHWnd, (DLGPROC)SplashDlgProc, (LPARAM)hBmp ); GetLastError(); /* free allocated memory */ GlobalFree(hgbl); free( pszBuf ); /* that's it */ return 1; }
static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { DetailsData *dat = (DetailsData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { DlgProfData *prof = (struct DlgProfData*)lParam; PROPSHEETHEADER *psh = prof->psh; SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0)); dat = (DetailsData*)mir_alloc(sizeof(DetailsData)); dat->prof = prof; prof->hwndOK = GetDlgItem(hwndDlg, IDOK); prof->hwndSM = GetDlgItem(hwndDlg, IDC_SM_COMBO); EnableWindow(prof->hwndOK, FALSE); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); TCHAR buf[512]; mir_sntprintf(buf, SIZEOF(buf), _T("%s\n%s"), TranslateT("Miranda NG profile manager"), TranslateT("Manage your Miranda NG profile")); SetDlgItemText(hwndDlg, IDC_NAME, buf); dat->currentPage = 0; dat->pageCount = psh->nPages; dat->opd = (DetailsPageData*)mir_calloc(sizeof(DetailsPageData)*dat->pageCount); OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)psh->ppsp; TCITEM tci; tci.mask = TCIF_TEXT; for (int i = 0; i < dat->pageCount; i++) { dat->opd[i].pTemplate = (DLGTEMPLATE *)LockResource(LoadResource(odp[i].hInstance, FindResourceA(odp[i].hInstance, odp[i].pszTemplate, MAKEINTRESOURCEA(5)))); dat->opd[i].dlgProc = odp[i].pfnDlgProc; dat->opd[i].hInst = odp[i].hInstance; dat->opd[i].hwnd = NULL; dat->opd[i].changed = 0; tci.pszText = (TCHAR*)odp[i].ptszTitle; if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->szProfile)) dat->currentPage = 1; TabCtrl_InsertItem(GetDlgItem(hwndDlg, IDC_TABS), i, &tci); } GetWindowRect(GetDlgItem(hwndDlg, IDC_TABS), &dat->rcDisplay); TabCtrl_AdjustRect(GetDlgItem(hwndDlg, IDC_TABS), FALSE, &dat->rcDisplay); POINT pt = { 0, 0 }; ClientToScreen(hwndDlg, &pt); OffsetRect(&dat->rcDisplay, -pt.x, -pt.y); TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), dat->currentPage); dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof); ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE); PSHNOTIFY pshn; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = 0; SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); // service mode combobox if (servicePlugins.getCount() == 0) { ShowWindow(GetDlgItem(hwndDlg, IDC_SM_LABEL), FALSE); ShowWindow(GetDlgItem(hwndDlg, IDC_SM_COMBO), FALSE); } else { HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO); LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("")); SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1); SendMessage(hwndCombo, CB_SETCURSEL, 0, 0); for (int i = 0; i < servicePlugins.getCount(); i++) { pluginEntry *p = servicePlugins[i]; index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->pluginname)); SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)i); } } ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); } return TRUE; case WM_CTLCOLORSTATIC: switch (GetDlgCtrlID((HWND)lParam)) { case IDC_WHITERECT: SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); } break; case PSM_CHANGED: dat->opd[dat->currentPage].changed = 1; return TRUE; case PSM_FORCECHANGED: { PSHNOTIFY pshn; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.idFrom = 0; pshn.lParam = 0; for (int i = 0; i < dat->pageCount; i++) { pshn.hdr.hwndFrom = dat->opd[i].hwnd; if (dat->opd[i].hwnd != NULL) SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); } } break; case WM_NOTIFY: switch (wParam) { case IDC_TABS: switch (((LPNMHDR)lParam)->code) { case TCN_SELCHANGING: if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL) { PSHNOTIFY pshn; pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = 0; if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) { SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); return TRUE; } } break; case TCN_SELCHANGE: if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL) ShowWindow(dat->opd[dat->currentPage].hwnd, SW_HIDE); dat->currentPage = TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS)); if (dat->currentPage != -1) { if (dat->opd[dat->currentPage].hwnd == NULL) { PSHNOTIFY pshn; dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof); ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE); pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = 0; SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); } ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); } break; } break; } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: { PSHNOTIFY pshn; pshn.hdr.idFrom = 0; pshn.lParam = 0; pshn.hdr.code = PSN_RESET; for (int i = 0; i < dat->pageCount; i++) { if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) continue; pshn.hdr.hwndFrom = dat->opd[i].hwnd; SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); } EndDialog(hwndDlg, 0); } break; case IDC_REMOVE: if (!dat->prof->pd->noProfiles) { HWND hwndList = GetDlgItem(dat->opd[0].hwnd, IDC_PROFILELIST); DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat->prof); } break; case IDOK: PSHNOTIFY pshn; pshn.hdr.idFrom = 0; pshn.lParam = 0; if (dat->currentPage != -1) { pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) break; } pshn.hdr.code = PSN_APPLY; for (int i = 0; i < dat->pageCount; i++) { if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) continue; pshn.hdr.hwndFrom = dat->opd[i].hwnd; SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); if (GetWindowLongPtr(dat->opd[i].hwnd, DWLP_MSGRESULT) == PSNRET_INVALID_NOCHANGEPAGE) { TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), i); if (dat->currentPage != -1) ShowWindow(dat->opd[dat->currentPage].hwnd, SW_HIDE); dat->currentPage = i; ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); return 0; } } EndDialog(hwndDlg, 1); } break; case WM_DESTROY: if (dat->currentPage != 1) { LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETCURSEL, 0, 0); if (curSel != CB_ERR) { int idx = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, (WPARAM)curSel, 0); SetServiceModePlugin(servicePlugins[idx]); } } DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); DeleteObject(dat->hBoldFont); for (int i = 0; i < dat->pageCount; i++) if (dat->opd[i].hwnd != NULL) DestroyWindow(dat->opd[i].hwnd); mir_free(dat->opd); mir_free(dat); break; } return FALSE; }
HWND WINAPI CreateDialogIndirect(HINSTANCE hInst, const VOID *lpDlg, HWND hWnd, DLGPROC lpFunc) { return CreateDialogIndirectParam(hInst,lpDlg,hWnd,lpFunc,0L); }
HWND CreateCancelDialog(void) { HWND hwndButton,dlgHdl; WORD *p, *pdlgtemplate,baseunitX,baseunitY; int nchar; int scrnWidth,scrnHeight; int buttonX, buttonY, buttonWidth, buttonHeight; int textX, textY, textWidth, textHeight; DWORD lStyle,baseunits; HDC screen; LOGFONT lf; /* allocate some memory to play with */ pdlgtemplate = p = (PWORD) rmalloc (1000); screen = CreateDC ("DISPLAY", NULL, NULL, NULL); scrnWidth = GetDeviceCaps (screen, HORZRES); scrnHeight = GetDeviceCaps (screen, VERTRES); DeleteDC (screen); baseunits = GetDialogBaseUnits(); /* start to fill in the dlgtemplate information. addressing by WORDs */ lStyle = WS_CAPTION | DS_MODALFRAME | WS_SYSMENU; baseunitX=LOWORD(baseunits); baseunitY=HIWORD(baseunits); *p++ = LOWORD (lStyle); *p++ = HIWORD (lStyle); *p++ = 0; /* LOWORD (lExtendedStyle) */ *p++ = 0; /* HIWORD (lExtendedStyle) */ *p++ = 0; /* NumberOfItems */ *p++ = ((scrnWidth*4)/3)/baseunitX; // x *p++ = ((scrnHeight*8)/3)/baseunitY; // y *p++ = DIALOG_WIDTH; /* cx */ *p++ = DIALOG_HEIGHT; /* cy */ *p++ = 0; /* Menu */ *p++ = 0; /* Class */ /* copy the title of the dialog */ nchar = nCopyAnsiToWideChar (p, (char *) "Printing in Progress"); p += nchar; dlgHdl = CreateDialogIndirectParam (ghInst, (LPDLGTEMPLATE) pdlgtemplate, ghMainWindow, (DLGPROC) PrintDlgProc, (LPARAM) 0); rfree(pdlgtemplate); // Add a text field textWidth = 19*baseunitX; textHeight = baseunitY; textX = (((DIALOG_WIDTH*baseunitX)/4) - textWidth) / 2; textY = (((DIALOG_HEIGHT*baseunitY)/8) - textHeight) / 4; hwndText = CreateWindow ("static", "",WS_VISIBLE | WS_CHILD | SS_CENTER, textX, textY, textWidth, textHeight, dlgHdl, (HMENU) 0, ghInst, 0); // Add a Cancel button: buttonWidth = 10*baseunitX; buttonHeight = (3*baseunitY)/2; buttonX = (((DIALOG_WIDTH*baseunitX)/4) - buttonWidth) / 2; buttonY = (3 * (((DIALOG_HEIGHT*baseunitY)/8) - buttonHeight)) / 5; hwndButton = CreateWindow ("button", "Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, buttonX, buttonY, buttonWidth, buttonHeight, dlgHdl, (HMENU) 0, ghInst, 0); SetLogFontData (&lf,"MS Sans Serif",0,8); SendMessage(hwndButton,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0)); SendMessage(hwndText,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0)); ShowWindow (dlgHdl,SW_SHOWNORMAL); return dlgHdl; }
static HWND SearchResource(LPCSTR lpName, int type, DLGPROC pDialogProc, LPARAM param, char *lpFileBase, int TotalFileSize, HWND parentWnd) { char *pResAll = lpFileBase + TotalFileSize; PRES pRes = (PRES)lpFileBase; char pszSearchedName[256]; char *pszType = ResourceType(pRes); char *pszName; int size = ResourceSize(pRes); char Name[512],*bb; PDIALOGBOXHEADER pdbh; HWND result; UINT_PTR ul; ul = (UINT_PTR)lpName; if (HIWORD(ul) == 0) { sprintf(pszSearchedName,"%d",LOWORD(ul)); } else if (IsOrd((char *)lpName)) { sprintf(pszSearchedName,"%d",OrdID(lpName)); } else if (lpName[1] == 0 && lpName[3] == 0) { ConvertWideString((char *)lpName,(char *)pszSearchedName); } else { strcpy(pszSearchedName,lpName); } do { if (pRes->HeaderSize+pRes->DataSize == 0) break; if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_DLGINCLUDE) { /* Ignore include files */ ; } else if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_RESOURCE32) { /* * This is the dummy resource that identifies a * 32 bit resource file. This resource should be * skipped also. */ } else { /* This is some other kind of a resource. See if it matches */ if (pRes->DataSize) { int size = ResourceSize(pRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == type) { pszName = ResourceName(pRes); if (!IsOrd(pszName)) { if (pszName[1] == 0 && pszName[3] == 0) ConvertWideString(pszName,Name); else strcpy(Name,pszName); } else { sprintf(Name,"%d",OrdID(pszName)); } if (!strcmp(Name,pszSearchedName)) { /* found it.*/ if (type == 5) { /* Build a dialog box */ pdbh = (PDIALOGBOXHEADER) SkipResHeader(pRes); bb = malloc(size); memcpy(bb,pdbh,size); result = CreateDialogIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)bb, parentWnd, pDialogProc,param); free(bb); return result; } else if (type == 4) { /* Build a menu */ return (HWND) ReadMenu((char *)SkipResHeader(pRes)); } else if (type == 3) { /* Build an Icon */ HICON hicon; hicon = CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, TRUE, 0x30000); return (HWND)hicon; } else if (type == 1) { /* Build a cursor */ return (HWND)CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, FALSE, 0x30000); } else if (type == 2 || type == 14) { /* Build bitmap */ char *start = SkipResHeader(pRes); bb = malloc(size); memcpy(bb,start,size); return (HWND) bb; } } } } } /* Move to the next resource. */ pRes = (PRES) (((char *) pRes) + pRes->HeaderSize + pRes->DataSize); DWordAlign((PBYTE *)&pRes); } while (pRes < (PRES) ((char *) pResAll + size)); return (HWND) 0; }
static bbUINT uiDlgCreateModal(uiDlg* const pThis, uiWINH hParent, const bbCHAR* pName, bbU32 style, bbU32 styleEx, uiRect const* pRect, int const modal) { bbUINT ret = -1; HGLOBAL hgbl = NULL; LPDLGTEMPLATE lpdt = NULL; LPWORD lpw; int nchar; uiDlgCreate create; bbASSERT(hParent); create.pThis = pThis; if (!pRect) ::GetClientRect(hParent, (RECT*)&create.rect); else create.rect = *pRect; #define uiDLGTEMPLATESIZE 1024 nchar = 1 + bbStrLen(pName); if (nchar > ((uiDLGTEMPLATESIZE - sizeof(DLGTEMPLATE) - 2*sizeof(WORD) / sizeof(bbCHAR) - 8*2))) // adjust this if code changed below { bbErrSet(bbENOMEM); goto uiDlg_CreateModal_err; } if ( ((hgbl = GlobalAlloc(GMEM_ZEROINIT, uiDLGTEMPLATESIZE)) == NULL) || ((lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl)) == NULL)) { bbErrSet(bbENOMEM); goto uiDlg_CreateModal_err; } lpdt->style = style | WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT; lpdt->dwExtendedStyle = styleEx; lpdt->cdit = 0; // number of controls lpdt->x = (short)create.rect.left; lpdt->y = (short)create.rect.top; lpdt->cx = (short)(create.rect.right - create.rect.left); lpdt->cy = (short)(create.rect.bottom - create.rect.top); lpw = (LPWORD) (lpdt + 1); *lpw++ = 0; // no menu *lpw++ = 0; // predefined dialog box class (by default) bbMemMove(lpw, pName, nchar*sizeof(bbCHAR)); // title lpw += nchar; *lpw++ = 8; // font bbStrCpy((bbCHAR*)lpw, bbT("Tahoma")); if (lpdt) GlobalUnlock(hgbl); if (modal) { ret = DialogBoxIndirectParam(uighInstance, (LPDLGTEMPLATE) hgbl, hParent, (DLGPROC) uiDialogProc, (LPARAM)&create); } else { HWND hWin = CreateDialogIndirectParam(uighInstance, (LPDLGTEMPLATE) hgbl, hParent, (DLGPROC) uiDialogProc, (LPARAM)&create); if (!hWin) bbErrSet(uiEWINCREATE); else ret = 0; bbASSERT(pThis->mhWin==hWin); } uiDlg_CreateModal_err: if (hgbl) GlobalFree(hgbl); return ret; }
/* ** Create (if not already) and show the dialog. ** */ void CBaseDialog::Show(const WCHAR* title, short x, short y, short w, short h, DWORD style, DWORD exStyle, HWND parent, bool modeless) { if (m_Window) { // Show existing window. ShowWindow(m_Window, SW_SHOW); SetForegroundWindow(m_Window); return; } const WCHAR* font = L"MS Shell Dlg 2"; const size_t titleSize = (wcslen(title) + 1) * sizeof(WCHAR); const size_t fontSize = (wcslen(font) + 1) * sizeof(WCHAR); const size_t dataSize = sizeof(DLGTEMPLATE) + sizeof(WCHAR) + // Menu array. sizeof(WCHAR) + // Class array. titleSize + // Title array. sizeof(WORD) + // Font point size. fontSize; // Font array. DLGTEMPLATE* dt = (DLGTEMPLATE*)new BYTE[dataSize]; dt->style = style | DS_SHELLFONT | WS_VISIBLE; dt->dwExtendedStyle = exStyle; dt->cdit = 0; dt->x = x; dt->y = y; dt->cx = w; dt->cy = h; BYTE* dtExtra = (BYTE*)dt + sizeof(DLGTEMPLATE); // Menu array. *(WCHAR*)dtExtra = L'\0'; dtExtra += sizeof(WCHAR); // Class array. *(WCHAR*)dtExtra = L'\0'; dtExtra += sizeof(WCHAR); // Title array. memcpy(dtExtra, title, titleSize); dtExtra += titleSize; // Font point size. *(WORD*)dtExtra = 8; dtExtra += sizeof(WORD); // Font array. memcpy(dtExtra, font, fontSize); if (modeless) { CreateDialogIndirectParam(NULL, dt, parent, InitialDlgProc, (LPARAM)this); } else { DialogBoxIndirectParam(NULL, dt, parent, InitialDlgProc, (LPARAM)this); } delete [] dt; }
int WINAPI DialogBoxIndirectParam(HINSTANCE hInstance, LPCDLGTEMPLATE hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM lParam) { return DIALOG_DoDialogBox (CreateDialogIndirectParam(hInstance, hDialogTemplate, hWndParent, lpDialogFunc, lParam), hWndParent); }