int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int iShowCmd) { MSG msg; SCRIPT_DIGITSUBSTITUTE scriptDigitSubstitute; g_LogFont.lfQuality = CLEARTYPE_QUALITY; // Register main window class InitMainWnd(); ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &scriptDigitSubstitute); // // Create main window // hwndMain = CreateWindowEx(0, szAppName, // window class name szAppName, // window caption WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position 800, // initial x size 800, // initial y size NULL, // parent window handle NULL, // use window class menu hInst, // program instance handle NULL); // creation parameters // // Initialize the font // g_LogFont.lfHeight = -70; lstrcpy(g_LogFont.lfFaceName, L"Times New Roman"); UpdateFont(); ShowWindow(hwndMain, iShowCmd); // // Standard message loop // while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } DeleteObject(g_hFont); return 0; }
void ShowImage(FIBITMAP *src) { MSG msg; FIBITMAP *src2; // initialize window classes InitMainWnd(); hwndMain = CreateMainWnd(); hdc = GetDC(hwndMain); assert(hdc != NULL); src2 = FreeImage_ConvertToStandardType(src); int width = FreeImage_GetWidth(src2); int height = FreeImage_GetHeight(src2); hbitmap = GetDibSection(src2, hdc, 0, 0, width, height); assert(hbitmap != NULL); hbitmap_hdc = CreateCompatibleDC(hdc); // Associate the new DC with the bitmap for drawing SelectObject( hbitmap_hdc, hbitmap ); ShowWindow(hwndMain, 1); // message-loop while(GetMessage(&msg, NULL, 0, 0) > 0) { DispatchMessage(&msg); } }
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PMAIN_WND_INFO Info; LRESULT Ret = 0; static RECT wndOldPos; /* Get the window context */ Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (Info == NULL && uMsg != WM_CREATE) { goto HandleDefaultMessage; } switch (uMsg) { case WM_CREATE: { Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams); /* Initialize the main window context */ Info->hSelf = hwnd; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)Info); InitMainWnd(Info); /* Show the window */ ShowWindow(hwnd, Info->nCmdShow); /* get the windows position */ GetWindowRect(hwnd, &wndOldPos); break; } case WM_SIZE: { MainWndResize(Info, LOWORD(lParam), HIWORD(lParam)); /* NOTE - do *not* forward this message to DefFrameProc! Otherwise the MDI client will attempt to resize itself */ break; } case WM_MOVE: { } break; case WM_NOTIFY: { /* FIXME - handle other notifications */ break; } case WM_COMMAND: { MainWndCommand(Info, LOWORD(wParam), (HWND)lParam); goto HandleDefaultMessage; } case WM_MENUSELECT: { if (Info->hStatus != NULL) { if (!MainWndMenuHint(Info, LOWORD(wParam), MainMenuHintTable, sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]), IDS_HINT_BLANK)) { MainWndMenuHint(Info, LOWORD(wParam), SystemMenuHintTable, sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]), IDS_HINT_BLANK); } } break; } case WM_ENTERMENULOOP: { Info->InMenuLoop = TRUE; UpdateMainStatusBar(Info); break; } case WM_EXITMENULOOP: { Info->InMenuLoop = FALSE; UpdateMainStatusBar(Info); break; } case WM_CLOSE: { DestroyWindow(hwnd); break; } case WM_ENABLE: { goto HandleDefaultMessage; } case WM_NCACTIVATE: { goto HandleDefaultMessage; } case WM_ACTIVATEAPP: { goto HandleDefaultMessage; } case WM_DESTROY: { DestroyMainWnd(Info); /* FIXME: set the windows position in registry*/ //wndOldPos HeapFree(ProcessHeap, 0, Info); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); /* Break the message queue loop */ PostQuitMessage(0); break; } default: { HandleDefaultMessage: if (Info != NULL && Info->hMdiClient != NULL) { Ret = DefFrameProc(hwnd, Info->hMdiClient, uMsg, wParam, lParam); } else { Ret = DefWindowProc(hwnd, uMsg, wParam, lParam); } break; } } return Ret; }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nShowCmd) { MSG msg; HACCEL hAccel; TCHAR arg[MAX_PATH]; TCHAR * pszCmdline; EnableCrashingOnCrashes(); //INITCOMMONCONTROLSEX icx = { sizeof(icx), ICC_ g_hInstance = hInst; // This program requires COM OleInitialize(0); // // Commandline processing // pszCmdline = GetArg(GetCommandLineW(), arg, MAX_PATH); if(pszCmdline && *pszCmdline == '-') { pszCmdline = GetArg(pszCmdline, arg, MAX_PATH); // 'touch' the specified file! if(lstrcmpi(arg, TEXT("-touch")) == 0) { // check to see if it's a quoted filename if(*pszCmdline == '\"') { GetArg(pszCmdline, arg, MAX_PATH); pszCmdline = arg; } if(!TouchFile(pszCmdline)) { HexWinErrorBox(GetLastError(), 0); return 1; } return 0; } else { pszCmdline = GetArg(pszCmdline, arg, MAX_PATH); } } { INITCOMMONCONTROLSEX icex = { sizeof(icex), -1 }; InitCommonControlsEx(&icex); } /*g_Config = OpenConfig(TEXT("mapsize.exe.129082349834.bookmarks")); smeg(g_Config, TEXT("bookmarks.bookmark."), TEXT("mapsize.exe")); SaveConfig(TEXT("oof.config"), g_Config);*/ LoadSettings(); RegisterTabView(); InitMainWnd(); CreateMainWnd(); // open file specified on commmand line? if(pszCmdline && *pszCmdline) { // check to see if it's a quoted filename if(*pszCmdline == '\"') { GetArg(pszCmdline, arg, MAX_PATH); pszCmdline = arg; } if(!HexeditOpenFile(g_hwndMain, pszCmdline, DefaultFileMode()))//HVOF_DEFAULT)) { SendMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0); } } // automatically create new document if none specified else { SendMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0); } InitDockingBars(g_hwndMain); if(g_fRestoreWinPos) nShowCmd = SW_SHOW; ShowWindow(g_hwndMain, nShowCmd); // force any floating popups (i.e. the DOCKWNDs) to // become visible at the same time //ShowOwnedPopups(g_hwndMain, TRUE); DockWnd_ShowDeferredPopups(g_hwndMain); // // load keyboard accelerator table // hAccel = LoadAccelerators(GetModuleHandle(0)/*g_hResourceModule*/, MAKEINTRESOURCE(IDR_ACCELERATOR1)); // // message-pump // while(GetMessage(&msg, 0, 0, 0) > 0) { if(!TranslateAccelerator(g_hwndMain, hAccel, &msg)) { if( !IsDialogMessage(g_hwndSearch, &msg) && !IsDialogMessage(g_hwndGoto, &msg) && !DockWnd_IsDialogMessage(g_hwndMain, DWID_TYPEVIEW, &msg) && !DockWnd_IsDialogMessage(g_hwndMain, DWID_SEARCHBAR, &msg) && !DockWnd_IsDialogMessage(g_hwndMain, DWID_HIGHLIGHT, &msg) ) { TranslateMessage(&msg); DispatchMessage(&msg); } } } SaveSettings(); // Shutdown COM OleUninitialize(); return 0; }
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PMAIN_WND_INFO Info; LRESULT Ret = 0; /* Get the window context */ Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (Info == NULL && msg != WM_CREATE) { goto HandleDefaultMessage; } switch(msg) { case WM_CREATE: { Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams); /* Initialize the main window context */ Info->hMainWnd = hwnd; Info->SelectedItem = NO_ITEM_SELECTED; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)Info); if (!InitMainWnd(Info)) return -1; /* Fill the list-view before showing the main window */ RefreshServiceList(Info); /* Show the window */ ShowWindow(hwnd, Info->nCmdShow); SetFocus(Info->hListView); } break; case WM_SIZE: { MainWndResize(Info, LOWORD(lParam), HIWORD(lParam)); } break; case WM_NOTIFY: { LPNMHDR pnmhdr = (LPNMHDR)lParam; switch (pnmhdr->code) { case NM_DBLCLK: { POINT pt; RECT rect; GetCursorPos(&pt); GetWindowRect(Info->hListView, &rect); if (PtInRect(&rect, pt)) { SendMessage(hwnd, WM_COMMAND, //ID_PROP, MAKEWPARAM((WORD)ID_PROP, (WORD)0), 0); } //OpenPropSheet(Info); } break; case NM_RETURN: { SendMessage(hwnd, WM_COMMAND, //ID_PROP, MAKEWPARAM((WORD)ID_PROP, (WORD)0), 0); } break; case LVN_COLUMNCLICK: { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; (void)ListView_SortItems(Info->hListView, CompareFunc, pnmv->iSubItem); bSortAscending = !bSortAscending; } break; case LVN_ITEMCHANGED: { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; if (pnmv->uNewState != 0) { ListViewSelectionChanged(Info, pnmv); SetMenuAndButtonStates(Info); } } break; case TTN_GETDISPINFO: { LPTOOLTIPTEXT lpttt; UINT idButton; lpttt = (LPTOOLTIPTEXT)lParam; /* Specify the resource identifier of the descriptive * text for the given button. */ idButton = (UINT)lpttt->hdr.idFrom; switch (idButton) { case ID_PROP: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP); break; case ID_REFRESH: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH); break; case ID_EXPORT: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT); break; case ID_CREATE: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_CREATE); break; case ID_DELETE: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DELETE); break; case ID_START: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START); break; case ID_STOP: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP); break; case ID_PAUSE: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE); break; case ID_RESTART: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART); break; } } break; } } break; case WM_CONTEXTMENU: { POINT pt; RECT lvRect; INT xPos = GET_X_LPARAM(lParam); INT yPos = GET_Y_LPARAM(lParam); GetCursorPos(&pt); /* display popup when cursor is in the list view */ GetWindowRect(Info->hListView, &lvRect); if (PtInRect(&lvRect, pt)) { TrackPopupMenuEx(GetSubMenu(Info->hShortcutMenu, 0), TPM_RIGHTBUTTON, xPos, yPos, Info->hMainWnd, NULL); } } break; case WM_COMMAND: { MainWndCommand(Info, LOWORD(wParam), (HWND)lParam); goto HandleDefaultMessage; } case WM_MENUSELECT: { if (Info->hStatus != NULL) { if (!MainWndMenuHint(Info, LOWORD(wParam), MainMenuHintTable, sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]), IDS_HINT_BLANK)) { MainWndMenuHint(Info, LOWORD(wParam), SystemMenuHintTable, sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]), IDS_HINT_BLANK); } } } break; case WM_ENTERMENULOOP: { Info->bInMenuLoop = TRUE; UpdateMainStatusBar(Info); break; } case WM_EXITMENULOOP: { Info->bInMenuLoop = FALSE; UpdateMainStatusBar(Info); break; } case WM_CLOSE: { HeapFree(ProcessHeap, 0, Info->pAllServices); DestroyMenu(Info->hShortcutMenu); DestroyWindow(hwnd); } break; case WM_DESTROY: { HeapFree(ProcessHeap, 0, Info); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); PostQuitMessage(0); } break; default: { HandleDefaultMessage: Ret = DefWindowProc(hwnd, msg, wParam, lParam); } break; } return Ret; }
// // Entry-point for text-editor application // int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int iShowCmd) { MSG msg; HACCEL hAccel; TCHAR **argv; int argc; //TCHAR *pszCmdlineFile = 0; TCHAR arg[MAX_PATH]; // // get the first commandline argument // TCHAR *pszCmdline = GetArg(GetCommandLineW(), arg, MAX_PATH); argv = GetArgvCommandLine(&argc); // check if we have any options if(pszCmdline && *pszCmdline == '-') { pszCmdline = GetArg(pszCmdline, arg, MAX_PATH); // do the user-account-control thing if(lstrcmpi(arg, _T("-uac")) == 0) { //return 0; } // image-file-execute-options else if(lstrcmpi(arg, _T("-ifeo")) == 0) { // skip notepad.exe pszCmdline = GetArg(pszCmdline, arg, MAX_PATH); } // unrecognised option else { } } // has a prior instance elevated us to admin in order to // modify some system-wide settings in the registry? if(argv && argc == 4 && lstrcmpi(argv[1], _T("-uac")) == 0) { g_fAddToExplorer = _ttoi(argv[2]); g_fReplaceNotepad = _ttoi(argv[3]); if(SetExplorerContextMenu(g_fAddToExplorer) && SetImageFileExecutionOptions(g_fReplaceNotepad)) { SaveRegSysSettings(); return 0; } else { return ERROR_ACCESS_DENIED; } } // default to the built-in resources g_hResourceModule = hInst; OleInitialize(0); // initialize window classes InitMainWnd(); InitTextView(); LoadRegSettings(); // create the main window! g_hwndMain = CreateMainWnd(); // open file specified on commmand line if(pszCmdline && *pszCmdline) { // check to see if it's a quoted filename if(*pszCmdline == '\"') { GetArg(pszCmdline, arg, MAX_PATH); pszCmdline = arg; } NeatpadOpenFile(g_hwndMain, pszCmdline); LoadFileData(pszCmdline, g_hwndMain); } // automatically create new document if none specified else { PostMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0); } ApplyRegSettings(); ShowWindow(g_hwndMain, iShowCmd); // // load keyboard accelerator table // hAccel = LoadAccelerators(g_hResourceModule, MAKEINTRESOURCE(IDR_ACCELERATOR1)); // // message-loop // while(GetMessage(&msg, NULL, 0, 0) > 0) { if(!TranslateAccelerator(g_hwndMain, hAccel, &msg)) { if((!IsWindow(g_hwndSearchDlg) || !IsDialogMessage(g_hwndSearchDlg, &msg))) { TranslateMessage(&msg); DispatchMessage(&msg); } } } if(g_fSaveOnExit) SaveRegSettings(); OleUninitialize(); ExitProcess(0); return 0; }
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PMAIN_WND_INFO Info; LRESULT Ret = 0; /* Get the window context */ Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (Info == NULL && msg != WM_CREATE) { goto HandleDefaultMessage; } switch(msg) { case WM_CREATE: { Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams); /* Initialize the main window context */ Info->hMainWnd = hwnd; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)Info); if (!InitMainWnd(Info)) SendMessage(hwnd, WM_CLOSE, 0, 0); /* Show the window */ ShowWindow(hwnd, Info->nCmdShow); } break; case WM_SETFOCUS: { if (Info->hTreeView != NULL) SetFocus(Info->hTreeView); } break; case WM_SIZE: { MainWndResize(Info, LOWORD(lParam), HIWORD(lParam)); } break; case WM_NOTIFY: { Ret = OnNotify(Info, lParam); } break; case WM_CONTEXTMENU: { OnContext(Info, lParam); } break; case WM_COMMAND: { MainWndCommand(Info, LOWORD(wParam), (HWND)lParam); goto HandleDefaultMessage; } case WM_MENUSELECT: { if (Info->hStatus != NULL) { if (!MainWndMenuHint(Info, LOWORD(wParam), MainMenuHintTable, sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]), IDS_HINT_BLANK)) { MainWndMenuHint(Info, LOWORD(wParam), SystemMenuHintTable, sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]), IDS_HINT_BLANK); } } } break; case WM_ENTERMENULOOP: { Info->InMenuLoop = TRUE; UpdateMainStatusBar(Info); break; } case WM_EXITMENULOOP: { Info->InMenuLoop = FALSE; UpdateMainStatusBar(Info); break; } case WM_CLOSE: { FreeDeviceStrings(Info->hTreeView); DestroyMenu(Info->hShortcutMenu); DestroyWindow(hwnd); } break; case WM_DESTROY: { HeapFree(ProcessHeap, 0, Info); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); /* Break the message queue loop */ PostQuitMessage(0); } break; default: { HandleDefaultMessage: Ret = DefWindowProc(hwnd, msg, wParam, lParam); } break; } return Ret; }