Advertisement
Guest User

IUP Windows ICON

a guest
Apr 14th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include <iup.h>
  2. #include <stdlib.h>
  3.  
  4. //////////////////////////////////////////////////
  5. // Set Windows Icon
  6. #if defined(_WIN32) || defined(WIN32)
  7. #define __windows
  8. #include <windows.h>
  9.  
  10. WNDPROC orig_proc;
  11. HICON icon;
  12.  
  13. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  14.     if (msg == WM_SETCURSOR) {
  15.         if (LOWORD(lParam) == HTCLIENT) {
  16.             SetCursor(LoadCursor(NULL, IDC_ARROW));
  17.             return TRUE;
  18.         }
  19.     }
  20.     return CallWindowProc(orig_proc, hwnd, msg, wParam, lParam);
  21. }
  22.  
  23. void set_win_icon(HWND hwnd) {
  24.     HINSTANCE handle = GetModuleHandle(NULL);
  25.     icon = LoadIcon(handle, "icon");
  26.     SetClassLong(hwnd, GCL_HICON, (LONG) icon);
  27.     orig_proc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG) WndProc);
  28. }
  29.  
  30. void free_win_icon() {
  31.     DestroyIcon(icon);
  32. }
  33. #endif
  34. //////////////////////////////////////////////////
  35.  
  36. int exit_cb(void) {
  37.     return IUP_CLOSE;
  38. }
  39.  
  40. int main(int argc, char *argv[]) {
  41.     // declare widgets
  42.     Ihandle *btn, *lbl, *vbox, *dlg;
  43.     // initialize iup
  44.     IupOpen(&argc, &argv);
  45.     // create widgets and set their attributes
  46.     btn = IupButton("&Ok", "");
  47.     IupSetCallback(btn, "ACTION", (Icallback) exit_cb);
  48.     IupSetAttribute(btn, "EXPAND", "Yes");
  49.     IupSetAttribute(btn, "TIP", "Exit button");
  50.     lbl = IupLabel("Hello, world!");
  51.     vbox = IupVbox(lbl, btn, NULL);
  52.     IupSetAttribute(vbox, "GAP", "10");
  53.     IupSetAttribute(vbox, "MARGIN", "10x10");
  54.     IupSetAttribute(vbox, "ALIGNMENT", "ACENTER");
  55.     dlg = IupDialog(vbox);
  56.     IupSetAttribute(dlg, "TITLE", "EXAMPLE");
  57.     //IupSetAttribute(dlg, "ICON", "icon");
  58.     // Map widgets and show dialog
  59.     IupShow(dlg);
  60.    
  61.    
  62.     #ifdef __windows
  63.     set_win_icon((HWND)IupGetAttribute(dlg,"HWND"));
  64.     #endif
  65.    
  66.     // Wait for user interaction
  67.     IupMainLoop();
  68.    
  69.     #ifdef __windows
  70.     free_win_icon();
  71.     #endif
  72.    
  73.     // Clean up
  74.     IupDestroy(dlg);
  75.     IupClose();
  76.     return EXIT_SUCCESS;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement