unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate) { HGLOBAL res_handle; HRSRC res; unsigned char* p = NULL; res = FindResourceA(module, name, type); if (res == NULL) { uprintf("Could not locate resource '%s': %s\n", desc, WindowsErrorString()); goto out; } res_handle = LoadResource(module, res); if (res_handle == NULL) { uprintf("Could not load resource '%s': %s\n", desc, WindowsErrorString()); goto out; } *len = SizeofResource(module, res); if (duplicate) { p = (unsigned char*)malloc(*len); if (p == NULL) { uprintf("Coult not allocate resource '%s'\n", desc); goto out; } memcpy(p, LockResource(res_handle), *len); } else { p = (unsigned char*)LockResource(res_handle); } out: return p; }
void schemasInit(void) { xmlChar* buf; if (!(datatypes_rsrc = FindResourceA(MSXML_hInstance, "DATATYPES", "XML"))) { FIXME("failed to find resource for %s\n", DT_nsURI); return; } if (!(datatypes_handle = LoadResource(MSXML_hInstance, datatypes_rsrc))) { FIXME("failed to load resource for %s\n", DT_nsURI); return; } buf = LockResource(datatypes_handle); datatypes_len = SizeofResource(MSXML_hInstance, datatypes_rsrc); /* Resource is loaded as raw data, * need a null-terminated string */ while (buf[datatypes_len - 1] != '>') datatypes_len--; datatypes_src = HeapAlloc(GetProcessHeap(), 0, datatypes_len + 1); memcpy(datatypes_src, buf, datatypes_len); datatypes_src[datatypes_len] = 0; if (xmlGetExternalEntityLoader() != external_entity_loader) { _external_entity_loader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(external_entity_loader); } }
std::string Settings::GetCustomResource(const char *name, const char *type) { const HINSTANCE module = 0; // main executable HRSRC hRes = FindResourceA(module, name, type); if ( hRes ) { HGLOBAL hData = LoadResource(module, hRes); if ( hData ) { const char *data = (const char*)::LockResource(hData); size_t size = ::SizeofResource(module, hRes); if ( data && size ) { if ( data[size-1] == '\0' ) // null-terminated string size--; return std::string(data, size); } } } std::string err; err += "Failed to get resource \""; err += name; err += "\" (type \""; err += type; err += "\")"; throw Win32Exception(err.c_str()); }
std::string FxStringFromResource(void* module, const std::string& id, const std::string& type) { HMODULE hModule = reinterpret_cast<HMODULE>(module); const int idValue = atoi(id.c_str()); const char* idResource = MAKEINTRESOURCEA(idValue); HRSRC info = FindResourceA(hModule, idResource, type.c_str()); if (NULL == info) { return string(); } HGLOBAL handle = LoadResource(hModule, info); if (NULL == handle) { return string(); } char* text = reinterpret_cast<char*>(LockResource(handle)); DWORD size = SizeofResource(hModule, info); string result; try { result = string(text, text + size); } catch (const exception&) { } UnlockResource(handle); return result; }
int LoadLubeFromDll(const char *pszName, PLUBEHEADER *ppLube) { int nSize; HRSRC hResInfo; HGLOBAL hRes; LPVOID lpLockRes; HMODULE handle; if (pszName) { handle = LoadLibraryExA(pszName, NULL, LOAD_LIBRARY_AS_DATAFILE); if (!handle) goto ErrorExit; } else { handle = NULL; } hResInfo = FindResourceA(handle, "#1", "Lube"); if (!hResInfo) goto ErrorExit; nSize = SizeofResource(handle, hResInfo); if (0 == nSize) goto ErrorExit; hRes = LoadResource(handle, hResInfo); if (!hRes) goto ErrorExit; lpLockRes = LockResource(hRes); if (!lpLockRes) goto ErrorExit; return RelocFlattedLube((PLUBEHEADER)lpLockRes, nSize, ppLube); ErrorExit: fprintf(stderr, "[ERROR] lube (0x0303 : Can't load lube resource from file.\n"); return LUBE_FAIL; }
void schemasInit(void) { int len; char* buf; if (!(datatypes_rsrc = FindResourceA(MSXML_hInstance, "DATATYPES", "XML"))) { FIXME("failed to find resource for %s\n", DT_nsURI); return; } if (!(datatypes_handle = LoadResource(MSXML_hInstance, datatypes_rsrc))) { FIXME("failed to load resource for %s\n", DT_nsURI); return; } buf = LockResource(datatypes_handle); len = SizeofResource(MSXML_hInstance, datatypes_rsrc) - 1; /* Resource is loaded as raw data, * need a null-terminated string */ while (buf[len] != '>') buf[len--] = 0; datatypes_src = BAD_CAST buf; datatypes_len = len + 1; if (xmlGetExternalEntityLoader() != external_entity_loader) { _external_entity_loader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(external_entity_loader); } }
void ShowHelp(void) { #define ID_HELP_TEXT 10020 #define ID_DOS_TEXT 300 CONST CHAR* src; DWORD src_count, charsWritten; HGLOBAL res_data; HANDLE handle; HRSRC hSrc; ShowCopyright(); hSrc = FindResourceA(NULL, MAKEINTRESOURCEA(ID_HELP_TEXT),MAKEINTRESOURCEA(ID_DOS_TEXT)); if (!hSrc) return; src_count = SizeofResource(NULL, hSrc); res_data = LoadResource(NULL, hSrc); if (!res_data) return; src = (char*) LockResource(res_data); if (!src) return; if ((handle=GetStdHandle(STD_ERROR_HANDLE)) != INVALID_HANDLE_VALUE) WriteConsoleA(handle, src, src_count, &charsWritten, NULL); }
void setguids() { char d[50]; WCHAR duni[50]; char* p; char* q; char match[]="Class={"; HRSRC h= FindResourceA(g_hinst, (LPCSTR)MAKEINTRESOURCE(1), "typelib"); p=(char*)LockResource(LoadResource(g_hinst, h)); q=p+SizeofResource(g_hinst, h); while(p<q) { p=(char*)memchr(p,match[0],q-p); if(!p) return; // bad typelib if(!memcmp(p, match, strlen(match))) break; ++p; } p+=strlen(match); // start of class name q=strchr(p, '}'); // end of class name memcpy(jclass, p, q-p); jclass[p-q]=0; p=q+2; // start of version q=strchr(p, '}'); // end of version memcpy(jversion, p, q-p); jversion[q-p]=0; p=q+1; // { at start of CLSD q=strchr(p, '}'); // } at end of CLSID memcpy(d,p,1+q-p); d[1+q-p]=0; touni(d, duni); CLSIDFromString(duni, &jclsid); jlibid=jclsid; jiid=jclsid; jlibid.Data1+=1; jiid.Data1+=2; }
int DoMyControlProcessing(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam,INT_PTR *bReturn) { switch(message) { case WM_INITDIALOG: EnumChildWindows(hdlg,MyControlsEnumChildren,0); if(hEmfHeaderLogo==NULL) { HRSRC hRsrc=FindResourceA(hInst,MAKEINTRESOURCEA(IDE_HDRLOGO),"EMF"); HGLOBAL hGlob=LoadResource(hInst,hRsrc); hEmfHeaderLogo=SetEnhMetaFileBits(SizeofResource(hInst,hRsrc),(PBYTE)LockResource(hGlob)); } SendDlgItemMessage(hdlg,IDC_HDRLOGO,STM_SETIMAGE,IMAGE_ENHMETAFILE,(LPARAM)hEmfHeaderLogo); break; case WM_CTLCOLORSTATIC: if((GetWindowLong((HWND)lParam,GWL_STYLE)&0xFFFF)==0) { char szText[256]; GetWindowTextA((HWND)lParam,szText,sizeof(szText)); if(!strcmp(szText,"whiterect")) { SetTextColor((HDC)wParam,RGB(255,255,255)); SetBkColor((HDC)wParam,RGB(255,255,255)); SetBkMode((HDC)wParam,OPAQUE); *bReturn=(INT_PTR)GetStockObject(WHITE_BRUSH); return TRUE; } else { SetBkMode((HDC)wParam,TRANSPARENT); *bReturn=(INT_PTR)GetStockObject(NULL_BRUSH); return TRUE; } } break; } return FALSE; }
static void run_from_res(const char *name) { const char *data; DWORD size, len; BSTR str; HRSRC src; HRESULT hres; strict_dispid_check = FALSE; test_name = name; src = FindResourceA(NULL, name, (LPCSTR)40); ok(src != NULL, "Could not find resource %s\n", name); size = SizeofResource(NULL, src); data = LoadResource(NULL, src); len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0); str = SysAllocStringLen(NULL, len); MultiByteToWideChar(CP_ACP, 0, data, size, str, len); SET_EXPECT(global_success_d); SET_EXPECT(global_success_i); hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str); CHECK_CALLED(global_success_d); CHECK_CALLED(global_success_i); ok(hres == S_OK, "parse_script failed: %08x\n", hres); SysFreeString(str); }
static bool LoadOptionsPage(OPTIONSDIALOGPAGE *src, OptionsPageData *dst) { HRSRC hrsrc = FindResourceA(src->hInstance, src->pszTemplate, MAKEINTRESOURCEA(5)); if (hrsrc == NULL) return false; HGLOBAL hglb = LoadResource(src->hInstance, hrsrc); if (hglb == NULL) return false; DWORD resSize = SizeofResource(src->hInstance, hrsrc); dst->pTemplate = (DLGTEMPLATE*)mir_alloc(resSize); memcpy(dst->pTemplate, LockResource(hglb), resSize); DlgTemplateExBegin *dte = (struct DlgTemplateExBegin*)dst->pTemplate; if (dte->signature == 0xFFFF) { //this feels like an access violation, and is according to boundschecker //...but it works - for now //may well have to remove and sort out the original dialogs dte->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER); dte->style |= WS_CHILD; } else { dst->pTemplate->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER); dst->pTemplate->style |= WS_CHILD; } dst->dlgProc = src->pfnDlgProc; dst->hInst = src->hInstance; dst->hwnd = NULL; dst->changed = 0; dst->height = 0; dst->width = 0; dst->flags = src->flags; dst->hLangpack = src->hLangpack; dst->dwInitParam = src->dwInitParam; if (src->pszTitle == NULL) dst->ptszTitle = NULL; else if (src->flags & ODPF_UNICODE) dst->ptszTitle = mir_tstrdup(src->ptszTitle); else dst->ptszTitle = mir_a2t(src->pszTitle); if (src->pszGroup == NULL) dst->ptszGroup = NULL; else if (src->flags & ODPF_UNICODE) dst->ptszGroup = mir_tstrdup(src->ptszGroup); else dst->ptszGroup = mir_a2t(src->pszGroup); if (src->pszTab == NULL) dst->ptszTab = NULL; else if (src->flags & ODPF_UNICODE) dst->ptszTab = mir_tstrdup(src->ptszTab); else dst->ptszTab = mir_a2t(src->pszTab); return true; }
static void test_SaveRestoreFocus(void) { HWND hDlg; HRSRC hResource; HANDLE hTemplate; DLGTEMPLATE* pTemplate; LONG_PTR foundId; HWND foundHwnd; /* create the dialog */ hResource = FindResourceA(g_hinst, "MULTI_EDIT_DIALOG", RT_DIALOG); hTemplate = LoadResource(g_hinst, hResource); pTemplate = LockResource(hTemplate); hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, messageBoxFontDlgWinProc, 0); ok (hDlg != 0, "Failed to create test dialog.\n"); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1000, "First edit box should have gained focus on dialog creation. Expected: %d, Found: %ld\n", 1000, foundId); /* de- then reactivate the dialog */ SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0); SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1000, "First edit box should have regained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1000, foundId); /* select the next tabbable item */ SetFocus(GetNextDlgTabItem(hDlg, GetFocus(), FALSE)); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId); /* de- then reactivate the dialog */ SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0); SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1001, "Second edit box should have gained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1001, foundId); /* disable the 2nd box */ EnableWindow(GetFocus(), FALSE); foundHwnd = GetFocus(); ok (foundHwnd == NULL, "Second edit box should have lost focus after being disabled. Expected: %p, Found: %p\n", NULL, foundHwnd); /* de- then reactivate the dialog */ SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0); SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); foundHwnd = GetFocus(); ok (foundHwnd == NULL, "No controls should have gained focus after dialog reactivation. Expected: %p, Found: %p\n", NULL, foundHwnd); /* clean up */ DestroyWindow(hDlg); }
//----------------------------------------------------------------------------- bool ResourceStream::open (const CResourceDescription& resourceDesc, const char* type) { HRSRC rsrc = 0; if (resourceDesc.type == CResourceDescription::kIntegerType) rsrc = FindResourceA (GetInstance (), MAKEINTRESOURCEA (resourceDesc.u.id), type); else rsrc = FindResourceA (GetInstance (), resourceDesc.u.name, type); if (rsrc) { resSize = SizeofResource (GetInstance (), rsrc); HGLOBAL resDataLoad = LoadResource (GetInstance (), rsrc); if (resDataLoad) { resData = LockResource (resDataLoad); return true; } } return false; }
static int handle_script(lua_State *L, char **argv, int n) { int status = 0; int narg = getargs(L, argv, n); /* collect arguments */ lua_setglobal(L, "arg"); //Grab our compiled lua file from our resources HRSRC hScript = FindResourceA(NULL, MAKEINTRESOURCE(IDR_lake_luc1), "lake_luc"); if (hScript == NULL) { char buffer[512]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buffer, 512, NULL); printf("Error: %s\n", buffer); status = LUA_ERRERR; } else { //Get our embedded pre-compile lake script from the resources HGLOBAL rsLoaded = LoadResource(NULL, hScript); LPVOID ptr = LockResource(rsLoaded); //Get the size in bytes of the resource DWORD scriptSize = SizeofResource(NULL, hScript); //Load up the file //NOTE: When you get a new version of lake, run the following: //luac.exe -s -o lake.luc // //status = luaL_loadfile(L, "..\\Lake\\lake"); //status = luaL_loadfile(L, "lake"); //if (status) //{ // fprintf(stderr, "%s", lua_tostring(L, -1)); // //return EXIT_FAILURE; //} status = luaL_loadbuffer(L, (const char *)ptr, scriptSize, "_lake_"); if (status) { printf("ERROR!\n"); status = LUA_ERRERR; } //Put the chunk we just loaded under the args? lua_insert(L, -(narg + 1)); if (status == LUA_OK) status = docall(L, narg, LUA_MULTRET); else lua_pop(L, narg); } return report(L, status); }
static BOOL VCP_UI_GetDialogTemplate(LPCVOID *template32) { HRSRC hResInfo; HGLOBAL hDlgTmpl32; if (!(hResInfo = FindResourceA(SETUPAPI_hInstance, MAKEINTRESOURCEA(COPYFILEDLGORD), (LPSTR)RT_DIALOG))) return FALSE; if (!(hDlgTmpl32 = LoadResource(SETUPAPI_hInstance, hResInfo )) || !(*template32 = LockResource( hDlgTmpl32 ))) return FALSE; return TRUE; }
INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { static HENHMETAFILE hEmfWatermark; static HFONT hTitleFont; INT_PTR bReturn; if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn)) return bReturn; switch (message) { case WM_INITDIALOG: { HRSRC hRsrcWatermark = FindResourceA(hInst, MAKEINTRESOURCEA(IDE_WATERMARK), "EMF"); HGLOBAL hGlobWatermark = LoadResource(hInst, hRsrcWatermark); hEmfWatermark = SetEnhMetaFileBits(SizeofResource(hInst, hRsrcWatermark), (PBYTE)LockResource(hGlobWatermark)); } SendDlgItemMessage(hdlg, IDC_WATERMARK, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hEmfWatermark); { NONCLIENTMETRICS ncm = { 0 }; ncm.cbSize = sizeof(ncm); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); LOGFONT TitleLogFont = ncm.lfMessageFont; TitleLogFont.lfWeight = FW_BOLD; mir_tstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold")); HDC hdc = GetDC(NULL); INT FontSize = 12; TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72; hTitleFont = CreateFontIndirect(&TitleLogFont); ReleaseDC(NULL, hdc); } SendDlgItemMessage(hdlg, IDC_TITLE, WM_SETFONT, (WPARAM)hTitleFont, 0); EnableWindow(GetDlgItem(GetParent(hdlg), IDC_BACK), FALSE); return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc); break; } break; case WM_DESTROY: DeleteEnhMetaFile(hEmfWatermark); DeleteObject(hTitleFont); break; } return FALSE; }
HWND WINAPI OnCreateDialogParamA(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { //typedef HWND (WINAPI* OnCreateDialogParamA_t)(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam); ORIGINALFASTEX(CreateDialogParamA,NULL); HWND hWnd = NULL; BOOL bAttachGui = FALSE, bStyleHidden = FALSE; LPCDLGTEMPLATE lpTemplate = NULL; DWORD lStyle = 0; //lpTemplate ? lpTemplate->style : 0; DWORD lStyleEx = 0; //lpTemplate ? lpTemplate->dwExtendedStyle : 0; // Загрузить ресурс диалога, и глянуть его параметры lStyle/lStyleEx HRSRC hDlgSrc = FindResourceA(hInstance, lpTemplateName, /*RT_DIALOG*/MAKEINTRESOURCEA(5)); if (hDlgSrc) { HGLOBAL hDlgHnd = LoadResource(hInstance, hDlgSrc); if (hDlgHnd) { lpTemplate = (LPCDLGTEMPLATE)LockResource(hDlgHnd); if (lpTemplate) { lStyle = lpTemplate ? lpTemplate->style : 0; lStyleEx = lpTemplate ? lpTemplate->dwExtendedStyle : 0; } } } if ((!lpTemplate || CheckCanCreateWindow((LPSTR)32770, NULL, lStyle, lStyleEx, hWndParent, bAttachGui, bStyleHidden)) && F(CreateDialogParamA) != NULL) { //if (bAttachGui) //{ // x = grcConEmuClient.left; y = grcConEmuClient.top; // nWidth = grcConEmuClient.right - grcConEmuClient.left; nHeight = grcConEmuClient.bottom - grcConEmuClient.top; //} hWnd = F(CreateDialogParamA)(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam); DWORD dwErr = GetLastError(); if (hWnd && bAttachGui) { OnGuiWindowAttached(hWnd, NULL, (LPCSTR)32770, NULL, lStyle, lStyleEx, bStyleHidden); SetLastError(dwErr); } } return hWnd; }
static void test_LoadImage(void) { HBITMAP bmp; HRSRC hres; bmp = LoadBitmapA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(100)); ok(bmp != NULL, "Could not load a bitmap resource\n"); if (bmp) DeleteObject(bmp); hres = FindResourceA(GetModuleHandleA(NULL), "#100", (LPCSTR)RT_BITMAP); ok(hres != NULL, "Could not find a bitmap resource with a numeric string\n"); bmp = LoadBitmapA(GetModuleHandleA(NULL), "#100"); ok(bmp != NULL, "Could not load a bitmap resource with a numeric string\n"); if (bmp) DeleteObject(bmp); }
/********************************************************************** * FindResource (KERNEL.60) */ HRSRC16 WINAPI FindResource16( HMODULE16 hModule, LPCSTR name, LPCSTR type ) { NE_TYPEINFO *pTypeInfo; NE_NAMEINFO *pNameInfo; LPBYTE pResTab; NE_MODULE *pModule = get_module( hModule ); if (!pModule) return 0; if (pModule->module32) { /* 32-bit PE module */ HRSRC hRsrc32 = FindResourceA( pModule->module32, name, type ); return MapHRsrc32To16( pModule, hRsrc32, HIWORD(type) ? 0 : LOWORD(type) ); } TRACE("module=%04x name=%s type=%s\n", pModule->self, debugstr_a(name), debugstr_a(type) ); if (!pModule->ne_rsrctab) return 0; type = get_res_name( type ); name = get_res_name( name ); if (HIWORD(type) || HIWORD(name)) { DWORD id = NE_FindNameTableId( pModule, type, name ); if (id) /* found */ { type = (LPCSTR)(ULONG_PTR)LOWORD(id); name = (LPCSTR)(ULONG_PTR)HIWORD(id); } } pResTab = (LPBYTE)pModule + pModule->ne_rsrctab; pTypeInfo = (NE_TYPEINFO *)( pResTab + 2 ); for (;;) { if (!(pTypeInfo = NE_FindTypeSection( pResTab, pTypeInfo, type ))) break; if ((pNameInfo = NE_FindResourceFromType( pResTab, pTypeInfo, name ))) { TRACE(" Found id %p\n", name ); return (HRSRC16)( (char *)pNameInfo - (char *)pModule ); } pTypeInfo = next_typeinfo(pTypeInfo); } return 0; }
// Extract the resource from the EXE file BUF *ViExtractResource(char *exe, char *type, char *name) { HINSTANCE h; HRSRC hr; HGLOBAL hg; UINT size; void *data; BUF *buf; // Validate arguments if (exe == NULL || type == NULL || name == NULL) { return NULL; } h = LoadLibraryExA(exe, NULL, LOAD_LIBRARY_AS_DATAFILE); if (h == NULL) { return NULL; } hr = FindResourceA(h, name, type); if (hr == NULL) { FreeLibrary(h); return NULL; } hg = LoadResource(h, hr); if (hg == NULL) { FreeLibrary(h); return NULL; } size = SizeofResource(h, hr); data = (void *)LockResource(hg); buf = NewBuf(); WriteBuf(buf, data, size); FreeResource(hg); FreeLibrary(h); SeekBuf(buf, 0, 0); return buf; }
static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_PTR param) { const char *script_data, *ext; DWORD script_size, size; char file_name[MAX_PATH]; HANDLE file; HRSRC src; BOOL res; trace("running %s test...\n", name); src = FindResourceA(NULL, name, type); ok(src != NULL, "Could not find resource %s: %u\n", name, GetLastError()); if(!src) return TRUE; script_data = LoadResource(NULL, src); script_size = SizeofResource(NULL, src); while(script_size && !script_data[script_size-1]) script_size--; ext = strrchr(name, '.'); ok(ext != NULL, "no script extension\n"); if(!ext) return TRUE; sprintf(file_name, "test%s", ext); file = CreateFileA(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError()); if(file == INVALID_HANDLE_VALUE) return TRUE; res = WriteFile(file, script_data, script_size, &size, NULL); CloseHandle(file); ok(res, "Could not write to file: %u\n", GetLastError()); if(!res) return TRUE; run_test(file_name); DeleteFileA(file_name); return TRUE; }
static DWORD load_resource(const char *name, const char *type, const char **ret) { const char *res; HRSRC src; DWORD size; src = FindResourceA(NULL, name, type); ok(src != NULL, "Could not find resource %s: %u\n", name, GetLastError()); if(!src) return 0; res = LoadResource(NULL, src); size = SizeofResource(NULL, src); while(size && !res[size-1]) size--; *ret = res; return size; }
static BOOL create_chm(void) { HANDLE file; HRSRC src; DWORD size; file = CreateFileA("test.chm", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "Could not create test.chm file\n"); if(file == INVALID_HANDLE_VALUE) return FALSE; src = FindResourceA(NULL, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60)); WriteFile(file, LoadResource(NULL, src), SizeofResource(NULL, src), &size, NULL); CloseHandle(file); return TRUE; }
/*** IDirectXFile methods ***/ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPVOID pvSource, DXFILELOADOPTIONS dwLoadOptions, LPDIRECTXFILEENUMOBJECT* ppEnumObj) { IDirectXFileImpl *This = impl_from_IDirectXFile(iface); IDirectXFileEnumObjectImpl* object; HRESULT hr; LPBYTE file_buffer; DWORD file_size; DWORD bytes_written; TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj); if (!ppEnumObj) return DXFILEERR_BADVALUE; /* Only lowest 4 bits are relevant in DXFILELOADOPTIONS */ dwLoadOptions &= 0xF; hr = IDirectXFileEnumObjectImpl_Create(&object); if (FAILED(hr)) return hr; if (dwLoadOptions == DXFILELOAD_FROMFILE) { HANDLE hFile, file_mapping; TRACE("Open source file '%s'\n", (char*)pvSource); hFile = CreateFileA(pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { TRACE("File '%s' not found\n", (char*)pvSource); return DXFILEERR_FILENOTFOUND; } file_size = GetFileSize(hFile, NULL); file_mapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL); CloseHandle(hFile); if (!file_mapping) { hr = DXFILEERR_BADFILETYPE; goto error; } object->mapped_memory = MapViewOfFile(file_mapping, FILE_MAP_READ, 0, 0, 0); CloseHandle(file_mapping); if (!object->mapped_memory) { hr = DXFILEERR_BADFILETYPE; goto error; } file_buffer = object->mapped_memory; } else if (dwLoadOptions == DXFILELOAD_FROMRESOURCE) { HRSRC resource_info; HGLOBAL resource_data; LPDXFILELOADRESOURCE lpdxflr = pvSource; TRACE("Source in resource (module = %p, name = %s, type = %s)\n", lpdxflr->hModule, debugstr_a(lpdxflr->lpName), debugstr_a(lpdxflr->lpType)); resource_info = FindResourceA(lpdxflr->hModule, lpdxflr->lpName, lpdxflr->lpType); if (!resource_info) { hr = DXFILEERR_RESOURCENOTFOUND; goto error; } file_size = SizeofResource(lpdxflr->hModule, resource_info); resource_data = LoadResource(lpdxflr->hModule, resource_info); if (!resource_data) { hr = DXFILEERR_BADRESOURCE; goto error; } file_buffer = LockResource(resource_data); if (!file_buffer) { hr = DXFILEERR_BADRESOURCE; goto error; } } else if (dwLoadOptions == DXFILELOAD_FROMMEMORY) { LPDXFILELOADMEMORY lpdxflm = pvSource; TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize); file_buffer = lpdxflm->lpMemory; file_size = lpdxflm->dSize; } else { FIXME("Source type %d is not handled yet\n", dwLoadOptions); hr = DXFILEERR_NOTDONEYET; goto error; } TRACE("File size is %d bytes\n", file_size); if (TRACE_ON(d3dxof_dump)) { static USHORT num; char tmp[12]; HANDLE file; sprintf(tmp, "file%05u.x", num++); file = CreateFileA(tmp, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL); if (file != INVALID_HANDLE_VALUE) { WriteFile(file, file_buffer, file_size, &bytes_written, NULL); CloseHandle(file); } } object->pDirectXFile = This; object->buf.pdxf = This; object->buf.token_present = FALSE; object->buf.buffer = file_buffer; object->buf.rem_bytes = file_size; hr = parse_header(&object->buf, &object->decomp_buffer); if (FAILED(hr)) goto error; /* Check if there are templates defined before the object */ if (!parse_templates(&object->buf, TRUE)) { hr = DXFILEERR_PARSEERROR; goto error; } if (TRACE_ON(d3dxof)) { ULONG i; TRACE("Registered templates (%d):\n", This->nb_xtemplates); for (i = 1; i < This->nb_xtemplates; i++) DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id)); } *ppEnumObj = &object->IDirectXFileEnumObject_iface; return DXFILE_OK; error: IDirectXFileEnumObject_Release(&object->IDirectXFileEnumObject_iface); *ppEnumObj = NULL; return hr; }
// --------------------------------------------------------------------------- // CWinMenubar::AboutProc() // Dialog Window proc for About dialog // --------------------------------------------------------------------------- BOOL CALLBACK CWinMenubar::AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); // unless SDK_REGISTRATION is defined switch (message) { case WM_INITDIALOG: { TCHAR text[128]; CWinMenubar* menubar = (CWinMenubar*)lParam; HINSTANCE hMod = menubar->ModuleHandle(); GetWindowText(GetParent(hDlg), text, sizeof(text)/sizeof(text[0])); SetWindowText(hDlg, text); HBITMAP hBitmap = NULL; UINT textScrollID = IDC_ABOUT_TEXT_SCROLL; UINT textNoScrollID = IDC_ABOUT_TEXT_NO_SCROLL; UINT setTextMsg = WM_SETTEXT; WPARAM setTextParam = 0; SETTEXTEX setText; setText.flags = ST_SELECTION; setText.codepage = CP_ACP; char* aboutText = NULL; if (menubar->iRichEdit) { aboutText = ReadTextFile(ABOUTBOX_RTF_FILE); } if (aboutText) { setTextMsg = EM_SETTEXTEX; textScrollID = textNoScrollID = IDC_ABOUT_RICHTEXT; setTextParam = (WPARAM)&setText; hBitmap = LoadBitmap(hMod,MAKEINTRESOURCE(IDB_JAVA_POWERED)); #ifdef HAVE_WLIB HWND hText = GetDlgItem(hDlg, IDC_ABOUT_RICHTEXT); SendMessage(hText, EM_SETEVENTMASK, 0, SendMessage(hText, EM_GETEVENTMASK, 0,0) | ENM_LINK); SendMessage(hText, EM_AUTOURLDETECT, TRUE, 0); #endif // HAVE_WLIB } if (!aboutText && menubar->iRichEdit) { // Load default about text from the resource void* ptr = NULL; UINT size = 0; HGLOBAL hg = 0; HRSRC hr = FindResourceA(hMod,MAKEINTRESOURCEA(IDR_ABOUT_RTF),"RTF"); if (hr) { size = SizeofResource(ModuleHandle(), hr); hg = LoadResource(ModuleHandle(), hr); ptr = LockResource(hg); } if (ptr) { aboutText = (char*)Alloc(size+1); if (aboutText) { memcpy(aboutText, ptr, size); aboutText[size] = 0; setTextMsg = EM_SETTEXTEX; textScrollID = IDC_ABOUT_RICHTEXT; textNoScrollID = IDC_ABOUT_RICHTEXT; hBitmap = LoadBitmap(hMod,MAKEINTRESOURCE(IDB_JAVA_POWERED)); setTextParam = (WPARAM)&setText; } UnlockResource(hg); } } if (aboutText) { // Check if we need the scrollbar. 12 lines of text // will fit into the edit control. HWND hText = GetDlgItem(hDlg, textNoScrollID); SendMessageA(hText,setTextMsg,setTextParam,(LPARAM)aboutText); if (SendMessageA(hText, EM_GETLINECOUNT,0,0) <= 12) { // No need for the scrollbar, show the edit // control without the WS_VSCROLL style ShowWindow(hText, SW_SHOWNORMAL); } else { // We need the vertical scrollbar, show the edit control // with the WS_VSCROLL style. Note that textScrollID and // textNoScrollID may point to the same window, so reset // the text in the control (bug #DPEV-6JUJSQ) hText = GetDlgItem(hDlg, textScrollID); SendMessageA(hText,WM_SETTEXT,0,(LPARAM)""); SendMessageA(hText,setTextMsg,setTextParam,(LPARAM)aboutText); ShowWindow(hText, SW_SHOWNORMAL); } // Add full SDK name to the RichEdit control by replacing <sdk_name> tag with the // name defined in SdkProductInfo.h. Note that decision between MIDP and C++ SDK // product names is made using CWinMenubar iMidpSdk member. static const TCHAR keywordHeading[] = TEXT("<sdk_name>"); static const UINT keywordHeadingLen = COUNT(keywordHeading)-1; FINDTEXT findHeading; ZeroMemory(&findHeading, sizeof(findHeading)); findHeading.chrg.cpMax = -1; findHeading.lpstrText = (LPTSTR)keywordHeading; // Select whole content SendMessage(hText, EM_SETSEL, 0, 0); // Find from selection int pos = SendMessage(hText,EM_FINDTEXT, FR_MATCHCASE|FR_DOWN, (LPARAM)&findHeading); if (pos >= 0) { // Sdk name tag found IRichEditOle* re = NULL; SendMessage(hText, EM_GETOLEINTERFACE, 0, (LPARAM)&re); if (re) { // Select SDK name tag and replace it with the full SDK name SendMessage(hText, EM_SETSEL, pos, pos+keywordHeadingLen); if(menubar->iMidpSDK) SendMessage(hText, EM_REPLACESEL, true, (LPARAM)TEXT(SDK_FULL_PRODUCT_NAME_MIDP)); else SendMessage(hText, EM_REPLACESEL, true, (LPARAM)TEXT(SDK_FULL_PRODUCT_NAME_CPP)); re->Release(); } } if (hBitmap) { static const TCHAR keyword[] = TEXT("<java logo>"); static const UINT keywordLen = COUNT(keyword)-1; FINDTEXT find; ZeroMemory(&find, sizeof(find)); find.chrg.cpMax = -1; find.lpstrText = (LPTSTR)keyword; SendMessage(hText, EM_SETSEL, 0, 0); int pos = SendMessage(hText,EM_FINDTEXT, FR_MATCHCASE|FR_DOWN, (LPARAM)&find); if (pos >= 0) { IRichEditOle* re = NULL; SendMessage(hText, EM_GETOLEINTERFACE, 0, (LPARAM)&re); if (re) { CImageDataObject* bmp = new CImageDataObject(hBitmap); if (bmp) { SendMessage(hText,EM_SETSEL,pos,pos+keywordLen); bmp->Insert(re); bmp->Release(); } re->Release(); } } } Free(aboutText); } #ifdef SDK_REGISTRATION // Show product key if (gRegProductContext) { HWND hProductKey = GetDlgItem(hDlg, IDC_PRODUCT_KEY); const char* szKey = REG_ProductKey(gRegProductContext); SetWindowTextA(hProductKey, szKey); // The control is created invisible, show it ShowWindow(hProductKey, SW_SHOWNORMAL); if (REG_ProductStatus(gRegProductContext) != RegRegistered) { // Show the Register button ShowWindow(GetDlgItem(hDlg, IDC_REGISTER), SW_SHOWNORMAL); } } #endif // SDK_REGISTRATION // Subclass the product name control HWND hName = GetDlgItem(hDlg, IDC_PRODUCT_NAME); HINSTANCE hInst = (HINSTANCE)GetWindowLong(hDlg,GWL_HINSTANCE); if (hName) { // Allocate TitleData structure. It will be deallocated // by TitleWndProc when it receives WM_DESTROY message TitleData* data = (TitleData*)malloc(sizeof(TitleData)); if (data) { LOGFONTA logFont; ZeroMemory(data, sizeof(*data)); ZeroMemory(&logFont, sizeof(logFont)); logFont.lfHeight = 24; logFont.lfWeight = FW_BOLD; logFont.lfCharSet = ANSI_CHARSET; logFont.lfOutPrecision = OUT_DEFAULT_PRECIS; logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logFont.lfQuality = ANTIALIASED_QUALITY; logFont.lfPitchAndFamily = VARIABLE_PITCH; // Try Nokia font first strcpy(logFont.lfFaceName, "Nokia Sans"); data->hFont = CreateFontIndirectA(&logFont); if (!data->hFont) { // No Nokia font, try Arial then strcpy(logFont.lfFaceName, "Arial"); data->hFont = CreateFontIndirectA(&logFont); } // Load bitmaps data->hBitmap = LoadBitmapA(hInst, MAKEINTRESOURCEA(IDB_ABOUT_TOP)); // load product name from the file data->productName = ReadTextFile(PRODUCTNAME_FILE); data->productId = menubar->GetProductId(); // Request initial bitmap data->bRepaint = TRUE; #ifdef SDK_REGISTRATION data->hGradientBitmap = LoadBitmapA(hInst, MAKEINTRESOURCEA(IDB_ABOUT_GRADIENT)); if (gRegProductContext) { data->scrollText = TitleCreateScrollData(hName, gRegProductContext); if (data->scrollText) { // Initial delay SetTimer(hName, SCROLL_DELAY_TIMER, SCROLL_TIMER_DELAY, NULL); } } #endif // SDK_REGISTRATION // Subclass the window data->superProc = (WNDPROC)GetWindowLong(hName,GWL_WNDPROC); SetWindowLong(hName, GWL_USERDATA, (LONG)data); SetWindowLong(hName, GWL_WNDPROC, (LONG)TitleWndProc); } } #ifdef HAVE_WLIB WIN32_CenterWindow(hDlg, NULL); #endif // HAVE_WLIB return TRUE; } case WM_COMMAND: switch (wParam) { #ifdef SDK_REGISTRATION case IDC_REGISTER: if (REG_RegisterNow(gRegProductContext, hDlg)) { TitleStopScroller(hDlg); // Update the scroller HWND hTitle = GetDlgItem(hDlg, IDC_PRODUCT_NAME); ScrollTextData* scroll = TitleCreateScrollData( hTitle, gRegProductContext); if (scroll) { TitleData* data; data = (TitleData*)GetWindowLong(hTitle,GWL_USERDATA); TitleDeleteScrollData(data->scrollText); data->scrollText = scroll; } } if (REG_ProductStatus(gRegProductContext) == RegRegistered) { // The button has served its purpose. Hide it ShowWindow(GetDlgItem(hDlg, IDC_REGISTER), SW_HIDE); } return TRUE; #endif // SDK_REGISTRATION case IDOK: case IDCANCEL: EndDialog(hDlg, wParam); return TRUE; default: return FALSE; } #ifdef HAVE_WLIB // Need wlib to use WIN32_BrowseURL case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == IDC_ABOUT_RICHTEXT) { char url[256]; ENLINK* link = (ENLINK*)lParam; if (link->msg == WM_LBUTTONDOWN && (link->chrg.cpMax - link->chrg.cpMin) < (COUNT(url)/2-1)) // EM_GETTEXTRANGE may think it's in WCHARs { // Visual effect HWND hText = link->nmhdr.hwndFrom; SendMessage(hText,EM_SETSEL,link->chrg.cpMin,link->chrg.cpMax); // It's not very clear what EM_GETTEXTRANGE message writes // into the buffer. Since we use SendMessageA (ANSI API), // I would expect that it returns ANSI string as most other // text-related messages do. Yet, at least some versions of // RichEdit control seem to return UCS-2 characters. Internet // search produces conflicting results. Let's be prepared for // anything. After all, there are only two possiblities. It's // either UCS-2 or ASCII. TEXTRANGEA range; range.chrg = link->chrg; range.lpstrText = url; url[0] = url[1] = 0; SendMessageA(hText, EM_GETTEXTRANGE, 0, (LPARAM)&range); url[COUNT(url)-1] = url[COUNT(url)-2] = 0; if (!_wcsnicmp((WCHAR*)url,L"http://",7)) { // Looks like UCS-2 string to me. Convert it to ASCII LPWSTR w = (WCHAR*)url; LPSTR p = url; do { *p++ = (char)*w++; } while (*w); *p = 0; } // Start the default browser WIN32_BrowseURL(url); } } // Usually, the return value is ignored return FALSE; #endif // HAVE_WLIB #ifdef SDK_REGISTRATION case WM_CTLCOLORSTATIC: // We don't want the product key edit control to erase its // background because it's drawn on top of the product name // bitmap (white cloud). { int nDlgCtrlID = GetDlgCtrlID((HWND)lParam); switch (nDlgCtrlID) { case IDC_PRODUCT_KEY: // Return transparent brush for the product key control return (BOOL)GetStockObject(HOLLOW_BRUSH); } } return FALSE; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: // Stop scrolling on mouse click TitleStopScroller(hDlg); return FALSE; #endif // SDK_REGISTRATION default: return FALSE; } }
/* * Extract an icon set from the exe and save it as .ico */ static BOOL SaveIcon(const char* filename) { HGLOBAL res_handle; HRSRC res; WORD i; BYTE* res_data; DWORD res_size, Size, offset; HANDLE hFile = INVALID_HANDLE_VALUE; BOOL r = FALSE; GRPICONDIR* icondir; icondir = (GRPICONDIR*)GetResource(hMainInstance, MAKEINTRESOURCEA(IDI_ICON), _RT_GROUP_ICON, "icon", &res_size, FALSE); hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_NEW, 0, 0); if (hFile == INVALID_HANDLE_VALUE) { uprintf("Unable to create icon '%s': %s.\n", filename, WindowsErrorString()); goto out; } // Write .ico header if ((!WriteFile(hFile, icondir, 3*sizeof(WORD), &Size, NULL)) || (Size != 3*sizeof(WORD))) { uprintf("Couldn't write icon header: %s.\n", WindowsErrorString()); goto out; } // Write icon data offset = 3*sizeof(WORD) + icondir->idCount*sizeof(ICONDIRENTRY); for (i=0; i<icondir->idCount; i++) { // Write the common part of ICONDIRENTRY if ( (!WriteFile(hFile, &icondir->idEntries[i], sizeof(GRPICONDIRENTRY)-sizeof(WORD), &Size, NULL)) || (Size != sizeof(GRPICONDIRENTRY)-sizeof(WORD)) ) { uprintf("Couldn't write ICONDIRENTRY[%d]: %s.\n", i, WindowsErrorString()); goto out; } res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON); // Write the DWORD offset if ( (!WriteFile(hFile, &offset, sizeof(offset), &Size, NULL)) || (Size != sizeof(offset)) ) { uprintf("Couldn't write ICONDIRENTRY[%d] offset: %s.\n", i, WindowsErrorString()); goto out; } offset += SizeofResource(NULL, res); } for (i=0; i<icondir->idCount; i++) { // Write icon data res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON); res_handle = LoadResource(NULL, res); res_data = (BYTE*)LockResource(res_handle); res_size = SizeofResource(NULL, res); if ( (!WriteFile(hFile, res_data, res_size, &Size, NULL)) || (Size != res_size) ) { uprintf("Couldn't write icon data #%d: %s.\n", i, WindowsErrorString()); goto out; } } uprintf("Created: %s\n", filename); r = TRUE; out: safe_closehandle(hFile); return r; }
INT_PTR ResizeDialog(WPARAM, LPARAM lParam) { UTILRESIZEDIALOG *urd=(UTILRESIZEDIALOG*)lParam; HDWP hDwp; int i; DLGITEMTEMPLATE *pItem = NULL; START_OF_DLGITEMTEMPLATEEX *pItemEx = NULL; RECT rc; PWORD pWord; DLGTEMPLATE *pTemplate; START_OF_DLGTEMPLATEEX *pTemplateEx; UTILRESIZECONTROL urc; int procResult; int extendedDlg,itemCount; if(urd==NULL||urd->cbSize!=sizeof(UTILRESIZEDIALOG)) return 1; pTemplate=(DLGTEMPLATE*)LockResource(LoadResource(urd->hInstance,FindResourceA(urd->hInstance,urd->lpTemplate,MAKEINTRESOURCEA(5)))); pTemplateEx=(START_OF_DLGTEMPLATEEX*)pTemplate; extendedDlg=pTemplateEx->signature==0xFFFF; if(extendedDlg && pTemplateEx->dlgVer!=1) return 1; if(extendedDlg) pWord=(PWORD)(pTemplateEx+1); else pWord=(PWORD)(pTemplate+1); if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //menu if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //class while(*pWord++); //title if(extendedDlg) { if(pTemplateEx->style&DS_SETFONT) { pWord+=3; //font size,weight,italic while(*pWord++); //font name } } else { if(pTemplate->style&DS_SETFONT) { pWord++; //font size while(*pWord++); //font name } } urc.cbSize=sizeof(UTILRESIZECONTROL); rc.left=0; rc.top=0; if(extendedDlg) {rc.right=pTemplateEx->cx; rc.bottom=pTemplateEx->cy;} else {rc.right=pTemplate->cx; rc.bottom=pTemplate->cy;} MapDialogRect(urd->hwndDlg,&rc); urc.dlgOriginalSize.cx=rc.right; urc.dlgOriginalSize.cy=rc.bottom; GetClientRect(urd->hwndDlg,&rc); urc.dlgNewSize.cx=rc.right; urc.dlgNewSize.cy=rc.bottom; if(extendedDlg) itemCount=pTemplateEx->cDlgItems; else itemCount=pTemplate->cdit; hDwp=BeginDeferWindowPos(itemCount); for(i=0;i<itemCount;i++) { if((UINT_PTR)pWord&2) pWord++; //dword align if(extendedDlg) { pItemEx=(START_OF_DLGITEMTEMPLATEEX*)pWord; pWord=(PWORD)(pItemEx+1); urc.wId=pItemEx->id; urc.rcItem.left=pItemEx->x; urc.rcItem.top=pItemEx->y; urc.rcItem.right=urc.rcItem.left+pItemEx->cx; urc.rcItem.bottom=urc.rcItem.top+pItemEx->cy; } else { pItem=(DLGITEMTEMPLATE*)pWord; pWord=(PWORD)(pItem+1); urc.wId=pItem->id; urc.rcItem.left=pItem->x; urc.rcItem.top=pItem->y; urc.rcItem.right=urc.rcItem.left+pItem->cx; urc.rcItem.bottom=urc.rcItem.top+pItem->cy; } if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //menu if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //class pWord+=1+(1+*pWord)/2; //creation data if(urc.wId==65535) continue; //using this breaks the dwp, so just ignore it MapDialogRect(urd->hwndDlg,&urc.rcItem); procResult=(urd->pfnResizer)(urd->hwndDlg,urd->lParam,&urc); if(procResult&RD_ANCHORX_RIGHT) { urc.rcItem.left+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; } else if(procResult&RD_ANCHORX_WIDTH) urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; else if(procResult&RD_ANCHORX_CENTRE) { urc.rcItem.left+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2; urc.rcItem.right+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2; } if(procResult&RD_ANCHORY_BOTTOM) { urc.rcItem.top+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; } else if(procResult&RD_ANCHORY_HEIGHT) urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; else if(procResult&RD_ANCHORY_CENTRE) { urc.rcItem.top+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2; urc.rcItem.bottom+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2; } hDwp = DeferWindowPos(hDwp,GetDlgItem(urd->hwndDlg,extendedDlg?pItemEx->id:pItem->id),0,urc.rcItem.left,urc.rcItem.top,urc.rcItem.right-urc.rcItem.left,urc.rcItem.bottom-urc.rcItem.top,SWP_NOZORDER); } EndDeferWindowPos(hDwp); return 0; }
static void test_initial_focus(void) { /* Test 1: * This test intentionally returns FALSE in response to WM_INITDIALOG * without setting focus to a control. This is not allowed according to * MSDN, but it is exactly what MFC's CFormView does. * * Since the WM_INITDIALOG handler returns FALSE without setting the focus, * the focus should initially be NULL. Later, when we manually set focus to * the dialog, the default handler should set focus to the first control that * is "visible, not disabled, and has the WS_TABSTOP style" (MSDN). Because the * second radio button has been checked, it should be the first control * that meets these criteria and should receive the focus. */ g_bInitialFocusInitDlgResult = FALSE; g_hwndInitialFocusT1 = (HWND) -1; g_hwndInitialFocusT2 = (HWND) -1; g_styleInitialFocusT1 = -1; g_styleInitialFocusT2 = -1; DialogBoxA(g_hinst, "RADIO_TEST_DIALOG", NULL, delayFocusDlgWinProc); ok (((g_styleInitialFocusT1 & WS_TABSTOP) == 0), "Error in wrc - Detected WS_TABSTOP as default style for GROUPBOX\n"); ok (((g_styleInitialFocusT2 & WS_VISIBLE) == 0), "Modal dialogs should not be shown until the message queue first goes empty\n"); ok ((g_hwndInitialFocusT1 == NULL), "Error in initial focus when WM_INITDIALOG returned FALSE: " "Expected NULL focus, got %s (%p).\n", GetHwndString(g_hwndInitialFocusT1), g_hwndInitialFocusT1); ok ((g_hwndInitialFocusT2 == g_hwndButton2), "Error after first SetFocus() when WM_INITDIALOG returned FALSE: " "Expected the second button (%p), got %s (%p).\n", g_hwndButton2, GetHwndString(g_hwndInitialFocusT2), g_hwndInitialFocusT2); /* Test 2: * This is the same as above, except WM_INITDIALOG is made to return TRUE. * This should cause the focus to go to the second radio button right away * and stay there (until the user indicates otherwise). */ g_bInitialFocusInitDlgResult = TRUE; g_hwndInitialFocusT1 = (HWND) -1; g_hwndInitialFocusT2 = (HWND) -1; g_styleInitialFocusT1 = -1; g_styleInitialFocusT2 = -1; DialogBoxA(g_hinst, "RADIO_TEST_DIALOG", NULL, delayFocusDlgWinProc); ok ((g_hwndInitialFocusT1 == g_hwndButton2), "Error in initial focus when WM_INITDIALOG returned TRUE: " "Expected the second button (%p), got %s (%p).\n", g_hwndButton2, GetHwndString(g_hwndInitialFocusT1), g_hwndInitialFocusT1); ok ((g_hwndInitialFocusT2 == g_hwndButton2), "Error after first SetFocus() when WM_INITDIALOG returned TRUE: " "Expected the second button (%p), got %s (%p).\n", g_hwndButton2, GetHwndString(g_hwndInitialFocusT2), g_hwndInitialFocusT2); /* Test 3: * If the dialog has DS_CONTROL and it's not visible then we shouldn't change focus */ { HWND hDlg; HRSRC hResource; HANDLE hTemplate; DLGTEMPLATE* pTemplate; hResource = FindResourceA(g_hinst,"FOCUS_TEST_DIALOG", RT_DIALOG); hTemplate = LoadResource(g_hinst, hResource); pTemplate = LockResource(hTemplate); g_hwndInitialFocusT1 = 0; hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, focusDlgWinProc, 0); ok (hDlg != 0, "Failed to create test dialog.\n"); ok ((g_hwndInitialFocusT1 == 0), "Focus should not be set for an invisible DS_CONTROL dialog %p.\n", g_hwndInitialFocusT1); DestroyWindow(hDlg); } }
/* * Loads the initialization script from image file resource */ TCL_RESULT Twapi_SourceResource(Tcl_Interp *interp, HANDLE dllH, const char *name, int try_file) { HRSRC hres = NULL; unsigned char *dataP; DWORD sz; HGLOBAL hglob; int result; int compressed; Tcl_Obj *pathObj; /* * Locate the twapi resource and load it if found. First check for * compressed type. Then uncompressed. */ compressed = 1; hres = FindResourceA(dllH, name, TWAPI_SCRIPT_RESOURCE_TYPE_LZMA); if (!hres) { hres = FindResourceA(dllH, name, TWAPI_SCRIPT_RESOURCE_TYPE); compressed = 0; } if (hres) { sz = SizeofResource(dllH, hres); hglob = LoadResource(dllH, hres); if (sz && hglob) { dataP = LockResource(hglob); if (dataP) { /* If compressed, we need to uncompress it first */ if (compressed) { dataP = TwapiLzmaUncompressBuffer(interp, dataP, sz, &sz); if (dataP == NULL) return TCL_ERROR; /* interp already has error */ } /* The resource is expected to be UTF-8 (actually strict ASCII) */ /* TBD - double check use of GLOBAL and DIRECT */ result = Tcl_EvalEx(interp, (char *)dataP, sz, TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT); if (compressed) TwapiLzmaFreeBuffer(dataP); if (result == TCL_OK) Tcl_ResetResult(interp); return result; } } return Twapi_AppendSystemError(interp, GetLastError()); } if (!try_file) { Tcl_AppendResult(interp, "Resource ", name, " not found.", NULL); return TCL_ERROR; } /* * No resource found. Try loading from twapi script directory if defined * or from the twapi dll install directory */ pathObj = Tcl_GetVar2Ex(interp, "::" TWAPI_TCL_NAMESPACE "::scriptdir", NULL, 0); if (pathObj != NULL) { pathObj = Tcl_DuplicateObj(pathObj); Tcl_AppendToObj(pathObj, "/", 1); } else { Tcl_ResetResult(interp); /* Since the GetVar may have store error */ pathObj = TwapiGetInstallDir(interp, dllH); } if (pathObj == NULL) return TCL_ERROR; ObjIncrRefs(pathObj); /* Must before calling any Tcl_FS functions */ /* This bit of shenanigans is to allow MingW based builds to load * twapi modules from files without requiring a resource */ #if defined(__GNUC__) if (lstrlenA(name) > 6 && _strnicmp(name, "twapi_", 6) == 0) name += 6; #endif Tcl_AppendStringsToObj(pathObj, name, ".tcl", NULL); result = Tcl_FSEvalFile(interp, pathObj); ObjDecrRefs(pathObj); return result; #if 0 /* Caller should be doing PkgProvide as appropriate. This function is not only called for packages. */ if (result != TCL_OK) return result; return Tcl_PkgProvide(interp, MODULENAME, MODULEVERSION); #endif }
/*********************************************************************** * COMDLG32_FR_DoFindReplace [internal] * Actual load and creation of the Find/Replace dialog. * RETURNS * Window handle to created dialog:Success * NULL:Failure */ static HWND COMDLG32_FR_DoFindReplace( COMDLG32_FR_Data *pdata /* [in] Internal data structure */ ) { HWND hdlgwnd = 0; HGLOBAL loadrc; DWORD error; LPDLGTEMPLATEW rcs; TRACE("hInst=%p, Flags=%08x\n", pdata->fr.hInstance, pdata->fr.Flags); if(!(pdata->fr.Flags & FR_ENABLETEMPLATEHANDLE)) { HMODULE hmod = COMDLG32_hInstance; HRSRC htemplate; if(pdata->fr.Flags & FR_ENABLETEMPLATE) { hmod = pdata->fr.hInstance; if(pdata->fr.Flags & FR_WINE_UNICODE) { htemplate = FindResourceW(hmod, (LPCWSTR)pdata->fr.lpTemplateName, (LPWSTR)RT_DIALOG); } else { htemplate = FindResourceA(hmod, pdata->fr.lpTemplateName, (LPCSTR)RT_DIALOG); } } else { int rcid = pdata->fr.Flags & FR_WINE_REPLACE ? REPLACEDLGORD : FINDDLGORD; htemplate = FindResourceA(hmod, MAKEINTRESOURCEA(rcid), (LPCSTR)RT_DIALOG); } if(!htemplate) { error = CDERR_FINDRESFAILURE; goto cleanup; } loadrc = LoadResource(hmod, htemplate); } else { loadrc = (HGLOBAL)pdata->fr.hInstance; } if(!loadrc) { error = CDERR_LOADRESFAILURE; goto cleanup; } if((rcs = (LPDLGTEMPLATEW)LockResource(loadrc)) == NULL) { error = CDERR_LOCKRESFAILURE; goto cleanup; } hdlgwnd = CreateDialogIndirectParamA(COMDLG32_hInstance, rcs, pdata->fr.hwndOwner, COMDLG32_FindReplaceDlgProc, (LPARAM)pdata); if(!hdlgwnd) { error = CDERR_DIALOGFAILURE; cleanup: COMDLG32_SetCommDlgExtendedError(error); HeapFree(GetProcessHeap(), 0, pdata); } return hdlgwnd; }