Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iup.h>
- #include <stdlib.h>
- //////////////////////////////////////////////////
- // Set Windows Icon
- #if defined(_WIN32) || defined(WIN32)
- #define __windows
- #include <windows.h>
- WNDPROC orig_proc;
- HICON icon;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- if (msg == WM_SETCURSOR) {
- if (LOWORD(lParam) == HTCLIENT) {
- SetCursor(LoadCursor(NULL, IDC_ARROW));
- return TRUE;
- }
- }
- return CallWindowProc(orig_proc, hwnd, msg, wParam, lParam);
- }
- void set_win_icon(HWND hwnd) {
- HINSTANCE handle = GetModuleHandle(NULL);
- icon = LoadIcon(handle, "icon");
- SetClassLong(hwnd, GCL_HICON, (LONG) icon);
- orig_proc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG) WndProc);
- }
- void free_win_icon() {
- DestroyIcon(icon);
- }
- #endif
- //////////////////////////////////////////////////
- int exit_cb(void) {
- return IUP_CLOSE;
- }
- int main(int argc, char *argv[]) {
- // declare widgets
- Ihandle *btn, *lbl, *vbox, *dlg;
- // initialize iup
- IupOpen(&argc, &argv);
- // create widgets and set their attributes
- btn = IupButton("&Ok", "");
- IupSetCallback(btn, "ACTION", (Icallback) exit_cb);
- IupSetAttribute(btn, "EXPAND", "Yes");
- IupSetAttribute(btn, "TIP", "Exit button");
- lbl = IupLabel("Hello, world!");
- vbox = IupVbox(lbl, btn, NULL);
- IupSetAttribute(vbox, "GAP", "10");
- IupSetAttribute(vbox, "MARGIN", "10x10");
- IupSetAttribute(vbox, "ALIGNMENT", "ACENTER");
- dlg = IupDialog(vbox);
- IupSetAttribute(dlg, "TITLE", "EXAMPLE");
- //IupSetAttribute(dlg, "ICON", "icon");
- // Map widgets and show dialog
- IupShow(dlg);
- #ifdef __windows
- set_win_icon((HWND)IupGetAttribute(dlg,"HWND"));
- #endif
- // Wait for user interaction
- IupMainLoop();
- #ifdef __windows
- free_win_icon();
- #endif
- // Clean up
- IupDestroy(dlg);
- IupClose();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement