Advertisement
Guest User

WinAPI

a guest
Sep 4th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define ISOLATION_AWARE_ENABLED 1
  2.  
  3. #include "stdafx.h"
  4. #include "Process.h"
  5. #include <iostream>
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include <tchar.h>
  10. #include "Windows.h"
  11. #include "commctrl.h"
  12. #include "resource.h"
  13.  
  14. static HINSTANCE mainInstance;
  15.  
  16. int MyButtonId = 1000;
  17. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18.  
  19. BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
  20. {
  21.     mainInstance = hModule;
  22.  
  23.     WNDCLASSEX wc = { 0 };
  24.     HWND MainHwnd;
  25.     MSG Msg;
  26.  
  27.     wc.cbSize = sizeof(wc);
  28.     wc.style = CS_HREDRAW | CS_VREDRAW;
  29.     wc.lpfnWndProc = WindowProc;
  30.     wc.hInstance = mainInstance;
  31.  
  32.     wc.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(30, 30, 30)));
  33.     wc.cbClsExtra = 0;
  34.     wc.cbWndExtra = 0;
  35.  
  36.     wc.lpszMenuName = NULL;
  37.     wc.lpszClassName = "Application";
  38.  
  39.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  40.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  41.  
  42.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  43.  
  44.  
  45.     if (!RegisterClassEx(&wc))
  46.     {
  47.         MessageBox(NULL, std::to_string(GetLastError()).c_str(), "RegisterClassEx!",
  48.             MB_ICONEXCLAMATION | MB_OK);
  49.         return 0;
  50.     }
  51.  
  52.     MainHwnd = CreateWindowEx(
  53.         WS_EX_CLIENTEDGE,
  54.         "Application",
  55.         "My Application",
  56.         WS_SYSMENU | WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX,
  57.         CW_USEDEFAULT, CW_USEDEFAULT, 400, 280,
  58.         NULL, NULL, mainInstance, NULL);
  59.  
  60.     if (MainHwnd == NULL)
  61.     {
  62.         MessageBox(NULL, std::to_string(GetLastError()).c_str(), "CreateWindow!",
  63.             MB_ICONEXCLAMATION | MB_OK);
  64.         return 0;
  65.     }
  66.  
  67.     ShowWindow(MainHwnd, 1);
  68.     UpdateWindow(MainHwnd);
  69.  
  70.     while (GetMessage(&Msg, NULL, 0, 0) > 0)
  71.     {
  72.         TranslateMessage(&Msg);
  73.         DispatchMessage(&Msg);
  74.     }
  75.    
  76.     return TRUE;
  77. }
  78.  
  79. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  80. {
  81.     switch (uMsg)
  82.     {
  83.     case WM_CREATE: {
  84.         MyButton = CreateWindow("BUTTON", "A Button Text", WS_VISIBLE | WS_CHILD | BS_BITMAP | BS_FLAT, 17, 18, 110, 30, hwnd, (HMENU)PickButtonId, mainInstance, NULL);
  85.  
  86.         ///////// --->
  87.  
  88.         // Here I'm using one of these :
  89.  
  90.         // Using LoadImage()
  91.         MyImage = (HBITMAP)LoadImage(hInstance, "UI\\myimage.bmp", IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_LOADFROMFILE);
  92.  
  93.         // Using LoadBitmap() | My_Bitmap is an image resource name
  94.         MyImage = LoadBitmap(hInstance, MAKEINTRESOURCE(My_Bitmap));
  95.  
  96.         ///////// <---
  97.  
  98.         SendMessage(MyButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)MyImage);
  99.  
  100.         break;
  101.     }
  102.  
  103.     default:
  104.         return DefWindowProc(hwnd, uMsg, wParam, lParam);
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement